diff --git a/.github/workflows/contributors_report_testing.yaml b/.github/workflows/contributors_report_testing.yaml index 1c1aa8b..0c9cf26 100644 --- a/.github/workflows/contributors_report_testing.yaml +++ b/.github/workflows/contributors_report_testing.yaml @@ -56,7 +56,7 @@ jobs: # START_DATE: ${{ env.START_DATE }} # END_DATE: ${{ env.END_DATE }} REPOSITORY: hcookie/organizational_contributors,ecmwf/anemoi-training - SHOW_ORGANIZATIONS: ecmwf + SHOW_ORGANIZATIONS: ecmwf, ecmwf-lab # SPONSOR_INFO: "true" - name: Show Contributor diff --git a/contributors/json_writer.py b/contributors/json_writer.py index 53decac..be79c42 100644 --- a/contributors/json_writer.py +++ b/contributors/json_writer.py @@ -12,7 +12,7 @@ def write_to_json( repository_list, sponsor_info, link_to_profile, - show_organizations_list + show_organizations_list, ): """Write data to a JSON file. diff --git a/contributors/markdown.py b/contributors/markdown.py index fcab55d..b154fca 100644 --- a/contributors/markdown.py +++ b/contributors/markdown.py @@ -2,7 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" -from collections import defaultdict +from collections import defaultdict, OrderedDict from .contributor_stats import ContributorStats @@ -87,12 +87,8 @@ def write_markdown_file(filename, start_date, end_date, organization, repository if len(table) == 1 and "Independent" in table: markdown_file.write(table["Independent"]) else: - # Put independent last - orgs = list(table.keys()) - if 'Independent' in orgs: - orgs.remove('Independent') - orgs.append('Independent') - for org in orgs: + # Put independent last + for org in list(table.keys()): org_title = f"## [{org}](https://github.com/{org})\n" if not org == "Independent" else f"## {org} \n" markdown_file.write(org_title) markdown_file.write(table[org]) @@ -140,6 +136,7 @@ def get_summary_table(collaborators, start_date, end_date, total_contributions): return summary_table + def get_contributor_table( collaborators: list[ContributorStats], start_date, @@ -194,7 +191,6 @@ def get_contributor_table( if not isinstance(repository, list): repository = [repository] - if organization or len(repository) > 1: # split the urls from the comma separated list and make them into markdown links commit_url_list = collaborator.commit_url.split(",") @@ -227,8 +223,14 @@ def get_contributor_table( if not added_to_org: organization_contributors["Independent"].append(row) - - tables = {org: headers + "".join(rows) for org, rows in organization_contributors.items()} + + ordered_orgs = [org for org in (*show_organizations_list, "Independent") if org in organization_contributors] + tables = OrderedDict( + [ + (org, headers + "".join(organization_contributors[org])) + for org in ordered_orgs + ] + ) # table += row return tables, total_contributions diff --git a/tests/test_contributors.py b/tests/test_contributors.py index 6e15545..fc7d6bb 100644 --- a/tests/test_contributors.py +++ b/tests/test_contributors.py @@ -28,13 +28,13 @@ def test_get_contributors(self, mock_contributor_stats): get_contributors(mock_repo, "2022-01-01", "2022-12-31") mock_contributor_stats.assert_called_once_with( - username='user', - new_contributor=False, - avatar_url='https://github.com/avatars/u/12345678?v=4', - contribution_count = 100, - commit_url ='https://github.com/owner/repo/commits?author=user&since=2022-01-01&until=2022-12-31', - sponsor_info='', - organizations=[] + username="user", + new_contributor=False, + avatar_url="https://github.com/avatars/u/12345678?v=4", + contribution_count=100, + commit_url="https://github.com/owner/repo/commits?author=user&since=2022-01-01&until=2022-12-31", + sponsor_info="", + organizations=[], ) @patch("contributors.get_contributors") @@ -55,7 +55,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors): 100, "commit_url", "sponsor_url_1", - [] + [], ), ] @@ -65,13 +65,13 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors): result, [ ContributorStats( - username = "user", + username="user", new_contributor=False, - avatar_url = "https://github.com/avatars/u/29484535?v=4", + avatar_url="https://github.com/avatars/u/29484535?v=4", contribution_count=200, - commit_url = "commit_url, commit_url", - sponsor_info = "sponsor_url_1", - organizations= [], + commit_url="commit_url, commit_url", + sponsor_info="sponsor_url_1", + organizations=[], ), ], ) @@ -136,12 +136,12 @@ def test_get_contributors_skip_users_with_no_commits(self, mock_contributor_stat # Note that only user is returned and user2 is not returned here because there were no commits in the date range mock_contributor_stats.assert_called_once_with( - username = "user", + username="user", new_contributor=False, avatar_url="https://github.com/avatars/u/12345678?v=4", contribution_count=100, commit_url="https://github.com/owner/repo/commits?author=user&since=2022-01-01&until=2022-12-31", - sponsor_info='', + sponsor_info="", organizations=[], ) diff --git a/tests/test_json_writer.py b/tests/test_json_writer.py index 191330c..6f6ae4d 100644 --- a/tests/test_json_writer.py +++ b/tests/test_json_writer.py @@ -27,7 +27,7 @@ def setUp(self): "new_contributor": False, "avatar_url": "https://test_url.com", "contribution_count": 10, - 'organizations': [], + "organizations": [], "commit_url": "https://test_commit_url.com", "sponsor_info": "", }