Skip to content

fix: Explicitly handle LINK_TO_PROFILE flag in markdown output #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]
Expand Down Expand Up @@ -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:
Expand Down
55 changes: 52 additions & 3 deletions test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_write_to_markdown(self, mock_file):
"2023-01-02",
None,
"org/repo",
"false",
False,
True,
ghe,
)
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_write_to_markdown_with_sponsors(self, mock_file):
"2023-01-02",
None,
"org/repo",
"true",
True,
True,
ghe,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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()
Loading