Skip to content

Commit

Permalink
contributor merge includes commit_urls
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Oct 11, 2023
1 parent 75d4676 commit 9afef70
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
15 changes: 14 additions & 1 deletion contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,26 @@ def merge_contributors(contributors: list) -> list:
merged_contributors = []
for contributor_list in contributors:
for contributor in contributor_list:
# if the contributor is already in the merged list, add their contribution count into the existing contributor
# if the contributor is already in the merged list, merge their relavent attributes
if contributor.username in [c.username for c in merged_contributors]:
for merged_contributor in merged_contributors:
if merged_contributor.username == contributor.username:
# Merge the contribution counts via addition
merged_contributor.contribution_count += (
contributor.contribution_count
)
# Merge the commit urls via concatenation
merged_contributor.commit_url = (
merged_contributor.commit_url
+ ", "
+ contributor.commit_url
)
# Merge the new_contributor attribute via OR
merged_contributor.new_contributor = (
merged_contributor.new_contributor
or contributor.new_contributor
)

else:
merged_contributors.append(contributor)

Expand Down
2 changes: 1 addition & 1 deletion contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
)

# Output the contributors information
print(contributors)
# print(contributors)
markdown.write_to_markdown(contributors, "contributors.md", start_date, end_date)
# write_to_json(contributors)

Expand Down
2 changes: 1 addition & 1 deletion markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ def write_to_markdown(collaborators, filename, start_date, end_date):
markdown_file.write("# Contributors\n\n")
markdown_file.write(table)
markdown_file.write(
"\n _this file was generated by the [Contributors GitHub Action](https://github.com/github/contributors)\n"
"\n _this file was generated by the [Contributors GitHub Action](https://github.com/github/contributors)_\n"
)
4 changes: 2 additions & 2 deletions test_contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_merge_contributors(self):
False,
"https://avatars.githubusercontent.com/u/29484535?v=4",
150,
"commit_url1",
"commit_url3",
)
all_contributors = [
[
Expand All @@ -75,7 +75,7 @@ def test_merge_contributors(self):
False,
"https://avatars.githubusercontent.com/u/29484535?v=4",
250,
"commit_url1",
"commit_url1, commit_url3",
),
ContributorStats(
"user2",
Expand Down
2 changes: 1 addition & 1 deletion test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors):
False,
"https://avatars.githubusercontent.com/u/29484535?v=4",
200,
"commit_url",
"commit_url, commit_url",
),
],
)
Expand Down

0 comments on commit 9afef70

Please sign in to comment.