diff --git a/markdown.py b/markdown.py index 5d5e419..0900d03 100644 --- a/markdown.py +++ b/markdown.py @@ -159,7 +159,8 @@ def get_contributor_table( columns = ["Username", "All Time Contribution Count"] if start_date and end_date: columns += ["New Contributor"] - if sponsor_info == "true": + # Add Sponsor URL column if sponsor_info is True + if sponsor_info: columns += ["Sponsor URL"] if start_date and end_date: columns += [f"Commits between {start_date} and {end_date}"] @@ -191,9 +192,9 @@ def get_contributor_table( commit_urls += f"{url}, " new_contributor = collaborator.new_contributor - row = ( - f"| {'' if not link_to_profile else '@'}{username} | {contribution_count} |" - ) + # Determine prefix for username based on boolean link_to_profile + prefix = "@" if link_to_profile else "" + row = f"| {prefix}{username} | {contribution_count} |" if "New Contributor" in columns: row += f" {new_contributor} |" if "Sponsor URL" in columns: diff --git a/test_markdown.py b/test_markdown.py index 54a7337..0c7504b 100644 --- a/test_markdown.py +++ b/test_markdown.py @@ -48,7 +48,7 @@ def test_write_to_markdown(self, mock_file): "2023-01-02", None, "org/repo", - "false", + False, True, ghe, ) @@ -104,7 +104,7 @@ def test_write_to_markdown_with_sponsors(self, mock_file): "2023-01-02", None, "org/repo", - "true", + True, True, ghe, ) @@ -160,7 +160,7 @@ def test_write_to_markdown_without_link_to_profile(self, mock_file): "2023-01-02", None, "org/repo", - "false", + False, False, ghe, ) @@ -180,6 +180,55 @@ def test_write_to_markdown_without_link_to_profile(self, mock_file): "| user2 | 200 | True | commit url2 |\n" ) + @patch("builtins.open", new_callable=mock_open) + def test_write_to_markdown_with_string_false_link_to_profile(self, mock_file): + """ + Test the write_to_markdown function with link_to_profile as string 'false' (no prefix). + """ + person1 = contributor_stats.ContributorStats( + "user1", + False, + "url", + 100, + "commit url", + "sponsor_url_1", + ) + person2 = contributor_stats.ContributorStats( + "user2", + False, + "url2", + 200, + "commit url2", + "sponsor_url_2", + ) + # Set person2 as a new contributor since this cannot be set on initiatization of the object + person2.new_contributor = True + collaborators = [ + person1, + person2, + ] + ghe = "" + + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + None, + "org/repo", + False, + False, + ghe, + ) + + mock_file.assert_called_once_with("filename", "w", encoding="utf-8") + mock_file().write.assert_any_call( + "| Username | All Time Contribution Count | New Contributor | Commits between 2023-01-01 and 2023-01-02 |\n" + "| --- | --- | --- | --- |\n" + "| user1 | 100 | False | commit url |\n" + "| user2 | 200 | True | commit url2 |\n" + ) + if __name__ == "__main__": unittest.main()