Skip to content

Commit 9f91afc

Browse files
committed
feat: add company column to contributor output
Include the GitHub profile company in markdown and JSON, and update README examples. Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
1 parent f6f4814 commit 9f91afc

8 files changed

Lines changed: 86 additions & 38 deletions

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ jobs:
219219
| ------------------ | ------------------- | ------------------ |
220220
| 1 | 143 | 0% |
221221
222-
| Username | All Time Contribution Count | New Contributor | Commits between 2021-01-01 and 2023-10-10 |
223-
| --------- | --------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
224-
| @zkoppert | 143 | False | [super-linter/super-linter](https://github.com/super-linter/super-linter/commits?author=zkoppert&since=2021-01-01&until=2023-10-10) |
222+
| Username | Company | All Time Contribution Count | New Contributor | Commits between 2021-01-01 and 2023-10-10 |
223+
| --------- | -------- | --------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
224+
| @zkoppert | @github | 143 | False | [super-linter/super-linter](https://github.com/super-linter/super-linter/commits?author=zkoppert&since=2021-01-01&until=2023-10-10) |
225225
```
226226

227227
## Example Markdown output with no dates supplied
@@ -235,9 +235,9 @@ jobs:
235235
| ------------------ | ------------------- | ------------------ |
236236
| 1 | 1913 | 0% |
237237
238-
| Username | All Time Contribution Count | New Contributor | Sponsor URL | Commits between 2021-09-01 and 2023-09-30 |
239-
| --------- | --------------------------- | --------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
240-
| @zkoppert | 1913 | False | [Sponsor Link](https://github.com/sponsors/zkoppert) | [super-linter/super-linter](https://github.com/super-linter/super-linter/commits?author=zkoppert&since=2021-09-01&until=2023-09-30) |
238+
| Username | Company | All Time Contribution Count | New Contributor | Sponsor URL | Commits between 2021-09-01 and 2023-09-30 |
239+
| --------- | -------- | --------------------------- | --------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
240+
| @zkoppert | @github | 1913 | False | [Sponsor Link](https://github.com/sponsors/zkoppert) | [super-linter/super-linter](https://github.com/super-linter/super-linter/commits?author=zkoppert&since=2021-09-01&until=2023-09-30) |
241241
```
242242

243243
## GitHub Actions Job Summary

contributor_stats.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# [
44
# {
55
# "username" : "zkoppert",
6+
# "company" : "@github",
67
# "new_contributor" : "False",
78
# "avatar_url" : "https://avatars.githubusercontent.com/u/29484535?v=4",
89
# "contribution_count" : 1261,
@@ -23,6 +24,7 @@ class ContributorStats:
2324
2425
Attributes:
2526
username (str): The username of the contributor
27+
company (str): The company listed on the contributor's GitHub profile
2628
new_contributor (bool): Whether the contributor is new or returning
2729
avatar_url (str): The url of the contributor's avatar
2830
contribution_count (int): The number of contributions the contributor has made
@@ -38,6 +40,7 @@ def __new__(cls, *args, **kwargs): # pylint: disable=unused-argument
3840
def __init__(
3941
self,
4042
username: str,
43+
company: str,
4144
new_contributor: bool,
4245
avatar_url: str,
4346
contribution_count: int,
@@ -47,6 +50,7 @@ def __init__(
4750
"""Initialize the contributor_stats object"""
4851
new_contributor = False
4952
self.username = username
53+
self.company = company
5054
self.new_contributor = new_contributor
5155
self.avatar_url = avatar_url
5256
self.contribution_count = contribution_count
@@ -57,6 +61,7 @@ def __repr__(self) -> str:
5761
"""Return the representation of the contributor_stats object"""
5862
return (
5963
f"contributor_stats(username={self.username}, "
64+
f"company={self.company}, "
6065
f"new_contributor={self.new_contributor}, "
6166
f"avatar_url={self.avatar_url}, "
6267
f"contribution_count={self.contribution_count}, commit_url={self.commit_url})"
@@ -67,6 +72,7 @@ def __eq__(self, other) -> bool:
6772
"""Check if two contributor_stats objects are equal"""
6873
return (
6974
self.username == other.username
75+
and self.company == other.company
7076
and self.new_contributor == other.new_contributor
7177
and self.avatar_url == other.avatar_url
7278
and self.contribution_count == other.contribution_count
@@ -121,6 +127,8 @@ def merge_contributors(contributors: list) -> list:
121127
merged_contributor.new_contributor
122128
or contributor.new_contributor
123129
)
130+
if not merged_contributor.company and contributor.company:
131+
merged_contributor.company = contributor.company
124132

125133
else:
126134
merged_contributors.append(contributor)

contributors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ def get_contributors(repo: object, start_date: str, end_date: str, ghe: str):
178178
commit_url = f"{endpoint}/{repo.full_name}/commits?author={user.login}&since={start_date}&until={end_date}"
179179
else:
180180
commit_url = f"{endpoint}/{repo.full_name}/commits?author={user.login}"
181+
company = getattr(user, "company", "") or ""
181182
contributor = contributor_stats.ContributorStats(
182183
user.login,
184+
company,
183185
False,
184186
user.avatar_url,
185187
user.contributions_count,

markdown.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def write_to_markdown(
1919
This function writes a list of collaborators to a markdown file in table format
2020
and optionally to GitHub Actions Job Summary if running in a GitHub Actions environment.
2121
Each collaborator is represented as a dictionary with keys 'username',
22-
'contribution_count', 'new_contributor', and 'commits'.
22+
'company', 'contribution_count', 'new_contributor', and 'commits'.
2323
2424
Args:
2525
collaborators (list): A list of dictionaries, where each dictionary
2626
represents a collaborator. Each dictionary should
27-
have the keys 'username', 'contribution_count',
27+
have the keys 'username', 'company', 'contribution_count',
2828
and 'commits'.
2929
filename (str): The path of the markdown file to which the table will
3030
be written.
@@ -157,7 +157,7 @@ def get_summary_table(collaborators, start_date, end_date, total_contributions):
157157
158158
Args:
159159
collaborators (list): A list of dictionaries, where each dictionary represents a collaborator.
160-
Each dictionary should have the keys 'username', 'contribution_count', and 'commits'.
160+
Each dictionary should have the keys 'username', 'company', 'contribution_count', and 'commits'.
161161
start_date (str): The start date of the date range for the contributor list.
162162
end_date (str): The end date of the date range for the contributor list.
163163
total_contributions (int): The total number of contributions made by all of the contributors.
@@ -215,7 +215,7 @@ def get_contributor_table(
215215
total_contributions (int): The total number of contributions made by all of the contributors.
216216
217217
"""
218-
columns = ["Username", "All Time Contribution Count"]
218+
columns = ["Username", "Company", "All Time Contribution Count"]
219219
if start_date and end_date:
220220
columns += ["New Contributor"]
221221
if sponsor_info == "true":
@@ -235,6 +235,7 @@ def get_contributor_table(
235235
total_contributions += collaborator.contribution_count
236236
username = collaborator.username
237237
contribution_count = collaborator.contribution_count
238+
company = collaborator.company.strip() if collaborator.company else "-"
238239
if repository:
239240
commit_urls = collaborator.commit_url
240241
if organization:
@@ -250,9 +251,7 @@ def get_contributor_table(
250251
commit_urls += f"{url}, "
251252
new_contributor = collaborator.new_contributor
252253

253-
row = (
254-
f"| {'' if not link_to_profile else '@'}{username} | {contribution_count} |"
255-
)
254+
row = f"| {'' if not link_to_profile else '@'}{username} | {company} | {contribution_count} |"
256255
if "New Contributor" in columns:
257256
row += f" {new_contributor} |"
258257
if "Sponsor URL" in columns:

test_contributor_stats.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def setUp(self):
2222
"""
2323
self.contributor = ContributorStats(
2424
"zkoppert",
25+
"@github",
2526
False,
2627
"https://avatars.githubusercontent.com/u/29484535?v=4",
2728
1261,
@@ -34,6 +35,7 @@ def test_init(self):
3435
Test the __init__ method of the ContributorStats class.
3536
"""
3637
self.assertEqual(self.contributor.username, "zkoppert")
38+
self.assertEqual(self.contributor.company, "@github")
3739
self.assertFalse(self.contributor.new_contributor)
3840
self.assertEqual(
3941
self.contributor.avatar_url,
@@ -51,6 +53,7 @@ def test_merge_contributors(self):
5153
"""
5254
contributor1 = ContributorStats(
5355
"user1",
56+
"@company1",
5457
False,
5558
"https://avatars.githubusercontent.com/u/29484535?v=4",
5659
100,
@@ -59,6 +62,7 @@ def test_merge_contributors(self):
5962
)
6063
contributor2 = ContributorStats(
6164
"user2",
65+
"@company2",
6266
False,
6367
"https://avatars.githubusercontent.com/u/29484535?v=4",
6468
200,
@@ -67,6 +71,7 @@ def test_merge_contributors(self):
6771
)
6872
contributor3 = ContributorStats(
6973
"user1",
74+
"@company1",
7075
False,
7176
"https://avatars.githubusercontent.com/u/29484535?v=4",
7277
150,
@@ -83,6 +88,7 @@ def test_merge_contributors(self):
8388
expected_result = [
8489
ContributorStats(
8590
"user1",
91+
"@company1",
8692
False,
8793
"https://avatars.githubusercontent.com/u/29484535?v=4",
8894
250,
@@ -91,6 +97,7 @@ def test_merge_contributors(self):
9197
),
9298
ContributorStats(
9399
"user2",
100+
"@company2",
94101
False,
95102
"https://avatars.githubusercontent.com/u/29484535?v=4",
96103
200,
@@ -111,6 +118,7 @@ def test_is_new_contributor_true(self):
111118
returning_contributors = [
112119
ContributorStats(
113120
username="user1",
121+
company="",
114122
new_contributor=False,
115123
avatar_url="https://avatars.githubusercontent.com/u/",
116124
contribution_count="100",
@@ -119,6 +127,7 @@ def test_is_new_contributor_true(self):
119127
),
120128
ContributorStats(
121129
username="user2",
130+
company="",
122131
new_contributor=False,
123132
avatar_url="https://avatars.githubusercontent.com/u/",
124133
contribution_count="200",
@@ -139,6 +148,7 @@ def test_is_new_contributor_false(self):
139148
returning_contributors = [
140149
ContributorStats(
141150
username="user1",
151+
company="",
142152
new_contributor=False,
143153
avatar_url="https://avatars.githubusercontent.com/u/",
144154
contribution_count="100",
@@ -147,6 +157,7 @@ def test_is_new_contributor_false(self):
147157
),
148158
ContributorStats(
149159
username="user2",
160+
company="",
150161
new_contributor=False,
151162
avatar_url="https://avatars.githubusercontent.com/u/",
152163
contribution_count="200",
@@ -177,6 +188,7 @@ def test_fetch_sponsor_info(self, mock_post):
177188
returning_contributors = [
178189
ContributorStats(
179190
username=user,
191+
company="",
180192
new_contributor=False,
181193
avatar_url="https://avatars.githubusercontent.com/u/",
182194
contribution_count="100",

test_contributors.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ def test_get_contributors(self, mock_contributor_stats):
2222
mock_user.login = "user"
2323
mock_user.avatar_url = "https://avatars.githubusercontent.com/u/12345678?v=4"
2424
mock_user.contributions_count = 100
25+
mock_user.company = "@company"
2526
mock_repo.contributors.return_value = [mock_user]
2627
mock_repo.full_name = "owner/repo"
2728

2829
get_contributors(mock_repo, "2022-01-01", "2022-12-31", "")
2930

3031
mock_contributor_stats.assert_called_once_with(
3132
"user",
33+
"@company",
3234
False,
3335
"https://avatars.githubusercontent.com/u/12345678?v=4",
3436
100,
@@ -49,6 +51,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors):
4951
mock_get_contributors.return_value = [
5052
ContributorStats(
5153
"user",
54+
"@company",
5255
False,
5356
"https://avatars.githubusercontent.com/u/29484535?v=4",
5457
100,
@@ -67,6 +70,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors):
6770
[
6871
ContributorStats(
6972
"user",
73+
"@company",
7074
False,
7175
"https://avatars.githubusercontent.com/u/29484535?v=4",
7276
200,
@@ -88,6 +92,7 @@ def test_get_all_contributors_with_repository(self, mock_get_contributors):
8892
mock_get_contributors.return_value = [
8993
ContributorStats(
9094
"user",
95+
"@company",
9196
False,
9297
"https://avatars.githubusercontent.com/u/29484535?v=4",
9398
100,
@@ -106,6 +111,7 @@ def test_get_all_contributors_with_repository(self, mock_get_contributors):
106111
[
107112
ContributorStats(
108113
"user",
114+
"@company",
109115
False,
110116
"https://avatars.githubusercontent.com/u/29484535?v=4",
111117
100,
@@ -128,10 +134,12 @@ def test_get_contributors_skip_users_with_no_commits(self, mock_contributor_stat
128134
mock_user.login = "user"
129135
mock_user.avatar_url = "https://avatars.githubusercontent.com/u/12345678?v=4"
130136
mock_user.contributions_count = 100
137+
mock_user.company = "@company"
131138
mock_user2 = MagicMock()
132139
mock_user2.login = "user2"
133140
mock_user2.avatar_url = "https://avatars.githubusercontent.com/u/12345679?v=4"
134141
mock_user2.contributions_count = 102
142+
mock_user2.company = "@company2"
135143

136144
mock_repo.contributors.return_value = [mock_user]
137145
mock_repo.full_name = "owner/repo"
@@ -143,6 +151,7 @@ def test_get_contributors_skip_users_with_no_commits(self, mock_contributor_stat
143151
# Note that only user is returned and user2 is not returned here because there were no commits in the date range
144152
mock_contributor_stats.assert_called_once_with(
145153
"user",
154+
"@company",
146155
False,
147156
"https://avatars.githubusercontent.com/u/12345678?v=4",
148157
100,
@@ -160,6 +169,7 @@ def test_get_contributors_skip_bot(self, mock_contributor_stats):
160169
mock_user.login = "[bot]"
161170
mock_user.avatar_url = "https://avatars.githubusercontent.com/u/12345678?v=4"
162171
mock_user.contributions_count = 100
172+
mock_user.company = "@company"
163173

164174
mock_repo.contributors.return_value = [mock_user]
165175
mock_repo.full_name = "owner/repo"
@@ -181,6 +191,7 @@ def test_get_contributors_no_commit_end_date(self, mock_contributor_stats):
181191
mock_user.login = "user"
182192
mock_user.avatar_url = "https://avatars.githubusercontent.com/u/12345678?v=4"
183193
mock_user.contributions_count = 100
194+
mock_user.company = "@company"
184195

185196
mock_repo.contributors.return_value = [mock_user]
186197
mock_repo.full_name = "owner/repo"
@@ -192,6 +203,7 @@ def test_get_contributors_no_commit_end_date(self, mock_contributor_stats):
192203
# Note that only user is returned and user2 is not returned here because there were no commits in the date range
193204
mock_contributor_stats.assert_called_once_with(
194205
"user",
206+
"@company",
195207
False,
196208
"https://avatars.githubusercontent.com/u/12345678?v=4",
197209
100,

test_json_writer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def setUp(self):
2424
"contributors": [
2525
{
2626
"username": "test_user",
27+
"company": "@company",
2728
"new_contributor": False,
2829
"avatar_url": "https://test_url.com",
2930
"contribution_count": 10,
@@ -38,6 +39,7 @@ def test_write_to_json(self):
3839
contributors = (
3940
ContributorStats(
4041
username="test_user",
42+
company="@company",
4143
new_contributor=False,
4244
avatar_url="https://test_url.com",
4345
contribution_count=10,

0 commit comments

Comments
 (0)