Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions chronicler/events/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from ...eventizer import Eventizer, uuid, Identity


GIT_EVENT_COMMIT = "org.grimoirelab.events.git.commit"
GIT_EVENT_MERGE_COMMIT = "org.grimoirelab.events.git.merge"
GIT_EVENT_ACTION_ADDED = "org.grimoirelab.events.git.file.added"
Expand Down Expand Up @@ -101,6 +102,7 @@ def eventize_item(self, raw_item: dict[str, Any]) -> list[CloudEvent]:
events.append(event)

action_events = self._eventize_commit_actions(event,
raw_item['data']['commit'],
raw_item['data']['files'])

events.extend(action_events)
Expand All @@ -112,7 +114,7 @@ def eventize_item(self, raw_item: dict[str, Any]) -> list[CloudEvent]:

return events

def _eventize_commit_actions(self, parent_event: CloudEvent, raw_files_data):
def _eventize_commit_actions(self, parent_event: CloudEvent, commit_hash, raw_files_data):

events = []

Expand All @@ -127,7 +129,10 @@ def _eventize_commit_actions(self, parent_event: CloudEvent, raw_files_data):
if parent_event['type'] == GIT_EVENT_COMMIT:
action_event = self._process_action(parent_event['source'],
parent_event['time'],
parent_event['id'], actions, file_data)
parent_event['id'],
commit_hash,
actions,
file_data)
events.append(action_event)
else:
prev_merge_action = None
Expand All @@ -137,12 +142,15 @@ def _eventize_commit_actions(self, parent_event: CloudEvent, raw_files_data):

action_event = self._process_action(parent_event['source'],
parent_event['time'],
parent_event['id'], action, file_data)
parent_event['id'],
commit_hash,
action,
file_data)
events.append(action_event)
prev_merge_action = action
return events

def _process_action(self, source, time, event_uuid, action, file_data):
def _process_action(self, source, time, event_uuid, commit_hash, action, file_data):
if action == 'A':
event_type = GIT_EVENT_ACTION_ADDED
elif action == 'M':
Expand All @@ -165,6 +173,7 @@ def _process_action(self, source, time, event_uuid, action, file_data):
event_id = uuid(*id_args)

data = {
"commit": commit_hash,
"filename": file_data['file'],
"modes": file_data['modes'],
"indexes": file_data['indexes'],
Expand All @@ -191,11 +200,14 @@ def _eventize_commit_identities(self, parent_event: CloudEvent, raw_item: dict[s

events = []

commit_hash = raw_item["data"]["commit"]

authors = self._parse_authors(raw_item["data"]["Author"])
identity_events = self._process_identities(parent_event['source'],
parent_event['time'],
parent_event['id'],
GIT_EVENT_COMMIT_AUTHORED_BY,
commit_hash,
authors)
events.extend(identity_events)

Expand All @@ -204,6 +216,7 @@ def _eventize_commit_identities(self, parent_event: CloudEvent, raw_item: dict[s
parent_event['time'],
parent_event['id'],
GIT_EVENT_COMMIT_COMMITTED_BY,
commit_hash,
committers)
events.extend(identity_events)

Expand All @@ -213,6 +226,7 @@ def _eventize_commit_identities(self, parent_event: CloudEvent, raw_item: dict[s
parent_event['time'],
parent_event['id'],
event_type,
commit_hash,
signers)
events.extend(identity_events)

Expand All @@ -224,6 +238,7 @@ def _process_identities(
time: str,
event_uuid: str,
event_type: str,
commit_hash: str,
raw_identities: list[str]
) -> Generator[CloudEvent, None, None]:
"""Obtain identity events from a list of identities.
Expand All @@ -232,6 +247,7 @@ def _process_identities(
:param time: time of the event
:param event_uuid: UUID of the parent event
:param event_type: type of the identity event
:param commit_hash: hash of the commit where identities contributed
:param raw_identities: list of strings with the identities information

:returns: generator of CloudEvent with the identity information
Expand All @@ -252,6 +268,7 @@ def _process_identities(
event_id = uuid(event_uuid, role, identity_id)

data = {
"commit": commit_hash,
"source": "git",
"name": identity.name,
"username": identity.username,
Expand Down
16 changes: 8 additions & 8 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Each event is structured into two parts:

- Attributes: metadata providing contextual information about the event and present in
- Attributes: metadata providing contextual information about the event and present in
all types of events. The attributes are based on the CloudEvents specification.
- Data: other information specific to the event.

Expand Down Expand Up @@ -64,6 +64,7 @@ Git events are related to commits in git repositories.

| Field | Type | Description |
|---------------|-----------------|------------------------------------------------------------|
| commit | `String` | Commit hash |
| filename | `String` | Name of the file |
| modes | `List (String)` | Git file modes |
| indexes | `List (String)` | Git indexes |
Expand Down Expand Up @@ -100,7 +101,6 @@ Git events are related to commits in git repositories.

File objects found in the `files` field of [commit](#commit) and [merge commit](#merge-commit) events.


| Field | Type | Description |
|---------|-----------------|-------------------------------------|
| action | `String` | Identifier of the action performed |
Expand All @@ -110,13 +110,13 @@ File objects found in the `files` field of [commit](#commit) and [merge commit](
| modes | `List (String)` | Git file modes |
| removed | `String` | Number of deleted lines in the file |


#### Commit contributors

Information about contributors related to a commit.

| Field | Type | Description |
|----------|----------|---------------------------------------------------|
| commit | `String` | Commit hash |
| name | `String` | Name of the contributor |
| username | `String` | Username of the contributor |
| email | `String` | Email of the contributor |
Expand All @@ -138,7 +138,7 @@ Identifies the person who applied or committed the patch to the repository.

##### Acked-by

Identifies the person who is more familiar with the area the patch
Identifies the person who is more familiar with the area the patch
attempts to modify and has approved the patch.

- Event type: `org.grimoirelab.events.git.commit.acked_by`
Expand All @@ -151,14 +151,14 @@ Identifies people who exchanged drafts of a patch before submitting it.

##### Helped-by

Identifies someone who suggested ideas for changes without providing the precise
Identifies someone who suggested ideas for changes without providing the precise
changes in patch form.

- Event type: `org.grimoirelab.events.git.commit.helped_by`

##### Mentored-by

Identifies someone who helped develop a patch as part of a mentorship program
Identifies someone who helped develop a patch as part of a mentorship program
(e.g., GSoC or Outreachy).

- Event type: `org.grimoirelab.events.git.commit.mentored_by`
Expand All @@ -170,14 +170,14 @@ Identifies the person who found the bug that the patch attempts to fix.
- Event type: `org.grimoirelab.events.git.commit.reported_by`

##### Reviewed-by
Identifies the reviewer who, after a detailed analysis, is completely satisfied
Identifies the reviewer who, after a detailed analysis, is completely satisfied
with the patch.

- Event type: `org.grimoirelab.events.git.commit.reviewed_by`

##### Signed-off-by

Indicates that the committer certifies they have the rights to submit the work,
Indicates that the committer certifies they have the rights to submit the work,
typically by adding a sign-off line in the commit message.

- Event type: `org.grimoirelab.events.git.commit.signed_off_by`
Expand Down
9 changes: 9 additions & 0 deletions releases/unreleased/commit-hash-in-git-events.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Commit hash in Git events
category: added
author: Santiago Dueñas <sduenas@bitergia.com>
issue: 12
notes: >
Git events - including actions and identities events -
will include the commit hash for traceability purposes.

Loading