Skip to content
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![Python package](https://github.com/github/contributors/actions/workflows/python-ci.yml/badge.svg)](https://github.com/github/contributors/actions/workflows/python-ci.yml)
[![Docker Image CI](https://github.com/github/contributors/actions/workflows/docker-ci.yml/badge.svg)](https://github.com/github/contributors/actions/workflows/docker-ci.yml)
[![CodeQL](https://github.com/github/contributors/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/github/contributors/actions/workflows/github-code-scanning/codeql)[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/github/contributors/badge)](https://scorecard.dev/viewer/?uri=github.com/github/contributors)
[![CodeQL](https://github.com/github/contributors/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/github/contributors/actions/workflows/github-code-scanning/codeql)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/github/contributors/badge)](https://scorecard.dev/viewer/?uri=github.com/github/contributors)

This is a GitHub Action that given an organization or specified repositories, produces information about the [contributors](https://chaoss.community/kb/metric-contributors/) over the specified time period.

Expand Down
3 changes: 2 additions & 1 deletion contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def __repr__(self) -> str:
f"contributor_stats(username={self.username}, "
f"new_contributor={self.new_contributor}, "
f"avatar_url={self.avatar_url}, "
f"contribution_count={self.contribution_count}, commit_url={self.commit_url})"
f"contribution_count={self.contribution_count}, "
f"commit_url={self.commit_url}, "
f"sponsor_info={self.sponsor_info})"
)

Expand Down
44 changes: 39 additions & 5 deletions test_contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def test_init(self):
"commit_url5",
)

def test_repr(self):
"""Test the __repr__ method includes key fields."""
expected = (
"contributor_stats(username=zkoppert, "
"new_contributor=False, "
"avatar_url=https://avatars.githubusercontent.com/u/29484535?v=4, "
"contribution_count=1261, "
"commit_url=commit_url5, "
"sponsor_info=)"
)
self.assertEqual(repr(self.contributor), expected)

def test_merge_contributors(self):
"""
Test the merge_contributors function.
Expand Down Expand Up @@ -113,15 +125,15 @@ def test_is_new_contributor_true(self):
username="user1",
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count="100",
contribution_count=100,
commit_url="url1",
sponsor_info="",
),
ContributorStats(
username="user2",
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count="200",
contribution_count=200,
commit_url="url2",
sponsor_info="",
),
Expand All @@ -141,15 +153,15 @@ def test_is_new_contributor_false(self):
username="user1",
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count="100",
contribution_count=100,
commit_url="url1",
sponsor_info="",
),
ContributorStats(
username="user2",
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count="200",
contribution_count=200,
commit_url="url2",
sponsor_info="",
),
Expand Down Expand Up @@ -179,7 +191,7 @@ def test_fetch_sponsor_info(self, mock_post):
username=user,
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count="100",
contribution_count=100,
commit_url="url1",
sponsor_info="",
),
Expand Down Expand Up @@ -214,6 +226,28 @@ def test_fetch_sponsor_info(self, mock_post):
timeout=60,
)

@patch("requests.post")
def test_fetch_sponsor_info_raises_on_error(self, mock_post):
"""Test get_sponsor_information raises when the API response is invalid."""
mock_response = MagicMock()
mock_response.status_code = 500
mock_response.json.return_value = {"errors": [{"message": "fail"}]}
mock_post.return_value = mock_response

contributors = [
ContributorStats(
username="user1",
new_contributor=False,
avatar_url="https://avatars.githubusercontent.com/u/",
contribution_count=100,
commit_url="url1",
sponsor_info="",
),
]

with self.assertRaises(ValueError):
get_sponsor_information(contributors, token="token", ghe="")


if __name__ == "__main__":
unittest.main()
Loading
Loading