Skip to content

Commit 211543e

Browse files
Copilotzkoppert
andcommitted
Support any email domain for co-authors, not just GitHub noreply
Co-authored-by: zkoppert <6935431+zkoppert@users.noreply.github.com>
1 parent 4454fe7 commit 211543e

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ This action can be configured to authenticate with GitHub App Installation or Pe
9393
| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` |
9494
| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" |
9595
| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" |
96-
| `ACKNOWLEDGE_COAUTHORS` | False | True | If you want to include co-authors from commit messages as contributors. Co-authors are identified via the `Co-authored-by:` trailer in commit messages using the GitHub noreply email format (e.g., `username@users.noreply.github.com`). This will impact action performance as it requires scanning all commits. ie. ACKNOWLEDGE_COAUTHORS = "True" or ACKNOWLEDGE_COAUTHORS = "False" |
96+
| `ACKNOWLEDGE_COAUTHORS` | False | True | If you want to include co-authors from commit messages as contributors. Co-authors are identified via the `Co-authored-by:` trailer in commit messages. The action will extract GitHub usernames from GitHub noreply emails (e.g., `username@users.noreply.github.com`) or use the full email address for other email domains. This will impact action performance as it requires scanning all commits. ie. ACKNOWLEDGE_COAUTHORS = "True" or ACKNOWLEDGE_COAUTHORS = "False" |
9797

9898
**Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date.
9999

100100
**Performance Note:** Using start and end dates will reduce speed of the action by approximately 63X. ie without dates if the action takes 1.7 seconds, it will take 1 minute and 47 seconds.
101101

102-
**Co-authors Note:** When `ACKNOWLEDGE_COAUTHORS` is enabled, the action will scan commit messages for `Co-authored-by:` trailers and include those users as contributors. Only co-authors with GitHub noreply email addresses (e.g., `username@users.noreply.github.com`) will be recognized, as this is the standard format used by GitHub for [creating commits with multiple authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors).
102+
**Co-authors Note:** When `ACKNOWLEDGE_COAUTHORS` is enabled, the action will scan commit messages for `Co-authored-by:` trailers and include those users as contributors. For GitHub noreply email addresses (e.g., `username@users.noreply.github.com`), the username will be extracted. For other email addresses (e.g., `john@example.com`), the full email address will be used as the contributor identifier. See [GitHub's documentation on creating commits with multiple authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors).
103103

104104
### Example workflows
105105

contributors.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,32 +156,37 @@ def get_all_contributors(
156156

157157
def get_coauthors_from_message(commit_message: str) -> List[str]:
158158
"""
159-
Extract co-author usernames from a commit message.
159+
Extract co-author identifiers from a commit message.
160160
161161
Co-authored-by trailers follow the format:
162162
Co-authored-by: Name <email>
163-
Or with a GitHub username:
164-
Co-authored-by: Name <username@users.noreply.github.com>
163+
164+
For GitHub noreply emails (username@users.noreply.github.com), extracts the username.
165+
For other emails, extracts the full email address.
165166
166167
Args:
167168
commit_message (str): The commit message to parse
168169
169170
Returns:
170-
List[str]: List of GitHub usernames extracted from co-author trailers
171+
List[str]: List of co-author identifiers (GitHub usernames or email addresses)
171172
"""
172173
# Match Co-authored-by trailers - case insensitive
173174
# Format: Co-authored-by: Name <email>
174175
pattern = r"Co-authored-by:\s*[^<]*<([^>]+)>"
175176
matches = re.findall(pattern, commit_message, re.IGNORECASE)
176177

177-
usernames = []
178+
identifiers = []
178179
for email in matches:
179180
# Check if it's a GitHub noreply email format: username@users.noreply.github.com
180181
noreply_pattern = r"^(\d+\+)?([^@]+)@users\.noreply\.github\.com$"
181182
noreply_match = re.match(noreply_pattern, email)
182183
if noreply_match:
183-
usernames.append(noreply_match.group(2))
184-
return usernames
184+
# For GitHub noreply emails, extract just the username
185+
identifiers.append(noreply_match.group(2))
186+
else:
187+
# For other emails, use the full email address
188+
identifiers.append(email)
189+
return identifiers
185190

186191

187192
def get_contributors(

test_contributors.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ def test_get_coauthors_from_message_multiple_coauthors(self):
256256

257257
def test_get_coauthors_from_message_with_regular_email(self):
258258
"""
259-
Test that regular emails are not extracted as co-authors.
259+
Test that regular emails are extracted as co-authors.
260260
"""
261261
message = """Fix bug
262262
263263
Co-authored-by: John Doe <john@example.com>
264264
"""
265265
result = get_coauthors_from_message(message)
266-
self.assertEqual(result, [])
266+
self.assertEqual(result, ["john@example.com"])
267267

268268
def test_get_coauthors_from_message_case_insensitive(self):
269269
"""
@@ -292,6 +292,19 @@ def test_get_coauthors_from_message_no_coauthors(self):
292292
result = get_coauthors_from_message(message)
293293
self.assertEqual(result, [])
294294

295+
def test_get_coauthors_from_message_mixed_email_types(self):
296+
"""
297+
Test extracting co-authors with both GitHub noreply and regular emails.
298+
"""
299+
message = """Feature implementation
300+
301+
Co-authored-by: Alice <alice@users.noreply.github.com>
302+
Co-authored-by: Bob <bob@example.com>
303+
Co-authored-by: Charlie <12345+charlie@users.noreply.github.com>
304+
"""
305+
result = get_coauthors_from_message(message)
306+
self.assertEqual(result, ["alice", "bob@example.com", "charlie"])
307+
295308
def test_get_coauthor_contributors(self):
296309
"""
297310
Test the get_coauthor_contributors function.

0 commit comments

Comments
 (0)