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

[github] Fix get_identities method not returning all identities #1118

Merged
merged 1 commit into from
Oct 5, 2023
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: 15 additions & 10 deletions grimoire_elk/enriched/github2.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ def get_identities(self, item):

category = item['category']
item = item['data']
comments_attr = None
if category == "issue":
identity_types = ['user', 'assignee']
comments_attr = 'comments_data'
comments_attrs = ['comments_data']
elif category == "pull_request":
identity_types = ['user', 'merged_by']
comments_attr = 'review_comments_data'
comments_attrs = ['review_comments_data', 'reviews_data']
else:
identity_types = []
comments_attrs = []

for identity in identity_types:
identity_attr = identity + "_data"
Expand All @@ -152,11 +152,12 @@ def get_identities(self, item):
if user:
yield user

comments = item.get(comments_attr, [])
for comment in comments:
user = self.get_sh_identity(comment['user_data'])
if user:
yield user
for comments_attr in comments_attrs:
comments = item.get(comments_attr, [])
for comment in comments:
user = self.get_sh_identity(comment['user_data'])
if user:
yield user

def get_sh_identity(self, item, identity_field=None):
identity = {}
Expand All @@ -171,9 +172,13 @@ def get_sh_identity(self, item, identity_field=None):
if not user:
return identity

identity['name'] = user.get('name', user.get('login', None))
identity['email'] = user.get('email', None)
identity['username'] = user.get('username', user.get('login', None))
identity['name'] = user.get('name', None)
if not identity['name']:
identity['name'] = user.get('login', None)
identity['username'] = user.get('username', None)
if not identity['username']:
identity['username'] = user.get('login', None)

return identity

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Undefined identities in GitHub comments
category: fixed
author: Jose Javier Merchante <jjmerchante@bitergia.com>
issue: null
notes: >
Fix a bug that causes certain identities from commentaries
to not be imported into SortingHat, resulting in them appearing
as UNDEFINED in OpenSearch.