From 77c57cd77176421f6ea4cf8b9f549cffc423ceb6 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Tue, 10 Nov 2026 05:31:02 +0100 Subject: [PATCH 01/17] feat: add sorting and skip_summary parameters --- README.md | 25 ++++++++++++++----------- contributors.py | 8 ++++++++ env.py | 25 +++++++++++++++++++++++++ json_writer.py | 8 ++++++++ markdown.py | 29 +++++++++++++++++++++++++---- 5 files changed, 80 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5a99c79..69bb8e4 100644 --- a/README.md +++ b/README.md @@ -95,17 +95,20 @@ This action can be configured to authenticate with GitHub App Installation or Pe #### Other Configuration Options -| field | required | default | description | -| ------------------- | ----------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. | -| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` | -| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` | -| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. | -| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` | -| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" | -| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" | -| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" | -| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" | +| field | required | default | description | +| ------------------- | ----------------------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. | +| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` | +| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` | +| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. | +| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` | +| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" | +| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" | +| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" | +| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" | +| `SORT_COLUMN` | False | contribution_count| The column you want to sort the table with. Possible values: `username` (column of strings), `contribution_count` (column of integers) or `new_contributor` (column of booleans, whether the given username is a new contributor) | +| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: "asc" for ascending order or "desc" for descending order. | +| `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" | **Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date. diff --git a/contributors.py b/contributors.py index ad790bb..be6dff7 100644 --- a/contributors.py +++ b/contributors.py @@ -29,6 +29,9 @@ def main(): link_to_profile, output_filename, show_avatar, + sort_column, + sort_order, + skip_summary, ) = env.get_env_vars() # Auth to GitHub.com @@ -86,6 +89,9 @@ def main(): link_to_profile, ghe, show_avatar, + sort_column, + sort_order, + skip_summary, ) json_writer.write_to_json( filename="contributors.json", @@ -96,6 +102,8 @@ def main(): sponsor_info=sponsor_info, link_to_profile=link_to_profile, contributors=contributors, + sort_column=sort_column, + sort_order=sort_order, ) diff --git a/env.py b/env.py index a36c631..0bb04ce 100644 --- a/env.py +++ b/env.py @@ -7,6 +7,7 @@ import os import re from os.path import dirname, join +from typing import List from dotenv import load_dotenv @@ -132,6 +133,17 @@ def validate_output_filename(output_filename: str) -> str: return filename +def validate_allowed_values(env_var_name: str, allowed_values: List[str], default: str) -> str: + """Check that env variable is contained in a list of defined values or set a default one. + Returns a lowercase value. + """ + allowed_values = [val.strip().lower() for val in allowed_values] + var_to_validate = os.getenv(env_var_name, default).strip().lower() + if var_to_validate in allowed_values: + return var_to_validate + return default.strip().lower() + + def get_env_vars( test: bool = False, ) -> tuple[ @@ -149,6 +161,9 @@ def get_env_vars( bool, str, bool, + str, + str, + str, ]: """ Get the environment variables for use in the action. @@ -169,6 +184,9 @@ def get_env_vars( end_date (str): The end date to get contributor information to sponsor_info (str): Whether to get sponsor information on the contributor link_to_profile (str): Whether to link username to Github profile in markdown output + sort_column (str): The column the table should be sorted by ('username', 'contribution_count' or 'new_contributor'). Case insensitive. + sort_order (str): The sorting order ('asc' or 'desc'). Case insensitive. + skip_summary (str): Whether to print the summary before the table """ if not test: @@ -222,6 +240,10 @@ def get_env_vars( repository.strip() for repository in repositories_str.split(",") ] + sort_column = validate_allowed_values('SORT_COLUMN', ['username', 'contribution_count', 'new_contributor'], 'contribution_count') + sort_order = validate_allowed_values('SORT_ORDER', ['asc', 'desc'], 'desc') + skip_summary = get_bool_env_var("SKIP_SUMMARY", False) + return ( organization, repositories_list, @@ -237,4 +259,7 @@ def get_env_vars( link_to_profile, output_filename, show_avatar, + sort_column, + sort_order, + skip_summary, ) diff --git a/json_writer.py b/json_writer.py index 9ae5961..5d6e97c 100644 --- a/json_writer.py +++ b/json_writer.py @@ -1,6 +1,7 @@ """This module contains a function that writes data to a JSON file.""" import json +from operator import attrgetter def write_to_json( @@ -12,6 +13,8 @@ def write_to_json( repository_list, sponsor_info, link_to_profile, + sort_column, + sort_order, ): """Write data to a JSON file. @@ -63,6 +66,11 @@ def write_to_json( # } # ] # } + + # Sort the list by chosen column and order + is_reverse = sort_order == 'desc' + contributors.sort(key=attrgetter(sort_column), reverse=is_reverse) + data = { "start_date": start_date, "end_date": end_date, diff --git a/markdown.py b/markdown.py index a40b276..bbd741b 100644 --- a/markdown.py +++ b/markdown.py @@ -2,6 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" import os +from operator import itemgetter def _is_truthy(value) -> bool: @@ -20,6 +21,9 @@ def write_to_markdown( sponsor_info, link_to_profile, ghe, + sort_column, + sort_order, + skip_summary, show_avatar=False, ): """ @@ -47,6 +51,10 @@ def write_to_markdown( link_to_profile (str): True if the user wants the username linked to Github profile in the report ghe (str): The GitHub Enterprise instance URL, if applicable. + sort_column (str): the column to sort the table with ('username', + 'contribution_count' or 'new_contributor') + sort_order (str): the order to sort the column with (`asc` or `desc`) + skip_summary (str): True if the user wants the summary not to be printed show_avatar (str): True if the user wants to show profile images in the report @@ -64,6 +72,8 @@ def write_to_markdown( sponsor_info, link_to_profile, ghe, + sort_column, + sort_order, show_avatar, ) @@ -75,7 +85,7 @@ def write_to_markdown( # Generate the markdown content once content = generate_markdown_content( - start_date, end_date, organization, repository, table, summary_table + start_date, end_date, organization, repository, table, summary_table, skip_summary ) # Write the markdown file @@ -104,7 +114,7 @@ def write_to_github_summary(content): def generate_markdown_content( - start_date, end_date, organization, repository, table, summary_table + start_date, end_date, organization, repository, table, summary_table, skip_summary ): """ This function generates markdown content as a string. @@ -121,6 +131,7 @@ def generate_markdown_content( and the total contribution count. summary_table (str): A string containing a markdown table of the summary statistics. + skip_summary (str): True if the user wants the summary not to be printed. Returns: str: The complete markdown content as a string. @@ -134,7 +145,8 @@ def generate_markdown_content( if repository: content += f"- Repository: {repository}\n" content += "\n" - content += summary_table + if not skip_summary: + content += summary_table content += table content += ( "\n _this file was generated by the " @@ -204,6 +216,8 @@ def get_contributor_table( sponsor_info, link_to_profile, ghe, + sort_column, + sort_order, show_avatar=False, ): """ @@ -218,6 +232,9 @@ def get_contributor_table( repository (str): The repository for which the contributors are being listed. sponsor_info (str): True if the user wants the sponsor_url shown in the report link_to_profile (str): True if the user wants the username linked to Github profile in the report + sort_column (str): the column to sort the table with ('username', + 'contribution_count' or 'new_contributor') + sort_order (str): the order to sort the column with (`asc` or `desc`) show_avatar (str): True if the user wants to show profile images in the report Returns: @@ -249,7 +266,11 @@ def get_contributor_table( table = headers total_contributions = 0 - for collaborator in collaborators: + # Sort the list by chosen column and order + is_reverse = sort_order == 'desc' + sorted_collaborators = sorted(collaborators, key=itemgetter(sort_column), reverse=is_reverse) + + for collaborator in sorted_collaborators: total_contributions += collaborator.contribution_count username = collaborator.username contribution_count = collaborator.contribution_count From 7c969c16fa789e9debcbcb9a7678c543d89264f5 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Tue, 10 Nov 2026 07:42:43 +0100 Subject: [PATCH 02/17] feat: add sorting and skip_summary parameters - lint and tests --- env.py | 16 ++- json_writer.py | 10 +- markdown.py | 16 ++- test_contributors.py | 9 ++ test_env.py | 84 +++++++++++++ test_json_writer.py | 4 + test_markdown.py | 278 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 406 insertions(+), 11 deletions(-) diff --git a/env.py b/env.py index 0bb04ce..e165f16 100644 --- a/env.py +++ b/env.py @@ -133,9 +133,11 @@ def validate_output_filename(output_filename: str) -> str: return filename -def validate_allowed_values(env_var_name: str, allowed_values: List[str], default: str) -> str: +def validate_allowed_values( + env_var_name: str, allowed_values: List[str], default: str +) -> str: """Check that env variable is contained in a list of defined values or set a default one. - Returns a lowercase value. + Returns a lowercase value. """ allowed_values = [val.strip().lower() for val in allowed_values] var_to_validate = os.getenv(env_var_name, default).strip().lower() @@ -163,7 +165,7 @@ def get_env_vars( bool, str, str, - str, + bool, ]: """ Get the environment variables for use in the action. @@ -240,8 +242,12 @@ def get_env_vars( repository.strip() for repository in repositories_str.split(",") ] - sort_column = validate_allowed_values('SORT_COLUMN', ['username', 'contribution_count', 'new_contributor'], 'contribution_count') - sort_order = validate_allowed_values('SORT_ORDER', ['asc', 'desc'], 'desc') + sort_column = validate_allowed_values( + "SORT_COLUMN", + ["username", "contribution_count", "new_contributor"], + "contribution_count", + ) + sort_order = validate_allowed_values("SORT_ORDER", ["asc", "desc"], "desc") skip_summary = get_bool_env_var("SKIP_SUMMARY", False) return ( diff --git a/json_writer.py b/json_writer.py index 5d6e97c..98d0be7 100644 --- a/json_writer.py +++ b/json_writer.py @@ -27,6 +27,8 @@ def write_to_json( repository_list (list): A list of repositories for which the contributors are being listed. sponsor_info (str): A string indicating whether sponsor information should be included. link_to_profile (str): A string indicating whether a link to the contributor's profile should be included. + sort_column (str): the column to sort the table with ('username', 'contribution_count' or 'new_contributor'). + sort_order (str): the order to sort the column with (`asc` or `desc`). Returns: None @@ -47,6 +49,8 @@ def write_to_json( # ], # "sponsor_info": false, # "link_to_profile": false, + # "sort_column": "contribution_count" + # "sort_order": "desc" # "contributors": [ # { # "username": "zkoppert", @@ -68,8 +72,8 @@ def write_to_json( # } # Sort the list by chosen column and order - is_reverse = sort_order == 'desc' - contributors.sort(key=attrgetter(sort_column), reverse=is_reverse) + is_reverse = sort_order == "desc" + contributors = sorted(contributors, key=attrgetter(sort_column), reverse=is_reverse) data = { "start_date": start_date, @@ -78,6 +82,8 @@ def write_to_json( "repository_list": repository_list, "sponsor_info": sponsor_info, "link_to_profile": link_to_profile, + "sort_column": sort_column, + "sort_order": sort_order, "contributors": [contributor.__dict__ for contributor in contributors], } diff --git a/markdown.py b/markdown.py index bbd741b..ccbf406 100644 --- a/markdown.py +++ b/markdown.py @@ -2,7 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" import os -from operator import itemgetter +from operator import attrgetter def _is_truthy(value) -> bool: @@ -85,7 +85,13 @@ def write_to_markdown( # Generate the markdown content once content = generate_markdown_content( - start_date, end_date, organization, repository, table, summary_table, skip_summary + start_date, + end_date, + organization, + repository, + table, + summary_table, + skip_summary, ) # Write the markdown file @@ -267,8 +273,10 @@ def get_contributor_table( total_contributions = 0 # Sort the list by chosen column and order - is_reverse = sort_order == 'desc' - sorted_collaborators = sorted(collaborators, key=itemgetter(sort_column), reverse=is_reverse) + is_reverse = sort_order == "desc" + sorted_collaborators = sorted( + collaborators, key=attrgetter(sort_column), reverse=is_reverse + ) for collaborator in sorted_collaborators: total_contributions += collaborator.contribution_count diff --git a/test_contributors.py b/test_contributors.py index a865344..f1d8e11 100644 --- a/test_contributors.py +++ b/test_contributors.py @@ -349,6 +349,9 @@ def test_main_runs_under_main_guard(self): False, "contributors.md", False, + "contribution_count", + "desc", + False, ) mock_auth = MagicMock() @@ -423,6 +426,9 @@ def test_main_sets_new_contributor_flag(self): False, "contributors.md", False, + "contribution_count", + "desc", + False, ) mock_auth_to_github.return_value = MagicMock() mock_get_all_contributors.side_effect = [[contributor], []] @@ -478,6 +484,9 @@ def test_main_fetches_sponsor_info_when_enabled(self): False, "contributors.md", False, + "contribution_count", + "desc", + False, ) mock_auth_to_github.return_value = MagicMock() mock_get_all_contributors.return_value = [contributor] diff --git a/test_env.py b/test_env.py index 6c0feb9..2ce701b 100644 --- a/test_env.py +++ b/test_env.py @@ -27,6 +27,9 @@ def setUp(self): "REPOSITORY", "START_DATE", "SHOW_AVATAR", + "SORT_COLUMN", + "SORT_ORDER", + "SKIP_SUMMARY", ] for key in env_keys: if key in os.environ: @@ -47,6 +50,9 @@ def setUp(self): "SPONSOR_INFO": "False", "LINK_TO_PROFILE": "True", "SHOW_AVATAR": "False", + "SORT_COLUMN": "username", + "SORT_ORDER": "asc", + "SKIP_SUMMARY": "True", }, clear=True, ) @@ -70,6 +76,9 @@ def test_get_env_vars(self): link_to_profile, _output_filename, _show_avatar, + sort_column, + sort_order, + skip_summary, ) = env.get_env_vars() self.assertEqual(organization, "org") @@ -84,6 +93,9 @@ def test_get_env_vars(self): self.assertEqual(end_date, "2022-12-31") self.assertFalse(sponsor_info) self.assertTrue(link_to_profile) + self.assertEqual(sort_column, "username") + self.assertEqual(sort_order, "asc") + self.assertTrue(skip_summary) @patch.dict( os.environ, @@ -100,6 +112,9 @@ def test_get_env_vars(self): "SPONSOR_INFO": "False", "LINK_TO_PROFILE": "True", "SHOW_AVATAR": "False", + "SORT_COLUMN": "username", + "SORT_ORDER": "asc", + "SKIP_SUMMARY": "True", }, clear=True, ) @@ -129,6 +144,9 @@ def test_get_env_vars_missing_values(self): "SPONSOR_INFO": "False", "LINK_TO_PROFILE": "True", "SHOW_AVATAR": "False", + "SORT_COLUMN": "username", + "SORT_ORDER": "asc", + "SKIP_SUMMARY": "True", }, clear=True, ) @@ -161,6 +179,9 @@ def test_get_env_vars_invalid_start_date(self): "SPONSOR_INFO": "False", "LINK_TO_PROFILE": "True", "SHOW_AVATAR": "False", + "SORT_COLUMN": "username", + "SORT_ORDER": "asc", + "SKIP_SUMMARY": "True", }, clear=True, ) @@ -185,6 +206,9 @@ def test_get_env_vars_no_dates(self): link_to_profile, _output_filename, _show_avatar, + sort_column, + sort_order, + skip_summary, ) = env.get_env_vars() self.assertEqual(organization, "org") @@ -199,6 +223,9 @@ def test_get_env_vars_no_dates(self): self.assertEqual(end_date, "") self.assertFalse(sponsor_info) self.assertTrue(link_to_profile) + self.assertEqual(sort_column, "username") + self.assertEqual(sort_order, "asc") + self.assertTrue(skip_summary) @patch.dict( os.environ, @@ -215,6 +242,9 @@ def test_get_env_vars_no_dates(self): "SPONSOR_INFO": "False", "LINK_TO_PROFILE": "True", "OUTPUT_FILENAME": "custom-report.md", + "SORT_COLUMN": "username", + "SORT_ORDER": "asc", + "SKIP_SUMMARY": "True", }, clear=True, ) @@ -235,6 +265,9 @@ def test_get_env_vars_custom_output_filename(self): _link_to_profile, output_filename, _show_avatar, + _sort_column, + _sort_order, + _skip_summary, ) = env.get_env_vars() self.assertEqual(output_filename, "custom-report.md") @@ -321,6 +354,9 @@ def test_get_env_vars_output_filename_empty_defaults(self): _link_to_profile, output_filename, _show_avatar, + _sort_column, + _sort_order, + _skip_summary, ) = env.get_env_vars() self.assertEqual(output_filename, "contributors.md") @@ -351,6 +387,9 @@ def test_get_env_vars_output_filename_whitespace_defaults(self): _link_to_profile, output_filename, _show_avatar, + _sort_column, + _sort_order, + _skip_summary, ) = env.get_env_vars() self.assertEqual(output_filename, "contributors.md") @@ -471,6 +510,9 @@ def test_get_env_vars_valid_date_range(self): _link_to_profile, _output_filename, _show_avatar, + _sort_column, + _sort_order, + _skip_summary, ) = env.get_env_vars() self.assertEqual(start_date, "2024-01-01") self.assertEqual(end_date, "2025-01-01") @@ -490,6 +532,48 @@ def test_validate_date_range_invalid_date_format_raises(self): "start_date and end_date must be in the format YYYY-MM-DD", ) + @patch.dict( + os.environ, + { + "ORGANIZATION": "org", + "REPOSITORY": "repo,repo2", + "GH_TOKEN": "token", + "SORT_COLUMN": "Whatever", + "SORT_ORDER": "ASc", + }, + clear=True, + ) + def test_get_env_vars_with_absent_or_invalid_sort_and_skip_summary_params(self): + """ + Test the get_env_vars function checking that default sorting and skip_summary params + are correctly applied in case of invalid (sort_column) or absent (skip_summary) definition, and that lowercase + conversion is applied (sort_order) + """ + + ( + _organization, + _repository_list, + _gh_app_id, + _gh_app_installation_id, + _gh_app_private_key, + _gh_app_enterprise_only, + _token, + _ghe, + _start_date, + _end_date, + _sponsor_info, + _link_to_profile, + _output_filename, + _show_avatar, + sort_column, + sort_order, + skip_summary, + ) = env.get_env_vars() + + self.assertEqual(sort_column, "contribution_count") + self.assertEqual(sort_order, "asc") + self.assertFalse(skip_summary) + if __name__ == "__main__": unittest.main() diff --git a/test_json_writer.py b/test_json_writer.py index e5c0052..95b3496 100644 --- a/test_json_writer.py +++ b/test_json_writer.py @@ -21,6 +21,8 @@ def setUp(self): "repository_list": ["repo1", "repo2"], "sponsor_info": False, "link_to_profile": False, + "sort_column": "contribution_count", + "sort_order": "desc", "contributors": [ { "username": "test_user", @@ -54,6 +56,8 @@ def test_write_to_json(self): repository_list=self.data["repository_list"], sponsor_info=self.data["sponsor_info"], link_to_profile=self.data["link_to_profile"], + sort_column=self.data["sort_column"], + sort_order=self.data["sort_order"], ) with open(self.filename, "r", encoding="utf-8") as f: result = json.load(f) diff --git a/test_markdown.py b/test_markdown.py index 006735e..52e0ac7 100644 --- a/test_markdown.py +++ b/test_markdown.py @@ -54,6 +54,9 @@ def test_write_to_markdown( "false", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -118,6 +121,9 @@ def test_write_to_markdown_with_sponsors( "true", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -182,6 +188,9 @@ def test_write_to_markdown_with_avatars( "false", True, ghe, + "contribution_count", + "asc", + False, show_avatar=True, ) @@ -249,6 +258,9 @@ def test_write_to_markdown_without_link_to_profile( "false", False, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -312,6 +324,9 @@ def test_write_to_github_summary( "false", True, ghe, + "contribution_count", + "asc", + False, ) # Verify that open was called twice - once for the markdown file @@ -371,6 +386,9 @@ def test_write_to_markdown_with_organization( "false", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -419,6 +437,9 @@ def test_write_to_markdown_empty_collaborators( "false", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -479,6 +500,9 @@ def test_write_to_markdown_no_dates( "false", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -529,6 +553,9 @@ def test_write_to_markdown_with_ghe( "false", True, ghe, + "contribution_count", + "asc", + False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -551,6 +578,257 @@ def test_write_to_markdown_with_ghe( ) mock_file().write.assert_called_once_with(expected_content) + @patch( + "markdown.os.environ.get", return_value=None + ) # Mock GITHUB_STEP_SUMMARY to None + @patch("builtins.open", new_callable=mock_open) + def test_write_to_markdown_sort_username_asc( + self, mock_file, mock_env_get + ): # pylint: disable=unused-argument + """ + Test sorting by username in ascending order. + """ + person1 = contributor_stats.ContributorStats( + "zzz_user1", + "url", + 100, + "commit url", + "sponsor_url_1", + ) + person2 = contributor_stats.ContributorStats( + "aaa_user2", + "url2", + 200, + "commit url2", + "sponsor_url_2", + ) + collaborators = [ + person1, + person2, + ] + ghe = "" + + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + None, + "org/repo", + "false", + True, + ghe, + "username", + "asc", + False, + ) + + mock_file.assert_called_once_with("filename", "w", encoding="utf-8") + # With the new implementation, content is written as a single string + expected_content = ( + "# Contributors\n\n" + "- Date range for contributor list: 2023-01-01 to 2023-01-02\n" + "- Repository: org/repo\n\n" + "| Total Contributors | Total Contributions | % New Contributors |\n" + "| --- | --- | --- |\n" + "| 2 | 300 | 0.0% |\n\n" + "| Username | Contribution Count | New Contributor | " + "Commits between 2023-01-01 and 2023-01-02 |\n" + "| --- | --- | --- | --- |\n" + "| @aaa_user2 | 200 | False | commit url2 |\n" + "| @zzz_user1 | 100 | False | commit url |\n" + "\n _this file was generated by the " + "[Contributors GitHub Action]" + "(https://github.com/github-community-projects/contributors)_\n" + ) + mock_file().write.assert_called_once_with(expected_content) + + @patch( + "markdown.os.environ.get", return_value=None + ) # Mock GITHUB_STEP_SUMMARY to None + @patch("builtins.open", new_callable=mock_open) + def test_write_to_markdown_sort_contribution_count_desc( + self, mock_file, mock_env_get + ): # pylint: disable=unused-argument + """ + Test sorting by contribution_count in descending order. + """ + person1 = contributor_stats.ContributorStats( + "user1", + "url", + 100, + "commit url", + "sponsor_url_1", + ) + person2 = contributor_stats.ContributorStats( + "user2", + "url2", + 200, + "commit url2", + "sponsor_url_2", + ) + collaborators = [ + person1, + person2, + ] + ghe = "" + + write_to_markdown( + collaborators, + "filename", + None, + None, + None, + "org/repo", + "false", + True, + ghe, + "contribution_count", + "desc", + False, + ) + + mock_file.assert_called_once_with("filename", "w", encoding="utf-8") + # With the new implementation, content is written as a single string + expected_content = ( + "# Contributors\n\n" + "- Repository: org/repo\n\n" + "| Total Contributors | Total Contributions |\n" + "| --- | --- |\n" + "| 2 | 300 |\n\n" + "| Username | All Time Contribution Count | All Commits |\n" + "| --- | --- | --- |\n" + "| @user2 | 200 | commit url2 |\n" + "| @user1 | 100 | commit url |\n" + "\n _this file was generated by the " + "[Contributors GitHub Action]" + "(https://github.com/github-community-projects/contributors)_\n" + ) + mock_file().write.assert_called_once_with(expected_content) + + @patch( + "markdown.os.environ.get", return_value=None + ) # Mock GITHUB_STEP_SUMMARY to None + @patch("builtins.open", new_callable=mock_open) + def test_write_to_markdown_with_organization_sort_new_contributor_desc( + self, mock_file, mock_env_get + ): # pylint: disable=unused-argument + """ + Test the write_to_markdown function with organization specified and sorting + by 'new_contributor' in descending order + """ + person1 = contributor_stats.ContributorStats( + "user1", + "url", + 100, + "https://github.com/org1/repo1/commits?author=user1", + "sponsor_url_1", + ) + person2 = contributor_stats.ContributorStats( + "user2", + "url2", + 200, + "https://github.com/org2/repo2/commits?author=user2, " + "https://github.com/org3/repo3/commits?author=user2", + "sponsor_url_2", + ) + # Set person2 as a new contributor since this cannot be set on initialization of the object + person2.new_contributor = True + collaborators = [ + person1, + person2, + ] + ghe = "" + + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + "test-org", + None, + "false", + True, + ghe, + "new_contributor", + "desc", + False, + ) + + mock_file.assert_called_once_with("filename", "w", encoding="utf-8") + # With the new implementation, content is written as a single string + expected_content = ( + "# Contributors\n\n" + "- Date range for contributor list: 2023-01-01 to 2023-01-02\n" + "- Organization: test-org\n\n" + "| Total Contributors | Total Contributions | % New Contributors |\n" + "| --- | --- | --- |\n" + "| 2 | 300 | 50.0% |\n\n" + "| Username | Contribution Count | New Contributor | " + "Commits between 2023-01-01 and 2023-01-02 |\n" + "| --- | --- | --- | --- |\n" + "| @user2 | 200 | True | " + "[org2/repo2](https://github.com/org2/repo2/commits?author=user2), " + "[org3/repo3](https://github.com/org3/repo3/commits?author=user2), |\n" + "| @user1 | 100 | False | " + "[org1/repo1](https://github.com/org1/repo1/commits?author=user1), |\n" + "\n _this file was generated by the " + "[Contributors GitHub Action]" + "(https://github.com/github-community-projects/contributors)_\n" + ) + mock_file().write.assert_called_once_with(expected_content) + + @patch( + "markdown.os.environ.get", return_value=None + ) # Mock GITHUB_STEP_SUMMARY to None + @patch("builtins.open", new_callable=mock_open) + def test_write_to_markdown_skipping_summary( + self, mock_file, mock_env_get + ): # pylint: disable=unused-argument + """ + Test skipping the summary table. + """ + person1 = contributor_stats.ContributorStats( + "user1", + "url", + 100, + "commit url", + "sponsor_url_1", + ) + collaborators = [person1] + ghe = "" + + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + None, + "org/repo", + "false", + True, + ghe, + "contribution_count", + "asc", + True, + ) + + mock_file.assert_called_once_with("filename", "w", encoding="utf-8") + # With the new implementation, content is written as a single string + expected_content = ( + "# Contributors\n\n" + "- Date range for contributor list: 2023-01-01 to 2023-01-02\n" + "- Repository: org/repo\n\n" + "| Username | Contribution Count | New Contributor | " + "Commits between 2023-01-01 and 2023-01-02 |\n" + "| --- | --- | --- | --- |\n" + "| @user1 | 100 | False | commit url |\n" + "\n _this file was generated by the " + "[Contributors GitHub Action]" + "(https://github.com/github-community-projects/contributors)_\n" + ) + mock_file().write.assert_called_once_with(expected_content) + if __name__ == "__main__": unittest.main() From 6b8b53c6b64512bdd7e2db55185d0e4ca6c6c65d Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:36:55 +0100 Subject: [PATCH 03/17] fix: make new arguments keyword arguments and reorder to improve compatibility with previous versions --- contributors.py | 8 ++++---- markdown.py | 20 ++++++++++---------- test_markdown.py | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/contributors.py b/contributors.py index be6dff7..b1493f1 100644 --- a/contributors.py +++ b/contributors.py @@ -88,10 +88,10 @@ def main(): sponsor_info, link_to_profile, ghe, - show_avatar, - sort_column, - sort_order, - skip_summary, + show_avatar=show_avatar, + sort_column=sort_column, + sort_order=sort_order, + skip_summary=skip_summary, ) json_writer.write_to_json( filename="contributors.json", diff --git a/markdown.py b/markdown.py index ccbf406..6b4550b 100644 --- a/markdown.py +++ b/markdown.py @@ -21,10 +21,10 @@ def write_to_markdown( sponsor_info, link_to_profile, ghe, - sort_column, - sort_order, - skip_summary, show_avatar=False, + sort_column="contribution_count", + sort_order="desc", + skip_summary=False, ): """ This function writes a list of collaborators to a markdown file in table format @@ -33,7 +33,7 @@ def write_to_markdown( 'contribution_count', 'new_contributor', and 'commits'. Args: - collaborators (list): A list of dictionaries, where each dictionary + collaborators (list): A tuple of objects, where each object represents a collaborator. Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. @@ -51,12 +51,12 @@ def write_to_markdown( link_to_profile (str): True if the user wants the username linked to Github profile in the report ghe (str): The GitHub Enterprise instance URL, if applicable. + show_avatar (str): True if the user wants to show profile images in + the report sort_column (str): the column to sort the table with ('username', 'contribution_count' or 'new_contributor') sort_order (str): the order to sort the column with (`asc` or `desc`) skip_summary (str): True if the user wants the summary not to be printed - show_avatar (str): True if the user wants to show profile images in - the report Returns: None @@ -72,9 +72,9 @@ def write_to_markdown( sponsor_info, link_to_profile, ghe, + show_avatar, sort_column, sort_order, - show_avatar, ) # Put together the summary table including # of new contributions, @@ -222,9 +222,9 @@ def get_contributor_table( sponsor_info, link_to_profile, ghe, - sort_column, - sort_order, show_avatar=False, + sort_column="contribution_count", + sort_order="desc", ): """ This function returns a string containing a markdown table of the contributors and the total contribution count. @@ -238,10 +238,10 @@ def get_contributor_table( repository (str): The repository for which the contributors are being listed. sponsor_info (str): True if the user wants the sponsor_url shown in the report link_to_profile (str): True if the user wants the username linked to Github profile in the report + show_avatar (str): True if the user wants to show profile images in the report sort_column (str): the column to sort the table with ('username', 'contribution_count' or 'new_contributor') sort_order (str): the order to sort the column with (`asc` or `desc`) - show_avatar (str): True if the user wants to show profile images in the report Returns: table (str): A string containing a markdown table of the contributors and the total contribution count. diff --git a/test_markdown.py b/test_markdown.py index 52e0ac7..7f45591 100644 --- a/test_markdown.py +++ b/test_markdown.py @@ -54,6 +54,7 @@ def test_write_to_markdown( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -121,6 +122,7 @@ def test_write_to_markdown_with_sponsors( "true", True, ghe, + False, "contribution_count", "asc", False, @@ -188,10 +190,10 @@ def test_write_to_markdown_with_avatars( "false", True, ghe, - "contribution_count", - "asc", - False, show_avatar=True, + sort_column="contribution_count", + sort_order="asc", + skip_summary=False, ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") @@ -258,6 +260,7 @@ def test_write_to_markdown_without_link_to_profile( "false", False, ghe, + False, "contribution_count", "asc", False, @@ -324,6 +327,7 @@ def test_write_to_github_summary( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -386,6 +390,7 @@ def test_write_to_markdown_with_organization( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -437,6 +442,7 @@ def test_write_to_markdown_empty_collaborators( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -500,6 +506,7 @@ def test_write_to_markdown_no_dates( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -553,6 +560,7 @@ def test_write_to_markdown_with_ghe( "false", True, ghe, + False, "contribution_count", "asc", False, @@ -618,6 +626,7 @@ def test_write_to_markdown_sort_username_asc( "false", True, ghe, + False, "username", "asc", False, @@ -683,6 +692,7 @@ def test_write_to_markdown_sort_contribution_count_desc( "false", True, ghe, + False, "contribution_count", "desc", False, @@ -750,6 +760,7 @@ def test_write_to_markdown_with_organization_sort_new_contributor_desc( "false", True, ghe, + False, "new_contributor", "desc", False, @@ -808,6 +819,7 @@ def test_write_to_markdown_skipping_summary( "false", True, ghe, + False, "contribution_count", "asc", True, From 0ad4b0c280756a7d9027ad5bc8a712400192d03f Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Tue, 24 Nov 2026 06:04:27 +0100 Subject: [PATCH 04/17] fix: make sorting case insentitive and using natural sort --- json_writer.py | 10 ++++++---- markdown.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/json_writer.py b/json_writer.py index 98d0be7..4fec7e6 100644 --- a/json_writer.py +++ b/json_writer.py @@ -1,7 +1,7 @@ """This module contains a function that writes data to a JSON file.""" import json -from operator import attrgetter +import re def write_to_json( @@ -71,9 +71,11 @@ def write_to_json( # ] # } - # Sort the list by chosen column and order - is_reverse = sort_order == "desc" - contributors = sorted(contributors, key=attrgetter(sort_column), reverse=is_reverse) + # Sort the list by chosen column and order, case insensitive order, natural sort (adapted from Mark Byers' snippet published under CC-BY-SA license at https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort/4836734#4836734) + is_reverse = sort_order == "desc" #default to desc + convert = lambda text: int(text) if text.isdigit() else text.casefold() + alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', str(key))] + contributors = sorted(contributors, key=lambda x: alphanum_key(getattr(x, sort_column)), reverse=is_reverse) data = { "start_date": start_date, diff --git a/markdown.py b/markdown.py index 6b4550b..590228c 100644 --- a/markdown.py +++ b/markdown.py @@ -2,7 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" import os -from operator import attrgetter +import re def _is_truthy(value) -> bool: @@ -272,10 +272,12 @@ def get_contributor_table( table = headers total_contributions = 0 - # Sort the list by chosen column and order - is_reverse = sort_order == "desc" + # Sort the list by chosen column and order, case insensitive order, natural sort (adapted from Mark Byers' snippet published under CC-BY-SA license at https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort/4836734#4836734) + is_reverse = sort_order == "desc" #default to desc + convert = lambda text: int(text) if text.isdigit() else text.casefold() + alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', str(key))] sorted_collaborators = sorted( - collaborators, key=attrgetter(sort_column), reverse=is_reverse + collaborators, key=lambda x: alphanum_key(getattr(x, sort_column)), reverse=is_reverse ) for collaborator in sorted_collaborators: From 925fe473eeb34040cf40aebc71c691a47ccfcc37 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Tue, 24 Nov 2026 06:08:47 +0100 Subject: [PATCH 05/17] fix: typo in sample json --- json_writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_writer.py b/json_writer.py index 4fec7e6..a696577 100644 --- a/json_writer.py +++ b/json_writer.py @@ -49,8 +49,8 @@ def write_to_json( # ], # "sponsor_info": false, # "link_to_profile": false, - # "sort_column": "contribution_count" - # "sort_order": "desc" + # "sort_column": "contribution_count", + # "sort_order": "desc", # "contributors": [ # { # "username": "zkoppert", From e306cab9eb30c022b003cc571169fe157dcc5b27 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:38:03 +0100 Subject: [PATCH 06/17] fix: pass README.md through prettier --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 69bb8e4..53b897d 100644 --- a/README.md +++ b/README.md @@ -95,20 +95,20 @@ This action can be configured to authenticate with GitHub App Installation or Pe #### Other Configuration Options -| field | required | default | description | -| ------------------- | ----------------------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. | -| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` | -| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` | -| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. | -| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` | -| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" | -| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" | -| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" | -| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" | -| `SORT_COLUMN` | False | contribution_count| The column you want to sort the table with. Possible values: `username` (column of strings), `contribution_count` (column of integers) or `new_contributor` (column of booleans, whether the given username is a new contributor) | -| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: "asc" for ascending order or "desc" for descending order. | -| `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" | +| field | required | default | description | +| ------------------- | ----------------------------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `GH_ENTERPRISE_URL` | False | "" | The `GH_ENTERPRISE_URL` is used to connect to an enterprise server instance of GitHub. github.com users should not enter anything here. | +| `ORGANIZATION` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the GitHub organization which you want the contributor information of all repos from. ie. github.com/github would be `github` | +| `REPOSITORY` | Required to have `ORGANIZATION` or `REPOSITORY` | | The name of the repository and organization which you want the contributor information from. ie. `github/contributors` or a comma separated list of multiple repositories `github/contributor,super-linter/super-linter` | +| `START_DATE` | False | Beginning of time | The date from which you want to start gathering contributor information. ie. Aug 1st, 2023 would be `2023-08-01`. | +| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` | +| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" | +| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" | +| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" | +| `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" | +| `SORT_COLUMN` | False | contribution_count | The column you want to sort the table with. Possible values: `username` (column of strings), `contribution_count` (column of integers) or `new_contributor` (column of booleans, whether the given username is a new contributor) | +| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: "asc" for ascending order or "desc" for descending order. | +| `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" | **Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date. From 0e9cdc77cfcb81641db1232982b89194c3933d27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:48:39 -0800 Subject: [PATCH 07/17] chore(deps): bump mypy-extensions (#564) Bumps the dependencies group with 1 update: [mypy-extensions](https://github.com/python/mypy_extensions). Updates `mypy-extensions` from 1.1.0 to 1.2.0 - [Commits](https://github.com/python/mypy_extensions/compare/1.1.0...1.2.0) --- updated-dependencies: - dependency-name: mypy-extensions dependency-version: 1.2.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- uv.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3516819..f54d8a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ dev = [ "black==26.10.1", "flake8==7.5.0", "mypy==2.4.1", - "mypy-extensions==1.1.0", + "mypy-extensions==1.2.0", "pylint==4.1.3", "pytest==9.2.0", "pytest-cov==7.1.0", diff --git a/uv.lock b/uv.lock index ecf69da..604e5f5 100644 --- a/uv.lock +++ b/uv.lock @@ -324,7 +324,7 @@ dev = [ { name = "black", specifier = "==26.10.1" }, { name = "flake8", specifier = "==7.5.0" }, { name = "mypy", specifier = "==2.4.1" }, - { name = "mypy-extensions", specifier = "==1.1.0" }, + { name = "mypy-extensions", specifier = "==1.2.0" }, { name = "pylint", specifier = "==4.1.3" }, { name = "pytest", specifier = "==9.2.0" }, { name = "pytest-cov", specifier = "==7.1.0" }, @@ -728,11 +728,11 @@ wheels = [ [[package]] name = "mypy-extensions" -version = "1.1.0" +version = "1.2.0" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/a2/6e/371856a3fb9d31ca8dac321cda606860fa4548858c0cc45d9d1d4ca2628b/mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558", size = 6343, upload-time = "2025-04-22T14:54:24.164Z" } +sdist = { url = "https://files.pythonhosted.org/packages/d0/6f/43edf3be2748d0e40974a5ee046a8bb4c9961a4bdd3e7d5c6dcbf32d1af6/mypy_extensions-1.2.0.tar.gz", hash = "sha256:c6e275a07f1c2fc096b62940452d0eaa3f3af7de45d704787866240a7c6d5a51", size = 6566, upload-time = "2026-11-03T16:26:33.692Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/79/7b/2c79738432f5c924bef5071f933bcc9efd0473bac3b4aa584a6f7c1c8df8/mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", size = 4963, upload-time = "2025-04-22T14:54:22.983Z" }, + { url = "https://files.pythonhosted.org/packages/b5/99/7b1adac7e97ce7bbda34792dc6e9b2f5cc5cffd1875883f78a818b2a2687/mypy_extensions-1.2.0-py3-none-any.whl", hash = "sha256:993e7a20aa5671eb41a7132cf555af30062da99729601601b9a8382b11cae768", size = 5114, upload-time = "2026-11-03T16:26:32.731Z" }, ] [[package]] From 67d40261b8d44cdbd59fd53beabd81be07134523 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:48:52 -0800 Subject: [PATCH 08/17] chore(deps): bump the dependencies group with 4 updates (#563) Bumps the dependencies group with 4 updates: [step-security/harden-runner](https://github.com/step-security/harden-runner), [github/codeql-action/init](https://github.com/github/codeql-action), [github/codeql-action/analyze](https://github.com/github/codeql-action) and [github/codeql-action/upload-sarif](https://github.com/github/codeql-action). Updates `step-security/harden-runner` from 2.22.3 to 2.22.4 - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](https://github.com/step-security/harden-runner/compare/46b06cea07f9e64621fdf066ba77ac6915163d43...1d88384fd173af6ecb012dfd0264a306b711241a) Updates `github/codeql-action/init` from 4.39.1 to 4.39.3 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...33d7b85da1a04171e211befe2c739303b9a4c066) Updates `github/codeql-action/analyze` from 4.39.1 to 4.39.3 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...33d7b85da1a04171e211befe2c739303b9a4c066) Updates `github/codeql-action/upload-sarif` from 4.39.1 to 4.39.3 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/9b3254085494b55a0f7c4c2b3d2d52cc712ce370...33d7b85da1a04171e211befe2c739303b9a4c066) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.22.4 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: github/codeql-action/init dependency-version: 4.39.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: github/codeql-action/analyze dependency-version: 4.39.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: github/codeql-action/upload-sarif dependency-version: 4.39.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/contributors_report.yaml | 2 +- .github/workflows/copilot-setup-steps.yml | 2 +- .github/workflows/dependency-review.yml | 2 +- .github/workflows/docker-ci.yml | 2 +- .github/workflows/mark-ready-when-ready.yml | 2 +- .github/workflows/python-ci.yml | 2 +- .github/workflows/scorecard.yml | 4 ++-- .github/workflows/stale.yml | 2 +- .github/workflows/super-linter.yaml | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d201e8b..61fc221 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -41,7 +41,7 @@ jobs: steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit @@ -52,7 +52,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 + uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -67,6 +67,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1 + uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/contributors_report.yaml b/.github/workflows/contributors_report.yaml index fe21618..0e50b59 100644 --- a/.github/workflows/contributors_report.yaml +++ b/.github/workflows/contributors_report.yaml @@ -17,7 +17,7 @@ jobs: steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index d2329ad..e1eeffd 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -26,7 +26,7 @@ jobs: # If you do not check out your code, Copilot will do this for you. steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index b1c220f..0668532 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 124083b..9fc92cc 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/mark-ready-when-ready.yml b/.github/workflows/mark-ready-when-ready.yml index e3702ba..24d8acd 100644 --- a/.github/workflows/mark-ready-when-ready.yml +++ b/.github/workflows/mark-ready-when-ready.yml @@ -25,7 +25,7 @@ jobs: github.event.pull_request.draft == true steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 15e15fc..9aacaec 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -25,7 +25,7 @@ jobs: python-version: [3.11, 3.12, 3.13, 3.14] steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 453280f..23dc76d 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit @@ -49,6 +49,6 @@ jobs: path: results.sarif retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 + uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 with: sarif_file: results.sarif diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 1105eef..4b4701a 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -14,7 +14,7 @@ jobs: pull-requests: read steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit diff --git a/.github/workflows/super-linter.yaml b/.github/workflows/super-linter.yaml index 283fe8f..4982b2f 100644 --- a/.github/workflows/super-linter.yaml +++ b/.github/workflows/super-linter.yaml @@ -22,7 +22,7 @@ jobs: statuses: write steps: - name: Harden the runner (Audit all outbound calls) - uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3 + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit From 872f8a4e74b3f63b4c174a680ec6601e2d390b59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:29:32 -0600 Subject: [PATCH 09/17] chore(deps): bump pylint from 4.1.3 to 4.1.4 in the dependencies group (#566) * chore(deps): bump pylint from 4.1.3 to 4.1.4 in the dependencies group Bumps the dependencies group with 1 update: [pylint](https://github.com/pylint-dev/pylint). Updates `pylint` from 4.1.3 to 4.1.4 - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v4.1.3...v4.1.4) --- updated-dependencies: - dependency-name: pylint dependency-version: 4.1.4 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] * fix(docker): bump libc6-dev pin to 2.41-12+deb13u5 ## What/Why Debian trixie replaced libc6-dev 2.41-12+deb13u4 with +deb13u5, so the pinned apt install fails and the Docker build breaks on every PR. ## Proof it works Checked the trixie, trixie-updates, and trixie-security Packages indexes. libc6-dev is at 2.41-12+deb13u5. The gcc, libffi-dev, and git pins still match. `make test` and `make lint` pass. The Docker build was not run locally; CI verifies it. ## Risk Low. A glibc point release for the build stage only. The runtime image uses the base image's libc. ## AI role Claude Opus 5.5 diagnosed the failed run, looked up the package versions, and wrote the change. jmeridth reviewed it. ## Review focus Whether to keep exact apt pins, given this will recur on the next Debian point release. Signed-off-by: jmeridth --------- Signed-off-by: dependabot[bot] Signed-off-by: jmeridth Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jmeridth --- Dockerfile | 2 +- pyproject.toml | 2 +- uv.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3154183..f91fc8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ COPY pyproject.toml uv.lock *.py /action/workspace/ COPY --from=ghcr.io/astral-sh/uv:0.10.9@sha256:10902f58a1606787602f303954cea099626a4adb02acbac4c69920fe9d278f82 /uv /uvx /bin/ RUN apt-get -y update \ - && apt-get -y install --no-install-recommends gcc=4:14.2.0-1 libc6-dev=2.41-12+deb13u4 libffi-dev=3.4.8-2 \ + && apt-get -y install --no-install-recommends gcc=4:14.2.0-1 libc6-dev=2.41-12+deb13u5 libffi-dev=3.4.8-2 \ && uv sync --frozen --no-dev --no-editable \ && rm -rf /var/lib/apt/lists/* diff --git a/pyproject.toml b/pyproject.toml index f54d8a7..133fac9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ dev = [ "flake8==7.5.0", "mypy==2.4.1", "mypy-extensions==1.2.0", - "pylint==4.1.3", + "pylint==4.1.4", "pytest==9.2.0", "pytest-cov==7.1.0", "types-requests==2.33.0.20261030", diff --git a/uv.lock b/uv.lock index 604e5f5..4ee6210 100644 --- a/uv.lock +++ b/uv.lock @@ -325,7 +325,7 @@ dev = [ { name = "flake8", specifier = "==7.5.0" }, { name = "mypy", specifier = "==2.4.1" }, { name = "mypy-extensions", specifier = "==1.2.0" }, - { name = "pylint", specifier = "==4.1.3" }, + { name = "pylint", specifier = "==4.1.4" }, { name = "pytest", specifier = "==9.2.0" }, { name = "pytest-cov", specifier = "==7.1.0" }, { name = "types-requests", specifier = "==2.33.0.20261030" }, @@ -839,7 +839,7 @@ crypto = [ [[package]] name = "pylint" -version = "4.1.3" +version = "4.1.4" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "astroid" }, @@ -850,9 +850,9 @@ dependencies = [ { name = "platformdirs" }, { name = "tomlkit" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/38/c9/0bde4152a05a7686b431ce216fe3f3698b0c0d94c20bfa256dd935b608f6/pylint-4.1.3.tar.gz", hash = "sha256:9928603068edfa0d1a3c167f174b099d4b97c3db75d32d0fcdd029770b4713a9", size = 1756180, upload-time = "2026-10-11T07:49:10.69Z" } +sdist = { url = "https://files.pythonhosted.org/packages/8f/d7/bfea980ba1ea5666c7f774627f3a7159b98a21426a081dd2f05db8eb93b3/pylint-4.1.4.tar.gz", hash = "sha256:4c9176dc6c9f1b98b742195f01899b290369d5a27b4b41d1014c17f2f96b26f1", size = 1768302, upload-time = "2026-11-14T21:41:51.625Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/3f/ba/62b18e2e157d05f976bd490b349b55d8850c2a454a5c313c91af9d2e0baf/pylint-4.1.3-py3-none-any.whl", hash = "sha256:a85357cae24f33ad8d86c8f3daaa92c600ae4012b54a57299cee76000e9364cf", size = 588959, upload-time = "2026-10-11T07:49:08.272Z" }, + { url = "https://files.pythonhosted.org/packages/b4/89/5235509abac00f5c470d5d8edae908bcec79d1c09803485ce57c25ccbed1/pylint-4.1.4-py3-none-any.whl", hash = "sha256:b39fcc762ec4a7fe385d01b8e170fd996847297cdc0e3850bdda1435c74cfd95", size = 591735, upload-time = "2026-11-14T21:41:49.56Z" }, ] [[package]] From 2fc56275695cd99d6cfee9e1d26f8b90877be38d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:32:55 +0000 Subject: [PATCH 10/17] chore(deps): bump python (#565) Bumps the dependencies group with 1 update in the / directory: python. Updates `python` from 3.15.0-slim to 3.15.2-slim --- updated-dependencies: - dependency-name: python dependency-version: 3.15.2-slim dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f91fc8a..fbe9175 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ #checkov:skip=CKV_DOCKER_2 #checkov:skip=CKV_DOCKER_3 #trivy:ignore:AVD-DS-0002 -FROM python:3.15.0-slim@sha256:f5b92f2a669a4c347044f29367f31983280b648250ca94dea66f98c53bc87e58 AS builder +FROM python:3.15.2-slim@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928 AS builder WORKDIR /action/workspace COPY pyproject.toml uv.lock *.py /action/workspace/ @@ -12,7 +12,7 @@ RUN apt-get -y update \ && uv sync --frozen --no-dev --no-editable \ && rm -rf /var/lib/apt/lists/* -FROM python:3.15.0-slim@sha256:f5b92f2a669a4c347044f29367f31983280b648250ca94dea66f98c53bc87e58 +FROM python:3.15.2-slim@sha256:65a65fc7b30b06cb6df4930fd4650697cb23f4c2698ab81fc87e4b031bc36928 LABEL com.github.actions.name="contributors" \ com.github.actions.description="GitHub Action that given an organization or repository, produces information about the contributors over the specified time period." \ com.github.actions.icon="users" \ From 8d468b626318d8d7523ebbe9fb3aadbdf2921c00 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:32:03 +0100 Subject: [PATCH 11/17] docs: document the behavior in case env var are defined with invalid values --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53b897d..a7afb03 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,12 @@ This action can be configured to authenticate with GitHub App Installation or Pe | `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" | | `SHOW_AVATAR` | False | False | If you want to show profile images in the markdown output. ie. SHOW_AVATAR = "True" or SHOW_AVATAR = "False" | | `SORT_COLUMN` | False | contribution_count | The column you want to sort the table with. Possible values: `username` (column of strings), `contribution_count` (column of integers) or `new_contributor` (column of booleans, whether the given username is a new contributor) | -| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: "asc" for ascending order or "desc" for descending order. | +| `SORT_ORDER` | False | desc | The order the SORT_COLUMN column will be sorted. Possibles values: `asc` for ascending order or `desc` for descending order. | | `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" | -**Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date. +**Notes**: +- If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date. +- When defining variables with invalid values, it will result in an error. With the exception of `sort_column` and `sort_order` for which the action will run using the default values. **Performance Note:** Using start and end dates will reduce speed of the action by approximately 63X. ie without dates if the action takes 1.7 seconds, it will take 1 minute and 47 seconds. From 78c159f3ae8a1ef6a40bf3c2ec621dddba643115 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Thu, 26 Nov 2026 05:07:29 +0100 Subject: [PATCH 12/17] refactor: make sorting functions a separate module with test cases --- json_writer.py | 9 ++-- markdown.py | 11 ++--- sort.py | 28 +++++++++++++ test_sort.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 14 deletions(-) create mode 100644 sort.py create mode 100644 test_sort.py diff --git a/json_writer.py b/json_writer.py index a696577..4596952 100644 --- a/json_writer.py +++ b/json_writer.py @@ -1,7 +1,7 @@ """This module contains a function that writes data to a JSON file.""" import json -import re +from sort import sort_contributions def write_to_json( @@ -71,11 +71,8 @@ def write_to_json( # ] # } - # Sort the list by chosen column and order, case insensitive order, natural sort (adapted from Mark Byers' snippet published under CC-BY-SA license at https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort/4836734#4836734) - is_reverse = sort_order == "desc" #default to desc - convert = lambda text: int(text) if text.isdigit() else text.casefold() - alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', str(key))] - contributors = sorted(contributors, key=lambda x: alphanum_key(getattr(x, sort_column)), reverse=is_reverse) + # case insentive and natural sorting of the list by chosen column and order + contributors = sort_contributions(contributors, sort_column, sort_order) data = { "start_date": start_date, diff --git a/markdown.py b/markdown.py index 590228c..d43bddc 100644 --- a/markdown.py +++ b/markdown.py @@ -2,7 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" import os -import re +from sort import sort_contributions def _is_truthy(value) -> bool: @@ -272,13 +272,8 @@ def get_contributor_table( table = headers total_contributions = 0 - # Sort the list by chosen column and order, case insensitive order, natural sort (adapted from Mark Byers' snippet published under CC-BY-SA license at https://stackoverflow.com/questions/4836710/is-there-a-built-in-function-for-string-natural-sort/4836734#4836734) - is_reverse = sort_order == "desc" #default to desc - convert = lambda text: int(text) if text.isdigit() else text.casefold() - alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', str(key))] - sorted_collaborators = sorted( - collaborators, key=lambda x: alphanum_key(getattr(x, sort_column)), reverse=is_reverse - ) + # case insentive and natural sorting of the list by chosen column and order + sorted_collaborators = sort_contributions(collaborators, sort_column, sort_order) for collaborator in sorted_collaborators: total_contributions += collaborator.contribution_count diff --git a/sort.py b/sort.py new file mode 100644 index 0000000..19eb4e0 --- /dev/null +++ b/sort.py @@ -0,0 +1,28 @@ +"""This is the module that contains functions related to tables sorting.""" + +import re + + +def sort_contributions(collaborators, sort_column, sort_order): + """ + This function returns a case-insensitive sorted list by chosen column and order, using natural sorting. + + Args: + collaborators (list): A list of dictionaries, where each dictionary represents a collaborator. + Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. + sort_column (str): The start date of the date range for the contributor list. + sort_order (str): The end date of the date range for the contributor list. + + Returns: + sorted_collaborators (list): A list of dictionaries of the same format as the one received as argument. + + """ + is_reverse = False if sort_order == "asc" else True #defaults to descending order if invalid + + def assign_type(split_text): + return int(split_text) if split_text.isdigit() else split_text.casefold() + + def split_and_type_alphanumerical_components(input_entry): + return [assign_type(c) for c in re.split('([0-9]+)', str(input_entry))] + + return sorted(collaborators, key=lambda x: split_and_type_alphanumerical_components(getattr(x, sort_column)), reverse=is_reverse) diff --git a/test_sort.py b/test_sort.py new file mode 100644 index 0000000..1ccaf60 --- /dev/null +++ b/test_sort.py @@ -0,0 +1,111 @@ +"""Test cases for the sort module.""" + +import unittest +import contributor_stats +from sort import sort_contributions + + +class TestSortedCollaborators(unittest.TestCase): + # Sample list of ContributorStats objects + """ ContributorStats object: + username: str, + avatar_url: str, + contribution_count: int, + commit_url: str, + sponsor_info: str, + new_contributor: bool, + """ + + person1 = contributor_stats.ContributorStats( + "Bob", + "url", + 3, + "commit url", + "sponsor_url_1", + True + ) + person2 = contributor_stats.ContributorStats( + "alice", + "url2", + 5, + "commit url2", + "sponsor_url_2", + False + ) + person3 = contributor_stats.ContributorStats( + "user10", + "url2", + 2, + "commit url2", + "sponsor_url_2", + False + ) + person4 = contributor_stats.ContributorStats( + "user2", + "url2", + 1, + "commit url2", + "sponsor_url_2", + False + ) + + collaborators = [ + person1, + person2, + person3, + person4, + ] + + def test_sort_does_not_modify_original_list(self): + original_order = [getattr(c, "username") for c in self.collaborators] + sort_contributions(self.collaborators, "username", "asc") + self.assertEqual( + [getattr(c, "username") for c in self.collaborators], + original_order, + ) + + def test_contribution_count_ascending(self): + sorted_collaborators = sort_contributions(self.collaborators, "contribution_count", "asc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["user2", "user10", "Bob", "alice"], + ) + + def test_contribution_count_descending(self): + sorted_collaborators = sort_contributions(self.collaborators, "contribution_count", "desc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["alice", "Bob", "user10", "user2"], + ) + + def test_username_ascending_is_case_insensitive_and_natural(self): + sorted_collaborators = sort_contributions(self.collaborators, "username", "asc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["alice", "Bob", "user2", "user10"], + ) + + def test_username_descending_is_case_insensitive_and_natural(self): + sorted_collaborators = sort_contributions(self.collaborators, "username", "desc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["user10", "user2", "Bob", "alice"], + ) + + def test_new_contributor_ascending(self): + sorted_collaborators = sort_contributions(self.collaborators, "new_contributor", "asc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["alice", "user10", "user2", "Bob"], + ) + + def test_new_contributor_descending(self): + sorted_collaborators = sort_contributions(self.collaborators, "new_contributor", "desc") + self.assertEqual( + [getattr(c, "username") for c in sorted_collaborators], + ["Bob", "alice", "user10", "user2"], + ) + + +if __name__ == "__main__": + unittest.main() From 3964c170981f01b066d96ba1938ce86dd61b57c0 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Thu, 26 Nov 2026 05:09:44 +0100 Subject: [PATCH 13/17] test: allow adding more tests to the class --- test_env.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_env.py b/test_env.py index 2ce701b..0e7e1e1 100644 --- a/test_env.py +++ b/test_env.py @@ -1,3 +1,4 @@ +# pylint: disable=too-many-public-methods """This is the test module for the env module.""" import os From eeb14104518952f04654ab97be2d3a3958f21759 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Thu, 26 Nov 2026 05:25:21 +0100 Subject: [PATCH 14/17] docs: fix ContributorStats object description in comments --- markdown.py | 16 ++++++++-------- sort.py | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/markdown.py b/markdown.py index d43bddc..5100264 100644 --- a/markdown.py +++ b/markdown.py @@ -29,13 +29,13 @@ def write_to_markdown( """ This function writes a list of collaborators to a markdown file in table format and optionally to GitHub Actions Job Summary if running in a GitHub Actions environment. - Each collaborator is represented as a dictionary with keys 'username', + Each collaborator is represented as a object with attributes 'username', 'contribution_count', 'new_contributor', and 'commits'. Args: - collaborators (list): A tuple of objects, where each object - represents a collaborator. Each dictionary should - have the keys 'username', 'contribution_count', + collaborators (list): A list of objects, where each object + represents a collaborator. Each object should + have the attributes 'username', 'contribution_count', and 'commits'. filename (str): The path of the markdown file to which the table will be written. @@ -184,8 +184,8 @@ def get_summary_table(collaborators, start_date, end_date, total_contributions): This function returns a string containing a markdown table of the summary statistics. Args: - collaborators (list): A list of dictionaries, where each dictionary represents a collaborator. - Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. + collaborators (list): A list of objects, where each object represents a collaborator. + Each object should have the attributes 'username', 'contribution_count', and 'commits'. start_date (str): The start date of the date range for the contributor list. end_date (str): The end date of the date range for the contributor list. total_contributions (int): The total number of contributions made by all of the contributors. @@ -230,8 +230,8 @@ def get_contributor_table( This function returns a string containing a markdown table of the contributors and the total contribution count. Args: - collaborators (list): A list of dictionaries, where each dictionary represents a collaborator. - Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. + collaborators (list): A list of objects, where each object represents a collaborator. + Each object should have the attributes 'username', 'contribution_count', and 'commits'. start_date (str): The start date of the date range for the contributor list. end_date (str): The end date of the date range for the contributor list. organization (str): The organization for which the contributors are being listed. diff --git a/sort.py b/sort.py index 19eb4e0..fdec443 100644 --- a/sort.py +++ b/sort.py @@ -8,13 +8,13 @@ def sort_contributions(collaborators, sort_column, sort_order): This function returns a case-insensitive sorted list by chosen column and order, using natural sorting. Args: - collaborators (list): A list of dictionaries, where each dictionary represents a collaborator. - Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. + collaborators (list): A list of objects, where each object represents a collaborator. + Each object should have the attributes 'username', 'contribution_count', and 'commits'. sort_column (str): The start date of the date range for the contributor list. sort_order (str): The end date of the date range for the contributor list. Returns: - sorted_collaborators (list): A list of dictionaries of the same format as the one received as argument. + sorted_collaborators (list): A list of objects of the same format as the one received as argument. """ is_reverse = False if sort_order == "asc" else True #defaults to descending order if invalid From 437108c398ad33082e7fd0a090ae81fc8f31032d Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Thu, 26 Nov 2026 05:47:27 +0100 Subject: [PATCH 15/17] style: apply linter suggestions --- json_writer.py | 1 + markdown.py | 1 + sort.py | 10 +++++--- test_sort.py | 66 +++++++++++++++++++++++++------------------------- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/json_writer.py b/json_writer.py index 4596952..be25b21 100644 --- a/json_writer.py +++ b/json_writer.py @@ -1,6 +1,7 @@ """This module contains a function that writes data to a JSON file.""" import json + from sort import sort_contributions diff --git a/markdown.py b/markdown.py index 5100264..84950d4 100644 --- a/markdown.py +++ b/markdown.py @@ -2,6 +2,7 @@ """This module contains the functions needed to write the output to markdown files.""" import os + from sort import sort_contributions diff --git a/sort.py b/sort.py index fdec443..e554733 100644 --- a/sort.py +++ b/sort.py @@ -17,12 +17,16 @@ def sort_contributions(collaborators, sort_column, sort_order): sorted_collaborators (list): A list of objects of the same format as the one received as argument. """ - is_reverse = False if sort_order == "asc" else True #defaults to descending order if invalid + is_reverse = not sort_order == "asc" # defaults to descending order if invalid def assign_type(split_text): return int(split_text) if split_text.isdigit() else split_text.casefold() def split_and_type_alphanumerical_components(input_entry): - return [assign_type(c) for c in re.split('([0-9]+)', str(input_entry))] + return [assign_type(c) for c in re.split("([0-9]+)", str(input_entry))] - return sorted(collaborators, key=lambda x: split_and_type_alphanumerical_components(getattr(x, sort_column)), reverse=is_reverse) + return sorted( + collaborators, + key=lambda x: split_and_type_alphanumerical_components(getattr(x, sort_column)), + reverse=is_reverse, + ) diff --git a/test_sort.py b/test_sort.py index 1ccaf60..b461930 100644 --- a/test_sort.py +++ b/test_sort.py @@ -1,13 +1,16 @@ """Test cases for the sort module.""" import unittest -import contributor_stats + from sort import sort_contributions +import contributor_stats + +# Case insensitive sort with natural sorting support class TestSortedCollaborators(unittest.TestCase): # Sample list of ContributorStats objects - """ ContributorStats object: + """ContributorStats object: username: str, avatar_url: str, contribution_count: int, @@ -17,36 +20,16 @@ class TestSortedCollaborators(unittest.TestCase): """ person1 = contributor_stats.ContributorStats( - "Bob", - "url", - 3, - "commit url", - "sponsor_url_1", - True + "Bob", "url", 3, "commit url", "sponsor_url_1", True ) person2 = contributor_stats.ContributorStats( - "alice", - "url2", - 5, - "commit url2", - "sponsor_url_2", - False + "alice", "url2", 5, "commit url2", "sponsor_url_2", False ) person3 = contributor_stats.ContributorStats( - "user10", - "url2", - 2, - "commit url2", - "sponsor_url_2", - False + "user10", "url2", 2, "commit url2", "sponsor_url_2", False ) person4 = contributor_stats.ContributorStats( - "user2", - "url2", - 1, - "commit url2", - "sponsor_url_2", - False + "user2", "url2", 1, "commit url2", "sponsor_url_2", False ) collaborators = [ @@ -57,6 +40,7 @@ class TestSortedCollaborators(unittest.TestCase): ] def test_sort_does_not_modify_original_list(self): + """Verify sorting leaves the original collaborators list unchanged.""" original_order = [getattr(c, "username") for c in self.collaborators] sort_contributions(self.collaborators, "username", "asc") self.assertEqual( @@ -65,42 +49,58 @@ def test_sort_does_not_modify_original_list(self): ) def test_contribution_count_ascending(self): - sorted_collaborators = sort_contributions(self.collaborators, "contribution_count", "asc") + """Verify collaborators are sorted by contribution count in ascending order.""" + sorted_collaborators = sort_contributions( + self.collaborators, "contribution_count", "asc" + ) self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["user2", "user10", "Bob", "alice"], ) def test_contribution_count_descending(self): - sorted_collaborators = sort_contributions(self.collaborators, "contribution_count", "desc") + """Verify collaborators are sorted by contribution count in descending order.""" + sorted_collaborators = sort_contributions( + self.collaborators, "contribution_count", "desc" + ) self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["alice", "Bob", "user10", "user2"], ) - def test_username_ascending_is_case_insensitive_and_natural(self): + def test_username_ascending(self): + """Verify collaborators are sorted by username in ascending order.""" sorted_collaborators = sort_contributions(self.collaborators, "username", "asc") self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["alice", "Bob", "user2", "user10"], ) - def test_username_descending_is_case_insensitive_and_natural(self): - sorted_collaborators = sort_contributions(self.collaborators, "username", "desc") + def test_username_descending(self): + """Verify collaborators are sorted by username in descending order.""" + sorted_collaborators = sort_contributions( + self.collaborators, "username", "desc" + ) self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["user10", "user2", "Bob", "alice"], ) def test_new_contributor_ascending(self): - sorted_collaborators = sort_contributions(self.collaborators, "new_contributor", "asc") + """Verify collaborators are sorted by new-contributor status in ascending order.""" + sorted_collaborators = sort_contributions( + self.collaborators, "new_contributor", "asc" + ) self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["alice", "user10", "user2", "Bob"], ) def test_new_contributor_descending(self): - sorted_collaborators = sort_contributions(self.collaborators, "new_contributor", "desc") + """Verify collaborators are sorted by new-contributor status in descending order.""" + sorted_collaborators = sort_contributions( + self.collaborators, "new_contributor", "desc" + ) self.assertEqual( [getattr(c, "username") for c in sorted_collaborators], ["Bob", "alice", "user10", "user2"], From 757de65f7f04cc35c2fe8c6b72838e315b6d42d2 Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:47:06 +0100 Subject: [PATCH 16/17] docs: fix reviewed doc issues --- README.md | 3 ++- json_writer.py | 2 +- markdown.py | 2 +- sort.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7afb03..b796c06 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,9 @@ This action can be configured to authenticate with GitHub App Installation or Pe | `SKIP_SUMMARY` | False | False | If you want to hide the summary with total contributions statistics above the contributors table. ie. SKIP_SUMMARY = "True" or SKIP_SUMMARY = "False" | **Notes**: + - If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date. -- When defining variables with invalid values, it will result in an error. With the exception of `sort_column` and `sort_order` for which the action will run using the default values. +- If `sort_column` and `sort_order` are defined with invalid values, the action will run using the default values as fallback. **Performance Note:** Using start and end dates will reduce speed of the action by approximately 63X. ie without dates if the action takes 1.7 seconds, it will take 1 minute and 47 seconds. diff --git a/json_writer.py b/json_writer.py index be25b21..63b4246 100644 --- a/json_writer.py +++ b/json_writer.py @@ -72,7 +72,7 @@ def write_to_json( # ] # } - # case insentive and natural sorting of the list by chosen column and order + # Case insensitive and natural sorting of the list by chosen column and order contributors = sort_contributions(contributors, sort_column, sort_order) data = { diff --git a/markdown.py b/markdown.py index 84950d4..353ea78 100644 --- a/markdown.py +++ b/markdown.py @@ -273,7 +273,7 @@ def get_contributor_table( table = headers total_contributions = 0 - # case insentive and natural sorting of the list by chosen column and order + # Case insensitive and natural sorting of the list by chosen column and order sorted_collaborators = sort_contributions(collaborators, sort_column, sort_order) for collaborator in sorted_collaborators: diff --git a/sort.py b/sort.py index e554733..784732d 100644 --- a/sort.py +++ b/sort.py @@ -10,8 +10,8 @@ def sort_contributions(collaborators, sort_column, sort_order): Args: collaborators (list): A list of objects, where each object represents a collaborator. Each object should have the attributes 'username', 'contribution_count', and 'commits'. - sort_column (str): The start date of the date range for the contributor list. - sort_order (str): The end date of the date range for the contributor list. + sort_column (str): The name of the column to sort ('username', 'contribution_count' or 'new_contributor'). + sort_order (str): The order to sort the column with ('asc' or 'desc'). Returns: sorted_collaborators (list): A list of objects of the same format as the one received as argument. From d09a86fb42b109cfb99c41e232b267a78d14fc6a Mon Sep 17 00:00:00 2001 From: oleole39 <59071673+oleole39@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:28:31 +0100 Subject: [PATCH 17/17] style: pass ruff check --- contributors.py | 6 ++-- env.py | 9 +++-- sort.py | 2 +- test_contributors.py | 10 +++--- test_sort.py | 81 +++++++++++++++++++++++--------------------- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/contributors.py b/contributors.py index b1493f1..88bff22 100644 --- a/contributors.py +++ b/contributors.py @@ -1,7 +1,7 @@ # pylint: disable=broad-exception-caught """This file contains the main() and other functions needed to get contributor information from the organization or repository""" -from datetime import datetime, timezone +from datetime import UTC, datetime import auth import contributor_stats @@ -173,8 +173,8 @@ def get_contributors(repo: object, start_date: str, end_date: str, ghe: str): avatars: dict[str, str] = {} counts: dict[str, int] = {} for commit in repo.get_commits( - since=datetime.fromisoformat(start_date).replace(tzinfo=timezone.utc), - until=datetime.fromisoformat(end_date).replace(tzinfo=timezone.utc), + since=datetime.fromisoformat(start_date).replace(tzinfo=UTC), + until=datetime.fromisoformat(end_date).replace(tzinfo=UTC), ): login = getattr(commit.author, "login", None) if not login or "[bot]" in login: diff --git a/env.py b/env.py index e165f16..787ae10 100644 --- a/env.py +++ b/env.py @@ -7,7 +7,6 @@ import os import re from os.path import dirname, join -from typing import List from dotenv import load_dotenv @@ -65,7 +64,7 @@ def validate_date_format(env_var_name: str) -> str: pattern = "%Y-%m-%d" try: datetime.datetime.strptime(date_to_validate, pattern).replace( - tzinfo=datetime.timezone.utc + tzinfo=datetime.UTC ) except ValueError as exc: raise ValueError( @@ -93,12 +92,12 @@ def validate_date_range(start_date: str, end_date: str) -> None: try: start = ( datetime.datetime.strptime(start_date, pattern) - .replace(tzinfo=datetime.timezone.utc) + .replace(tzinfo=datetime.UTC) .date() ) end = ( datetime.datetime.strptime(end_date, pattern) - .replace(tzinfo=datetime.timezone.utc) + .replace(tzinfo=datetime.UTC) .date() ) except ValueError as exc: @@ -134,7 +133,7 @@ def validate_output_filename(output_filename: str) -> str: def validate_allowed_values( - env_var_name: str, allowed_values: List[str], default: str + env_var_name: str, allowed_values: list[str], default: str ) -> str: """Check that env variable is contained in a list of defined values or set a default one. Returns a lowercase value. diff --git a/sort.py b/sort.py index 784732d..8656224 100644 --- a/sort.py +++ b/sort.py @@ -17,7 +17,7 @@ def sort_contributions(collaborators, sort_column, sort_order): sorted_collaborators (list): A list of objects of the same format as the one received as argument. """ - is_reverse = not sort_order == "asc" # defaults to descending order if invalid + is_reverse = sort_order != "asc" # defaults to descending order if invalid def assign_type(split_text): return int(split_text) if split_text.isdigit() else split_text.casefold() diff --git a/test_contributors.py b/test_contributors.py index f1d8e11..306bce5 100644 --- a/test_contributors.py +++ b/test_contributors.py @@ -2,7 +2,7 @@ import runpy import unittest -from datetime import datetime, timezone +from datetime import UTC, datetime from unittest.mock import MagicMock, patch import contributors as contributors_module @@ -34,8 +34,8 @@ def test_get_contributors(self, mock_contributor_stats): self.assertEqual(len(result), 1) mock_repo.get_commits.assert_called_once_with( - since=datetime(2022, 1, 1, tzinfo=timezone.utc), - until=datetime(2022, 12, 31, tzinfo=timezone.utc), + since=datetime(2022, 1, 1, tzinfo=UTC), + until=datetime(2022, 12, 31, tzinfo=UTC), ) mock_contributor_stats.assert_called_once_with( "user", @@ -145,8 +145,8 @@ def test_get_contributors_with_single_commit(self, mock_contributor_stats): self.assertEqual(len(result), 1) mock_repo.get_commits.assert_called_once_with( - since=datetime(2022, 1, 1, tzinfo=timezone.utc), - until=datetime(2022, 12, 31, tzinfo=timezone.utc), + since=datetime(2022, 1, 1, tzinfo=UTC), + until=datetime(2022, 12, 31, tzinfo=UTC), ) mock_contributor_stats.assert_called_once_with( "user", diff --git a/test_sort.py b/test_sort.py index b461930..cae0a81 100644 --- a/test_sort.py +++ b/test_sort.py @@ -2,49 +2,54 @@ import unittest -from sort import sort_contributions - import contributor_stats +from sort import sort_contributions -# Case insensitive sort with natural sorting support class TestSortedCollaborators(unittest.TestCase): - # Sample list of ContributorStats objects - """ContributorStats object: - username: str, - avatar_url: str, - contribution_count: int, - commit_url: str, - sponsor_info: str, - new_contributor: bool, """ + Test case for the sort module (case insensitive sort with natural sorting support) + """ + + def __init__(self, methodName="runTest"): + # Sample list of ContributorStats objects + """ContributorStats object: + username: str, + avatar_url: str, + contribution_count: int, + commit_url: str, + sponsor_info: str, + new_contributor: bool, + """ + + super().__init__(methodName) + + person1 = contributor_stats.ContributorStats( + "Bob", "url", 3, "commit url", "sponsor_url_1", True + ) + person2 = contributor_stats.ContributorStats( + "alice", "url2", 5, "commit url2", "sponsor_url_2", False + ) + person3 = contributor_stats.ContributorStats( + "user10", "url2", 2, "commit url2", "sponsor_url_2", False + ) + person4 = contributor_stats.ContributorStats( + "user2", "url2", 1, "commit url2", "sponsor_url_2", False + ) - person1 = contributor_stats.ContributorStats( - "Bob", "url", 3, "commit url", "sponsor_url_1", True - ) - person2 = contributor_stats.ContributorStats( - "alice", "url2", 5, "commit url2", "sponsor_url_2", False - ) - person3 = contributor_stats.ContributorStats( - "user10", "url2", 2, "commit url2", "sponsor_url_2", False - ) - person4 = contributor_stats.ContributorStats( - "user2", "url2", 1, "commit url2", "sponsor_url_2", False - ) - - collaborators = [ - person1, - person2, - person3, - person4, - ] + self.collaborators = [ + person1, + person2, + person3, + person4, + ] def test_sort_does_not_modify_original_list(self): """Verify sorting leaves the original collaborators list unchanged.""" - original_order = [getattr(c, "username") for c in self.collaborators] + original_order = [c.username for c in self.collaborators] sort_contributions(self.collaborators, "username", "asc") self.assertEqual( - [getattr(c, "username") for c in self.collaborators], + [c.username for c in self.collaborators], original_order, ) @@ -54,7 +59,7 @@ def test_contribution_count_ascending(self): self.collaborators, "contribution_count", "asc" ) self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["user2", "user10", "Bob", "alice"], ) @@ -64,7 +69,7 @@ def test_contribution_count_descending(self): self.collaborators, "contribution_count", "desc" ) self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["alice", "Bob", "user10", "user2"], ) @@ -72,7 +77,7 @@ def test_username_ascending(self): """Verify collaborators are sorted by username in ascending order.""" sorted_collaborators = sort_contributions(self.collaborators, "username", "asc") self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["alice", "Bob", "user2", "user10"], ) @@ -82,7 +87,7 @@ def test_username_descending(self): self.collaborators, "username", "desc" ) self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["user10", "user2", "Bob", "alice"], ) @@ -92,7 +97,7 @@ def test_new_contributor_ascending(self): self.collaborators, "new_contributor", "asc" ) self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["alice", "user10", "user2", "Bob"], ) @@ -102,7 +107,7 @@ def test_new_contributor_descending(self): self.collaborators, "new_contributor", "desc" ) self.assertEqual( - [getattr(c, "username") for c in sorted_collaborators], + [c.username for c in sorted_collaborators], ["Bob", "alice", "user10", "user2"], )