-
Notifications
You must be signed in to change notification settings - Fork 1
Make /address-pr-comment skill use the URL of the PR context #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2a8015f
ruff
ejfine 407bd32
workspace
ejfine 4192c10
bump faker
ejfine 0352a2b
pytest
ejfine fb75284
comment
ejfine ed469aa
more pyrefly config
ejfine 15ab7b5
node
ejfine bba6854
pytest assertions
ejfine 708e258
bump pyrefly
ejfine 2482a8c
derive commit link
ejfine 7de5e13
verify env
ejfine 67bae4a
pr open
ejfine f152ff4
pytest
ejfine 048f5f2
dryer
ejfine 956606a
check gh auth before PR lookup to surface clear login error
ejfine dac9e51
Pass resolved PR number to commit-link.py in SKILL.md
ejfine c2a1953
Validate origin+GitHub URL in verify-env.py has_remote()
ejfine 12f9ca6
Fix commit link URL to use /commits/ not /changes/
ejfine 7fc2137
Render commit link as Markdown hyperlink in reply files
ejfine ce40658
Merge remote-tracking branch 'origin/main' into more-mutmut
ejfine e8d45cf
bump
ejfine ee8f45a
Update commit-link.py docstring to explain Markdown link rationale
ejfine 0f3ae6a
Move Markdown link rationale from docstring to inline comment
ejfine aee79e4
Fix docstring: /commits/<hash> redirects to PR-scoped changes view
ejfine 865587b
docstring
ejfine 491cb21
liss
ejfine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/usr/bin/env python3 | ||
|
ejfine marked this conversation as resolved.
|
||
| """Replace the [COMMIT LINK] placeholder in a reply file with the PR-scoped commit link. | ||
|
|
||
| Usage: commit-link.py <reply-file> [--pr <number>] [--commit <hash>] | ||
|
|
||
| Everything is self-derived when the optional flags are omitted: | ||
| --pr auto-detected from the current branch via `gh pr view` | ||
| --commit defaults to HEAD | ||
|
|
||
| The link points at the commit *within the PR* (GitHub redirects | ||
| /pull/<pr>/changes/<hash> to the PR-scoped changes view) rather than the | ||
| repo-wide commit view (/commit/<hash>), so replies posted against it are | ||
| associated with the PR. Owner and repo are derived from the git remote | ||
| automatically. | ||
|
|
||
| Prints "replaced" on success. Exits non-zero if the placeholder is absent. | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| sys.path.insert(0, str(Path(__file__).parent)) | ||
| from utils import owner_repo_from_remote | ||
| from utils import run_cmd | ||
|
|
||
| PLACEHOLDER = "[COMMIT LINK]" | ||
|
|
||
|
|
||
| def resolve_commit(ref: str) -> str: | ||
| try: | ||
| result = run_cmd( | ||
| ["git", "rev-parse", ref], | ||
| timeout=15, | ||
| timeout_msg=f"Timed out resolving commit ref '{ref}'.", | ||
| ) | ||
| except subprocess.CalledProcessError as e: | ||
| _ = sys.stderr.write(f"Cannot resolve commit ref '{ref}': {e.stderr}\n") | ||
| sys.exit(1) | ||
| return result.stdout.strip() | ||
|
|
||
|
|
||
| def detect_pr() -> int: | ||
| try: | ||
| result = run_cmd( | ||
| ["gh", "pr", "view", "--json", "number"], | ||
| timeout=30, | ||
| timeout_msg="Timed out detecting the PR for the current branch.", | ||
| ) | ||
| except subprocess.CalledProcessError as e: | ||
| _ = sys.stderr.write(f"Cannot detect a PR for the current branch: {e.stderr}\nPass --pr explicitly.\n") | ||
| sys.exit(1) | ||
| return int(json.loads(result.stdout)["number"]) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| _ = parser.add_argument("reply_file", type=Path, help="Reply file containing the [COMMIT LINK] placeholder") | ||
| _ = parser.add_argument("--pr", type=int, default=None, help="PR number (default: auto-detect from current branch)") | ||
| _ = parser.add_argument("--commit", default="HEAD", help="Commit ref to link (default: HEAD)") | ||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| content = args.reply_file.read_text(encoding="utf-8") | ||
| except OSError as e: | ||
| _ = sys.stderr.write(f"File error for {args.reply_file}: {e}\n") | ||
| sys.exit(1) | ||
|
|
||
| if PLACEHOLDER not in content: | ||
| _ = sys.stderr.write(f"Placeholder {PLACEHOLDER} not found in {args.reply_file}.\n") | ||
| sys.exit(1) | ||
|
|
||
| owner, repo = owner_repo_from_remote() | ||
| pr = args.pr if args.pr is not None else detect_pr() | ||
| commit = resolve_commit(args.commit) | ||
| url = f"https://github.com/{owner}/{repo}/pull/{pr}/changes/{commit}" | ||
| # Markdown format required: GitHub auto-canonicalises bare PR-scoped URLs to | ||
| # the standalone /commit/<hash> view, where comments are not PR-associated. | ||
| link = f"[{commit[:7]}]({url})" | ||
|
|
||
| try: | ||
| _ = args.reply_file.write_text(content.replace(PLACEHOLDER, link), encoding="utf-8") | ||
| except OSError as e: | ||
| _ = sys.stderr.write(f"File error for {args.reply_file}: {e}\n") | ||
| sys.exit(1) | ||
| _ = sys.stdout.write("replaced\n") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.