Skip to content

Commit ac8fcdf

Browse files
committed
Add repository branch information
Signed-off-by: lishengbao <[email protected]>
1 parent 99faca8 commit ac8fcdf

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

grimoire_elk_gitcode/enriched/gitcode.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@
5656
logger = logging.getLogger(__name__)
5757

5858

59+
def deep_get(dictionary, keys, default=None):
60+
"""递归获取字典深层的值"""
61+
for key in keys:
62+
if dictionary is None:
63+
return default
64+
dictionary = dictionary.get(key)
65+
return dictionary or default
66+
67+
5968
class Mapping(BaseMapping):
6069

6170
@staticmethod
@@ -386,9 +395,8 @@ def __get_rich_pull(self, item):
386395
rich_pr['closed_at'] = pull_request['closed_at']
387396
rich_pr['url'] = pull_request['html_url']
388397
rich_pr['review_mode'] = pull_request.get('review_mode')
389-
labels = []
390-
[labels.append(label['name']) for label in pull_request['labels'] if 'labels' in pull_request]
391-
rich_pr['labels'] = labels
398+
rich_pr['labels'] = [label['name'] for label in pull_request.get('labels', [])]
399+
rich_pr['assignees_accept_count'] = sum(1 for a in pull_request['assignees'] if a.get('accept') is True and not a.get('login', '').lower().endswith('bot'))
392400

393401
rich_pr['pull_request'] = True
394402
rich_pr['item_type'] = 'pull request'
@@ -610,6 +618,28 @@ def __get_rich_repo(self, item):
610618
rich_releases.append(rich_releases_dict)
611619
rich_repo['releases'] = rich_releases
612620
rich_repo['releases_count'] = len(rich_releases)
621+
622+
623+
rich_branches = []
624+
for branch in repo.get('branches', []):
625+
rich_branches_item = {}
626+
rich_branches_item["name"] = deep_get(branch, ["name"])
627+
rich_branches_item["author_name"] = deep_get(branch, ["commit", "commit", "author", "name"])
628+
rich_branches_item["author_date"] = deep_get(branch, ["commit", "commit", "author", "date"])
629+
rich_branches_item["author_email"] = deep_get(branch, ["commit", "commit", "author", "email"])
630+
rich_branches_item["committer_name"] = deep_get(branch, ["commit", "commit", "committer", "name"])
631+
rich_branches_item["committer_date"] = deep_get(branch, ["commit", "commit", "committer", "date"])
632+
rich_branches_item["committer_email"] = deep_get(branch, ["commit", "commit", "committer", "email"])
633+
rich_branches_item["message"] = deep_get(branch, ["commit", "commit", "message"])
634+
rich_branches_item["sha"] = deep_get(branch, ["commit", "sha"])
635+
rich_branches_item["url"] = deep_get(branch, ["commit", "url"])
636+
rich_branches_item["protected"] = deep_get(branch, ["protected"])
637+
rich_branches_item["developers_can_push"] = branch.get("developers_can_push")
638+
rich_branches_item["developers_can_merge"] = branch.get("developers_can_merge")
639+
rich_branches.append(rich_branches_item)
640+
rich_repo['branches'] = rich_branches
641+
rich_repo['branches_count'] = len(rich_branches)
642+
613643

614644
rich_repo["topics"] = repo.get('project_labels', [])
615645

setup.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@
6262
tests_require=['httpretty==0.8.6'],
6363
test_suite='tests',
6464
install_requires=[
65-
'grimoire-elk>=0.72.0',
66-
'perceval>=0.9.6',
67-
'perceval-gitcode>=0.1.0',
68-
'cereslib>=0.1.0',
69-
'grimoirelab-toolkit>=0.1.4',
70-
'sortinghat>=0.6.2',
71-
'graal>=0.2.2',
72-
'elasticsearch==6.3.1',
73-
'elasticsearch-dsl==6.3.1',
74-
'requests==2.26.0',
75-
'urllib3==1.26.5',
76-
'PyMySQL>=0.7.0',
77-
'pandas>=0.22.0,<=0.25.3',
78-
'geopy>=1.20.0',
79-
'statsmodels >= 0.9.0'
65+
# 'grimoire-elk>=0.72.0',
66+
# 'perceval>=0.9.6',
67+
# 'perceval-gitcode>=0.1.0',
68+
# 'cereslib>=0.1.0',
69+
# 'grimoirelab-toolkit>=0.1.4',
70+
# 'sortinghat>=0.6.2',
71+
# 'graal>=0.2.2',
72+
# 'elasticsearch==6.3.1',
73+
# 'elasticsearch-dsl==6.3.1',
74+
# 'requests==2.26.0',
75+
# 'urllib3==1.26.5',
76+
# 'PyMySQL>=0.7.0',
77+
# 'pandas>=0.22.0,<=0.25.3',
78+
# 'geopy>=1.20.0',
79+
# 'statsmodels >= 0.9.0'
8080
],
8181
zip_safe=False
8282
)

0 commit comments

Comments
 (0)