-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from github/markdown-output
Add markdown out and format commits as url
- Loading branch information
Showing
7 changed files
with
95 additions
and
73 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""This module contains the functions needed to write the output to markdown files.""" | ||
|
||
|
||
def write_to_markdown(collaborators, filename): | ||
""" | ||
This function writes a list of collaborators to a markdown file in table format. | ||
Each collaborator is represented as a dictionary with keys 'username', 'contribution_count', and 'commits'. | ||
Args: | ||
collaborators (list): A list of dictionaries, where each dictionary represents a collaborator. | ||
Each dictionary should have the keys 'username', 'contribution_count', and 'commits'. | ||
filename (str): The path of the markdown file to which the table will be written. | ||
""" | ||
headers = "| Username | Contribution Count | Commits |\n| --- | --- | --- |\n" | ||
table = headers | ||
|
||
for repo in collaborators: | ||
for collaborator in repo: | ||
username = collaborator.username | ||
contribution_count = collaborator.contribution_count | ||
commits = collaborator.commits | ||
|
||
row = f"| {username} | {contribution_count} | {commits} |\n" | ||
table += row | ||
|
||
with open(filename, "w", encoding="utf-8") as markdown_file: | ||
markdown_file.write("# Contributors\n\n") | ||
markdown_file.write(table) | ||
markdown_file.write( | ||
"\n _this file was generated by the [Contributors GitHub Action](https://github.com/github/contributors)\n" | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""This is the test module for the markdown module""" | ||
import unittest | ||
from unittest.mock import patch, mock_open | ||
from markdown import write_to_markdown | ||
import contributor_stats | ||
|
||
|
||
class TestMarkdown(unittest.TestCase): | ||
""" | ||
Test case for the markdown module. | ||
""" | ||
|
||
@patch("builtins.open", new_callable=mock_open) | ||
def test_write_to_markdown(self, mock_file): | ||
""" | ||
Test the write_to_markdown function. | ||
""" | ||
person1 = contributor_stats.ContributorStats( | ||
"user1", | ||
"url", | ||
100, | ||
"commit url", | ||
) | ||
person2 = contributor_stats.ContributorStats( | ||
"user2", | ||
"url2", | ||
200, | ||
"commit url2", | ||
) | ||
collaborators = [ | ||
[ | ||
person1, | ||
person2, | ||
] | ||
] | ||
|
||
write_to_markdown(collaborators, "filename") | ||
|
||
mock_file.assert_called_once_with("filename", "w", encoding="utf-8") | ||
mock_file().write.assert_any_call("# Contributors\n\n") | ||
mock_file().write.assert_any_call( | ||
"| Username | Contribution Count | Commits |\n| --- | --- | --- |\n| user1 | 100 | commit url |\n| user2 | 200 | commit url2 |\n" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |