Skip to content

Commit c655476

Browse files
authored
fix gh cli (#11)
1 parent 4ed1a56 commit c655476

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-19
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"changeset": patch
3+
---
4+
5+
emit errors when gh cli fails

changeset/changelog.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,38 +135,57 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
135135

136136
# Try to get PR author using GitHub CLI if available
137137
try:
138+
# Check if we're in GitHub Actions and have a token
139+
gh_token = (
140+
os.environ.get('GITHUB_TOKEN') or os.environ.get('GH_TOKEN')
141+
)
142+
143+
cmd = [
144+
"gh",
145+
"api",
146+
f"repos/{git_info.get('owner', '')}/"
147+
f"{git_info.get('repo', '')}/pulls/{pr_number}",
148+
"--jq",
149+
".user.login",
150+
]
151+
152+
env = os.environ.copy()
153+
if gh_token:
154+
env['GH_TOKEN'] = gh_token
155+
138156
gh_result = subprocess.run(
139-
[
140-
"gh",
141-
"api",
142-
f"repos/{git_info.get('owner', '')}/"
143-
f"{git_info.get('repo', '')}/pulls/{pr_number}",
144-
"--jq",
145-
".user.login",
146-
],
157+
cmd,
147158
capture_output=True,
148159
text=True,
149160
check=True,
161+
env=env,
150162
)
151163
if gh_result.stdout.strip():
152164
metadata["pr_author"] = gh_result.stdout.strip()
153165
metadata["pr_author_is_username"] = True
166+
print(
167+
f"✓ Got GitHub username for PR #{pr_number}: "
168+
f"{metadata['pr_author']}"
169+
)
154170

155171
# Also try to get co-authors from PR commits
156172
try:
157173
# Get all commits in the PR
174+
cmd = [
175+
"gh",
176+
"api",
177+
f"repos/{git_info.get('owner', '')}/"
178+
f"{git_info.get('repo', '')}/pulls/{pr_number}/commits",
179+
"--jq",
180+
".[].author.login",
181+
]
182+
158183
commits_result = subprocess.run(
159-
[
160-
"gh",
161-
"api",
162-
f"repos/{git_info.get('owner', '')}/"
163-
f"{git_info.get('repo', '')}/pulls/{pr_number}/commits",
164-
"--jq",
165-
".[].author.login",
166-
],
184+
cmd,
167185
capture_output=True,
168186
text=True,
169187
check=True,
188+
env=env,
170189
)
171190
if commits_result.stdout.strip():
172191
# Get unique commit authors (excluding the PR author)
@@ -181,8 +200,9 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
181200
except Exception:
182201
pass
183202

184-
except Exception:
203+
except Exception as e:
185204
# If gh command fails, try to extract from commit author
205+
print(f"⚠️ GitHub CLI failed for PR #{pr_number}: {e!s}")
186206
author_result = subprocess.run(
187207
["git", "log", "-1", "--format=%an", commit_hash],
188208
capture_output=True,
@@ -191,6 +211,10 @@ def get_changeset_metadata(changeset_path: Path) -> dict:
191211
if author_result.stdout.strip():
192212
metadata["pr_author"] = author_result.stdout.strip()
193213
metadata["pr_author_is_username"] = False
214+
print(
215+
f"⚠️ Using git author name for PR #{pr_number}: "
216+
f"{metadata['pr_author']} (no @ will be added)"
217+
)
194218
else:
195219
# No PR number found, use commit author
196220
author_result = subprocess.run(

changeset/changeset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def version(dry_run: bool, skip_changelog: bool):
680680
package_changes[package] = {"changes": [], "descriptions": []}
681681
package_changes[package]["changes"].append(change_type)
682682
package_changes[package]["descriptions"].append(
683-
{"type": change_type, "description": desc, "changeset": filepath.name}
683+
{"type": change_type, "description": desc, "changeset": filepath.name, "filepath": filepath}
684684
)
685685

686686
# Show changesets

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)