Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metadata] Remove metadata from empty enriched items #848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions grimoire_elk/enriched/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def metadata(func):
@functools.wraps(func)
def decorator(self, *args, **kwargs):
eitem = func(self, *args, **kwargs)

if not eitem:
return eitem

metadata = {
'metadata__gelk_version': self.gelk_version,
'metadata__gelk_backend_name': self.__class__.__name__,
Expand Down Expand Up @@ -388,6 +392,8 @@ def enrich_items(self, ocean_backend, events=False):

if not events:
rich_item = self.get_rich_item(item)
if not rich_item:
continue
data_json = json.dumps(rich_item)
bulk_json += '{"index" : {"_id" : "%s" } }\n' % \
(item[self.get_field_unique_id()])
Expand Down
1 change: 1 addition & 0 deletions grimoire_elk/enriched/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def get_rich_item(self, item):
else:
logger.error("[github] rich item not defined for GitHub category {}".format(
item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down
3 changes: 3 additions & 0 deletions grimoire_elk/enriched/github2.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def get_rich_item(self, item):
else:
logger.error("[github] rich item not defined for GitHub category {}".format(
item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down Expand Up @@ -386,6 +387,8 @@ def enrich_items(self, ocean_backend):
eitems = []

eitem = self.get_rich_item(item)
if not eitem:
continue
items_to_enrich.append(eitem)
if item['category'] == ISSUE_TYPE:
eitems = self.enrich_issue(item, eitem)
Expand Down
3 changes: 2 additions & 1 deletion grimoire_elk/enriched/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def get_rich_item(self, item):
elif item['category'] == 'merge_request':
rich_item = self.__get_rich_merge(item)
else:
logger.error("[gerrit] rich item not defined for GitLab category {}".format(item['category']))
logger.error("[gitlab] rich item not defined for GitLab category {}".format(item['category']))
return rich_item

self.add_repository_labels(rich_item)
self.add_metadata_filter_raw(rich_item)
Expand Down
225 changes: 225 additions & 0 deletions tests/data/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -3276,5 +3276,230 @@
"timestamp": 1579025969.338453,
"updated_on": 1550852463.0,
"uuid": "ce0a349fd6c16890c489c4eb3c2fe958910c034c"
},
{
"backend_name": "GitHub",
"backend_version": "0.24.0",
"category": "message",
"classified_fields_filtered": [
"user_data",
"merged_by_data",
"assignee_data",
"assignees_data",
"requested_reviewers_data",
"comments_data.user_data",
"comments_data.reactions_data.user_data",
"reviews_data.user_data",
"review_comments_data.user_data",
"review_comments_data.reactions_data.user_data"
],
"data": {
"assignee": null,
"assignees": [],
"author_association": "MEMBER",
"body": "Add also the cache support for users.\n\nThe users in an issue are: \"user\", \"assignee\". Both of them have now extra user data retrieved from GitHub User API.\n",
"closed_at": "2016-01-26T19:26:43Z",
"comments": 3,
"comments_data": [
{
"author_association": "MEMBER",
"body": "Reviewed it. @acs I miss the code where you add the information about who made a comment or a change.\n",
"created_at": "2016-01-22T12:17:18Z",
"html_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7#issuecomment-173902372",
"id": 173902372,
"issue_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7",
"node_id": "MDEyOklzc3VlQ29tbWVudDE3MzkwMjM3Mg==",
"reactions": {
"+1": 0,
"-1": 0,
"confused": 0,
"eyes": 0,
"heart": 0,
"hooray": 0,
"laugh": 0,
"rocket": 0,
"total_count": 0,
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/173902372/reactions"
},
"reactions_data": [],
"updated_at": "2016-01-22T12:17:18Z",
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/173902372",
"user": {
"avatar_url": "https://avatars3.githubusercontent.com/u/833352?v=4",
"events_url": "https://api.github.com/users/sduenas/events{/privacy}",
"followers_url": "https://api.github.com/users/sduenas/followers",
"following_url": "https://api.github.com/users/sduenas/following{/other_user}",
"gists_url": "https://api.github.com/users/sduenas/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/sduenas",
"id": 833352,
"login": "sduenas",
"node_id": "MDQ6VXNlcjgzMzM1Mg==",
"organizations_url": "https://api.github.com/users/sduenas/orgs",
"received_events_url": "https://api.github.com/users/sduenas/received_events",
"repos_url": "https://api.github.com/users/sduenas/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/sduenas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sduenas/subscriptions",
"type": "User",
"url": "https://api.github.com/users/sduenas"
}
},
{
"author_association": "MEMBER",
"body": "@sduenas all review addressed except adding user data for people doing comments and changes. I am not sure we should complete user data also for this actors. The resulting JSON could be huge and with a lot of duplicates. What do you think?\n",
"created_at": "2016-01-26T04:45:20Z",
"html_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7#issuecomment-174822113",
"id": 174822113,
"issue_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7",
"node_id": "MDEyOklzc3VlQ29tbWVudDE3NDgyMjExMw==",
"reactions": {
"+1": 0,
"-1": 0,
"confused": 0,
"eyes": 0,
"heart": 0,
"hooray": 0,
"laugh": 0,
"rocket": 0,
"total_count": 0,
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/174822113/reactions"
},
"reactions_data": [],
"updated_at": "2016-01-26T04:45:20Z",
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/174822113",
"user": {
"avatar_url": "https://avatars0.githubusercontent.com/u/209533?v=4",
"events_url": "https://api.github.com/users/acs/events{/privacy}",
"followers_url": "https://api.github.com/users/acs/followers",
"following_url": "https://api.github.com/users/acs/following{/other_user}",
"gists_url": "https://api.github.com/users/acs/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/acs",
"id": 209533,
"login": "acs",
"node_id": "MDQ6VXNlcjIwOTUzMw==",
"organizations_url": "https://api.github.com/users/acs/orgs",
"received_events_url": "https://api.github.com/users/acs/received_events",
"repos_url": "https://api.github.com/users/acs/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/acs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/acs/subscriptions",
"type": "User",
"url": "https://api.github.com/users/acs"
}
},
{
"author_association": "MEMBER",
"body": "@acs you're right. We can keep these data away for the moment.\n\nCan you check the code that I added? Do you think it's better than your proposal?\n",
"created_at": "2016-01-26T12:43:46Z",
"html_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7#issuecomment-174995322",
"id": 174995322,
"issue_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7",
"node_id": "MDEyOklzc3VlQ29tbWVudDE3NDk5NTMyMg==",
"reactions": {
"+1": 0,
"-1": 0,
"confused": 0,
"eyes": 0,
"heart": 0,
"hooray": 0,
"laugh": 0,
"rocket": 0,
"total_count": 0,
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/174995322/reactions"
},
"reactions_data": [],
"updated_at": "2016-01-26T12:43:46Z",
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/comments/174995322",
"user": {
"avatar_url": "https://avatars3.githubusercontent.com/u/833352?v=4",
"events_url": "https://api.github.com/users/sduenas/events{/privacy}",
"followers_url": "https://api.github.com/users/sduenas/followers",
"following_url": "https://api.github.com/users/sduenas/following{/other_user}",
"gists_url": "https://api.github.com/users/sduenas/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/sduenas",
"id": 833352,
"login": "sduenas",
"node_id": "MDQ6VXNlcjgzMzM1Mg==",
"organizations_url": "https://api.github.com/users/sduenas/orgs",
"received_events_url": "https://api.github.com/users/sduenas/received_events",
"repos_url": "https://api.github.com/users/sduenas/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/sduenas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sduenas/subscriptions",
"type": "User",
"url": "https://api.github.com/users/sduenas"
}
}
],
"comments_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7/comments",
"created_at": "2016-01-21T19:57:25Z",
"events_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7/events",
"html_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7",
"id": 128006801,
"labels": [],
"labels_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7/labels{/name}",
"locked": false,
"milestone": null,
"node_id": "MDExOlB1bGxSZXF1ZXN0NTY4MDA0OTg=",
"number": 7,
"pull_request": {
"diff_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7.diff",
"html_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7",
"patch_url": "https://github.com/chaoss/grimoirelab-perceval/pull/7.patch",
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/pulls/7"
},
"reactions": {
"+1": 0,
"-1": 0,
"confused": 0,
"eyes": 0,
"heart": 0,
"hooray": 0,
"laugh": 0,
"rocket": 0,
"total_count": 0,
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7/reactions"
},
"reactions_data": [],
"repository_url": "https://api.github.com/repos/chaoss/grimoirelab-perceval",
"state": "closed",
"title": "[github] Add to issues user data from the GitHub User API (email, company ...)",
"updated_at": "2016-01-26T19:26:43Z",
"url": "https://api.github.com/repos/chaoss/grimoirelab-perceval/issues/7",
"user": {
"avatar_url": "https://avatars0.githubusercontent.com/u/209533?v=4",
"events_url": "https://api.github.com/users/acs/events{/privacy}",
"followers_url": "https://api.github.com/users/acs/followers",
"following_url": "https://api.github.com/users/acs/following{/other_user}",
"gists_url": "https://api.github.com/users/acs/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/acs",
"id": 209533,
"login": "acs",
"node_id": "MDQ6VXNlcjIwOTUzMw==",
"organizations_url": "https://api.github.com/users/acs/orgs",
"received_events_url": "https://api.github.com/users/acs/received_events",
"repos_url": "https://api.github.com/users/acs/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/acs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/acs/subscriptions",
"type": "User",
"url": "https://api.github.com/users/acs"
}
},
"origin": "https://github.com/chaoss/grimoirelab-perceval",
"perceval_version": "0.12.23",
"search_fields": {
"item_id": "128006801",
"owner": "chaoss",
"repo": "grimoirelab-perceval"
},
"tag": "https://github.com/chaoss/grimoirelab-perceval",
"timestamp": 1571652244.817805,
"updated_on": 1453836403.0,
"uuid": "f18b8ff1f44b5e4e9c816844f9eca59973101ffa"
}
]
Loading