-
Notifications
You must be signed in to change notification settings - Fork 23
chore(harness): inject PR template + review-handling guidance #2214
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
Open
richardsolomou
wants to merge
4
commits into
main
Choose a base branch
from
posthog-code/pr-template-and-review-hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−2
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7b5e781
chore(harness): add SessionStart hook for PR template + review handling
richardsolomou df16406
chore(harness): instruct agent to link matching open issues in PR body
richardsolomou be3f95b
chore(harness): move PR template + review + issue-link guidance into …
richardsolomou a4bece6
fix(harness): drop unnecessary \\$id escape in resolveReviewThread sn…
richardsolomou 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env bash | ||
| # SessionStart hook: inject PR workflow guidance. | ||
| # - Always: instruct the agent to leave a reply and resolve each PR review | ||
| # conversation it deals with. | ||
| # - Always: instruct the agent to search for matching open issues before | ||
| # opening a PR and link them via `Closes #N` / `Refs #N`. | ||
| # - When detectable: inject the repo's PR template (or the org's `.github` | ||
| # repo template as a fallback) so PRs are opened with the right structure. | ||
|
|
||
| set -uo pipefail | ||
|
|
||
| cd "${CLAUDE_PROJECT_DIR:-$PWD}" 2>/dev/null || exit 0 | ||
| git rev-parse --git-dir >/dev/null 2>&1 || exit 0 | ||
|
|
||
| template="" | ||
| src="" | ||
|
|
||
| for path in \ | ||
| .github/pull_request_template.md \ | ||
| .github/PULL_REQUEST_TEMPLATE.md \ | ||
| .github/pull_request_template.txt \ | ||
| docs/pull_request_template.md \ | ||
| docs/PULL_REQUEST_TEMPLATE.md \ | ||
| pull_request_template.md \ | ||
| PULL_REQUEST_TEMPLATE.md | ||
| do | ||
| if [[ -f "$path" ]]; then | ||
| template=$(cat "$path") | ||
| src="repo: $path" | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if [[ -z "$template" ]] && command -v gh >/dev/null 2>&1; then | ||
| remote=$(git config --get remote.origin.url 2>/dev/null || echo "") | ||
| owner=$(printf '%s' "$remote" | sed -nE 's|.*github\.com[:/]([^/]+)/.*|\1|p') | ||
|
|
||
| if [[ -n "$owner" ]]; then | ||
| for path in \ | ||
| .github/pull_request_template.md \ | ||
| .github/PULL_REQUEST_TEMPLATE.md \ | ||
| profile/pull_request_template.md \ | ||
| pull_request_template.md \ | ||
| PULL_REQUEST_TEMPLATE.md | ||
| do | ||
| content=$(gh api "/repos/${owner}/.github/contents/${path}" --jq '.content' 2>/dev/null | base64 -d 2>/dev/null || true) | ||
| if [[ -n "$content" ]]; then | ||
| template="$content" | ||
| src="org fallback: ${owner}/.github/${path}" | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
| fi | ||
|
|
||
| review_block="### PR review / comment handling | ||
| When addressing PR review comments or review threads, treat each thread as done only after BOTH of these: | ||
| 1. Reply to the thread with a short note describing what changed (and the commit SHA when useful) so the reviewer can see the resolution inline. | ||
| 2. Resolve the conversation thread. | ||
| Use the GitHub GraphQL API via \`gh\` to resolve threads, e.g.: | ||
| gh api graphql -f query='mutation(\$id:ID!){resolveReviewThread(input:{threadId:\$id}){thread{isResolved}}}' -f id=\"<thread-node-id>\" | ||
| Reply to a thread via \`gh api -X POST /repos/{owner}/{repo}/pulls/{n}/comments/{id}/replies -f body='...'\`. Never silently push fixes without confirming each related thread is replied to and resolved." | ||
|
|
||
| issue_block="### Related-issue linking | ||
| Before opening a pull request, search the repo for existing open issues that match the work in the branch. Use \`gh issue list --state open --search '<keywords>'\` (and \`gh issue view <n>\` to confirm relevance) to find candidates derived from the branch name, commit messages, and changed files. For every issue the PR would resolve, include a \`Closes #<n>\` line in the PR body so GitHub auto-links and auto-closes it on merge. If the issue is related but the PR does not fully resolve it, use \`Refs #<n>\` instead. Skip this only when there are clearly no matching issues." | ||
|
|
||
| if [[ -n "$template" ]]; then | ||
| template_block=" | ||
|
|
||
| ### PR template | ||
| A PR template was detected (${src}). When opening a pull request with \`gh pr create\`, pass the template below as the \`--body\` argument — preserve the section headings exactly and fill each section based on the branch's actual changes. Do NOT fall back to the generic Summary/Test plan format. Keep any required PR footer (e.g. the PostHog Code attribution) appended after the template. | ||
|
|
||
| --- BEGIN PR TEMPLATE --- | ||
| ${template} | ||
| --- END PR TEMPLATE ---" | ||
| else | ||
| template_block="" | ||
| fi | ||
|
|
||
| ctx="${review_block} | ||
|
|
||
| ${issue_block}${template_block}" | ||
|
|
||
| jq -nc --arg c "$ctx" '{hookSpecificOutput: {hookEventName: "SessionStart", additionalContext: $c}}' | ||
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.