Skip to content

Commit 0fd011c

Browse files
authored
Fix pr authors metadata (#9)
* don't @ commit display names * fix uv lock
1 parent 44c2a2d commit 0fd011c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

changeset/changelog.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
150150
)
151151
if gh_result.stdout.strip():
152152
metadata["pr_author"] = gh_result.stdout.strip()
153+
metadata["pr_author_is_username"] = True
153154

154155
# Also try to get co-authors from PR commits
155156
try:
@@ -176,6 +177,7 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
176177
commit_authors.discard('') # Remove empty strings
177178
if commit_authors:
178179
metadata["co_authors"] = list(commit_authors)
180+
metadata["co_authors_are_usernames"] = True
179181
except Exception:
180182
pass
181183

@@ -188,6 +190,7 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
188190
)
189191
if author_result.stdout.strip():
190192
metadata["pr_author"] = author_result.stdout.strip()
193+
metadata["pr_author_is_username"] = False
191194
else:
192195
# No PR number found, use commit author
193196
author_result = subprocess.run(
@@ -197,6 +200,7 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
197200
)
198201
if author_result.stdout.strip():
199202
metadata["pr_author"] = author_result.stdout.strip()
203+
metadata["pr_author_is_username"] = False
200204

201205
# Extract co-authors from commit message if we don't already have
202206
# them from GitHub API
@@ -213,6 +217,7 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
213217
and co_author_name != metadata.get("pr_author")
214218
):
215219
co_authors.append(co_author_name)
220+
metadata["co_authors_are_usernames"] = False
216221

217222
if co_authors:
218223
metadata["co_authors"] = co_authors
@@ -226,6 +231,9 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
226231
metadata["pr_number"] = os.environ.get("PR_NUMBER", "")
227232
if not metadata.get("pr_author"):
228233
metadata["pr_author"] = os.environ.get("PR_AUTHOR", "")
234+
# Assume env var contains username if it exists
235+
if metadata["pr_author"]:
236+
metadata["pr_author_is_username"] = True
229237
if not metadata.get("commit_hash"):
230238
metadata["commit_hash"] = os.environ.get(
231239
"COMMIT_SHA", git_info.get("commit", "")
@@ -239,7 +247,9 @@ def format_changelog_entry(entry: dict, config: dict, pr_metadata: dict) -> str:
239247
description = entry["description"]
240248
pr_number = pr_metadata.get("pr_number")
241249
pr_author = pr_metadata.get("pr_author")
250+
pr_author_is_username = pr_metadata.get("pr_author_is_username", False)
242251
co_authors = pr_metadata.get("co_authors", [])
252+
co_authors_are_usernames = pr_metadata.get("co_authors_are_usernames", False)
243253
commit_hash = pr_metadata.get("commit_hash", "")[:7]
244254
repo_url = pr_metadata.get("repo_url", "")
245255

@@ -257,18 +267,24 @@ def format_changelog_entry(entry: dict, config: dict, pr_metadata: dict) -> str:
257267
# Add author thanks if available
258268
authors_to_thank = []
259269
if pr_author:
260-
# Check if pr_author already contains @ symbol
270+
# Only add @ if we have a GitHub username, not a display name
261271
if pr_author.startswith("@"):
262272
authors_to_thank.append(pr_author)
263-
else:
273+
elif pr_author_is_username:
264274
authors_to_thank.append(f"@{pr_author}")
275+
else:
276+
# Display name from git - don't add @
277+
authors_to_thank.append(pr_author)
265278

266279
# Add co-authors
267280
for co_author in co_authors:
268281
if co_author.startswith("@"):
269282
authors_to_thank.append(co_author)
270-
else:
283+
elif co_authors_are_usernames:
271284
authors_to_thank.append(f"@{co_author}")
285+
else:
286+
# Display names from git - don't add @
287+
authors_to_thank.append(co_author)
272288

273289
if authors_to_thank:
274290
if len(authors_to_thank) == 1:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)