GitHub PR 全流程操作
github-pr-workflow
GitHub PR 完整生命周期:分支、提交、发起 PR、CI、合并。
- License 许可
- MIT
- 最近更新
- 2026-11-06
- Stars
- ★ 5
- Forks
- 4
01 前言 Front Matter
- name
- github-pr-workflow
- author
- Hermes Agent
- license
- MIT
- version
- 1.1.0
- metadata
- { "hermes": { "tags": [ "GitHub", "Pull-Requests", "CI/CD", "Git", "Automation", "Merge" ], "related_skills": [ "github-auth", "github-code-review" ] } }
- description
- GitHub PR lifecycle: branch, commit, open, CI, merge.
02 资源文件 6
- 参考文档references/ci-troubleshooting.md4.8 KB
- 参考文档references/conventional-commits.md2.4 KB
- 参考文档references/opencode-pr-feedback-fix-cycle.md2.0 KB
- 参考文档references/pr-review-thread-graphql.md2.8 KB
- 参考文档templates/pr-body-bugfix.md513 B
- 参考文档templates/pr-body-feature.md580 B
03 SKILL.md 正文
GitHub Pull Request Workflow
Complete guide for managing the PR lifecycle. Each section shows the gh way first, then the git + curl fallback for machines without gh.
Prerequisites
- Authenticated with GitHub (see
github-authskill) - Inside a git repository with a GitHub remote
- For Aaron's repositories under
~/code/, also load the repo-appropriate coding workflow before committing/pushing. If Aaron asks for Linear-backed OpenCode-driven work, first verify the independently maintained OpenCode command and both helper scripts required byhermes-opencode-linear-build. If they are absent, use a maintained Pi/Codex workflow. When the compatibility workflow is provisioned, OpenCode owns/cmd:linear-build-workspace, including commit/push/PR; Hermes remains read-only unless Aaron explicitly authorizes a bypass.
Operating discipline for Aaron
- Prefer one clear command per purpose. Avoid oversized shell chains that combine validation, inspection, release checks, and quoting-heavy commands into one brittle invocation.
- If a command fails due quoting or timeout, split the task into smaller commands instead of retrying a giant combined command.
- Keep secrets out of PR bodies, comments, diffs, and skill/reference updates; redact credential values.
- For user-visible UI/desktop changes, PRs should include validation evidence: screenshots at minimum and video when practical. Prefer committed
docs/pr-evidence/<issue-or-slug>/artifacts or repo-approved artifact links so GitHub can render the evidence from the PR body/comment.
Quick Auth Detection
# Determine which method to use throughout this workflow
if command -v gh &>/dev/null && gh auth status &>/dev/null; then
AUTH="gh"
else
AUTH="git"
# Ensure we have a token for API calls
if [ -z "$GITHUB_TOKEN" ]; then
if [ -f ~/.hermes/.env ] && grep -q "^GITHUB_TOKEN=" ~/.hermes/.env; then
GITHUB_TOKEN=$(grep "^GITHUB_TOKEN=" ~/.hermes/.env | head -1 | cut -d= -f2 | tr -d '\n\r')
elif grep -q "github.com" ~/.git-credentials 2>/dev/null; then
GITHUB_TOKEN=$(grep "github.com" ~/.git-credentials 2>/dev/null | head -1 | sed 's|https://[^:]*:\([^@]*\)@.*|\1|')
fi
fi
fi
echo "Using: $AUTH"
Extracting Owner/Repo from the Git Remote
Many curl commands need owner/repo. Extract it from the git remote:
# Works for both HTTPS and SSH remote URLs
REMOTE_URL=$(git remote get-url origin)
OWNER_REPO=$(echo "$REMOTE_URL" | sed -E 's|.*github\.com[:/]||; s|\.git$||')
OWNER=$(echo "$OWNER_REPO" | cut -d/ -f1)
REPO=$(echo "$OWNER_REPO" | cut -d/ -f2)
echo "Owner: $OWNER, Repo: $REPO"
1. Branch Creation
This part is pure git — identical either way:
# Make sure you're up to date
git fetch origin
git checkout main && git pull origin main
# Create and switch to a new branch
git checkout -b feat/add-user-authentication
Branch naming conventions:
feat/description— new featuresfix/description— bug fixesrefactor/description— code restructuringdocs/description— documentationci/description— CI/CD changes
2. Making Commits
Use the appropriate implementation mechanism for the repository, then commit. For Aaron's ~/code/ repos, repo file changes should come from the active repo coding workflow (OpenCode when Aaron requested OpenCode, Codex where still specified by current repo/user preference); do not use Hermes file tools for those mutations unless explicitly authorized. For generic/non-Aaron contexts, file tools (write_file, patch) are acceptable.
# Stage specific files
git add src/auth.py src/models/user.py tests/test_auth.py
# Commit with a conventional commit message
git commit -m "feat: add JWT-based user authentication
- Add login/register endpoints
- Add User model with password hashing
- Add auth middleware for protected routes
- Add unit tests for auth flow"
Commit message format (Conventional Commits):
type(scope): short description
Longer explanation if needed. Wrap at 72 characters.
Types: feat, fix, refactor, docs, test, ci, chore, perf
3. Pushing and Creating a PR
Push the Branch (same either way)
git push -u origin HEAD
Pre-PR Rebase Gate
Before opening any PR for Aaron's repos, make sure the branch is rebased onto the latest intended target branch and conflicts are resolved. Do this after final local validation/review fixes and before gh pr create.
git fetch origin <base-branch>
git rebase origin/<base-branch>
git status --short
git merge-base --is-ancestor origin/<base-branch> HEAD
If the rebase introduces conflicts, resolve them through the repo's active implementation workflow (OpenCode/Codex as appropriate), rerun impacted validation and code reviews, refresh visual evidence if user-visible behavior changed, then push. Do not open a PR from a branch that is behind, conflicted, or not proven to contain the latest target branch tip.
If a branch was already pushed before rebase, prefer a normal push when possible. If history was rewritten and the remote branch must be updated, use git push --force-with-lease, never plain --force.
Create the PR
With gh:
gh pr create \
--title "feat: add JWT-based user authentication" \
--body "## Summary
- Adds login and register API endpoints
- JWT token generation and validation
## Test Plan
- [ ] Unit tests pass
Closes #42"
Options: --draft, --reviewer user1,user2, --label "enhancement", --base develop
With git + curl:
BRANCH=$(git branch --show-current)
curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$OWNER/$REPO/pulls \
-d "{
\"title\": \"feat: add JWT-based user authentication\",
\"body\": \"## Summary\nAdds login and register API endpoints.\n\nCloses #42\",
\"head\": \"$BRANCH\",
\"base\": \"main\"
}"
The response JSON includes the PR number — save it for later commands.
To create as a draft, add "draft": true to the JSON body.
4. Monitoring CI Status
Check CI Status
With gh:
# One-shot check
gh pr checks
# Watch until all checks finish (polls every 10s)
gh pr checks --watch
With git + curl:
# Get the latest commit SHA on the current branch
SHA=$(git rev-parse HEAD)
# Query the combined status
curl -s \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/commits/$SHA/status \
| python3 -c "
import sys, json
data = json.load(sys.stdin)
print(f\"Overall: {data['state']}\")
for s in data.get('statuses', []):
print(f\" {s['context']}: {s['state']} - {s.get('description', '')}\")"
# Also check GitHub Actions check runs (separate endpoint)
curl -s \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/commits/$SHA/check-runs \
| python3 -c "
import sys, json
data = json.load(sys.stdin)
for cr in data.get('check_runs', []):
print(f\" {cr['name']}: {cr['status']} / {cr['conclusion'] or 'pending'}\")"
Poll Until Complete (git + curl)
# Simple polling loop — check every 30 seconds, up to 10 minutes
SHA=$(git rev-parse HEAD)
for i in $(seq 1 20); do
STATUS=$(curl -s \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/commits/$SHA/status \
| python3 -c "import sys,json; print(json.load(sys.stdin)['state'])")
echo "Check $i: $STATUS"
if [ "$STATUS" = "success" ] || [ "$STATUS" = "failure" ] || [ "$STATUS" = "error" ]; then
break
fi
sleep 30
done
5. Auto-Fixing CI Failures
When CI fails, diagnose and fix. This loop works with either auth method.
Step 1: Get Failure Details
With gh:
# List recent workflow runs on this branch
gh run list --branch $(git branch --show-current) --limit 5
# View failed logs
gh run view <RUN_ID> --log-failed
With git + curl:
BRANCH=$(git branch --show-current)
# List workflow runs on this branch
curl -s \
-H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$BRANCH&per_page=5" \
| python3 -c "
import sys, json
runs = json.load(sys.stdin)['workflow_runs']
for r in runs:
print(f\"Run {r['id']}: {r['name']} - {r['conclusion'] or r['status']}\")"
# Get failed job logs (download as zip, extract, read)
RUN_ID=<run_id>
curl -s -L \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID/logs \
-o /tmp/ci-logs.zip
cd /tmp && unzip -o ci-logs.zip -d ci-logs && cat ci-logs/*.txt
Step 2: Fix and Push
After identifying the issue, use the appropriate repo implementation mechanism. For Aaron's ~/code/ repos, route fixes through the active repo coding workflow (OpenCode when in OpenCode workflow, Codex when explicitly using Codex) and then verify the resulting diff; for generic contexts, direct file tools (patch, write_file) may be used:
git add <fixed_files>
git commit -m "fix: resolve CI failure in <check_name>"
git push
Step 3: Verify
Re-check CI status using the commands from Section 4 above.
Auto-Fix Loop Pattern
When asked to auto-fix CI, follow this loop:
- Check CI status → identify failures
- Read failure logs → understand the error
- Apply the fix through the active repo implementation workflow for Aaron's
~/code/repos; useread_file+patch/write_fileonly in generic contexts or when Aaron explicitly authorizes direct Hermes edits - Commit and push the focused fix
- Wait for CI → re-check status
- Repeat if still failing (up to 3 attempts, then ask the user)
Retargeting or Rebasing an Existing PR
When a PR review request says it "needs to be rebased onto <base>" or otherwise retargeted before merge, do the mechanical GitHub work before final review:
- Inspect PR metadata and current merge state:
gh pr view <N> --json number,url,baseRefName,headRefName,headRefOid,mergeStateStatus,mergeable,statusCheckRollup - Check out or use the PR branch worktree, then rebase onto the requested base:
git fetch origin <base-branch> git rebase origin/<base-branch> git status --short --branch git merge-base --is-ancestor origin/<base-branch> HEAD - If history changed, update the remote branch with
git push --force-with-lease, never plain--force. - If the PR's GitHub base is still wrong, update it explicitly:
gh pr edit <N> --base <base-branch> - Re-check PR metadata; require
baseRefName=<base-branch>andmergeStateStatus/mergeableto be acceptable before posting review findings. - Rerun read-only review against the new base (
origin/<base-branch>...HEAD) because conflict resolution or base changes can change the effective diff. If no checks are configured, reportno checks reportedas informational rather than CI failure.
For Aaron's macOS setup, if a plain gh/git fetch invocation cannot see GitHub credentials, retry via HOME=/Users/anichols zsh -lc '<command>' before treating auth as unavailable.
Addressing PR Review Feedback
When asked to "check the PR for feedback" and update it:
- Gather all feedback surfaces, not just CI:
gh pr view <N> --json number,url,title,state,reviewDecision,mergeable,headRefName,headRefOid,comments,reviews,statusCheckRollup gh api repos/$OWNER/$REPO/pulls/<N>/comments --paginate gh api repos/$OWNER/$REPO/issues/<N>/comments --paginate gh api repos/$OWNER/$REPO/pulls/<N>/reviews --paginate - For inline review threads, also inspect thread resolution state; REST pull comments do not tell you whether the conversation is resolved:
gh api graphql \
-f owner=$OWNER -f repo=$REPO -F number=<N> \
-f query='query($owner:String!,$repo:String!,$number:Int!){ repository(owner:$owner,name:$repo){ pullRequest(number:$number){ reviewThreads(first:50){ nodes{ id isResolved comments(first:10){ nodes{ databaseId body author{login} } } } } } } }'
For file-based GraphQL queries and thread reply/resolve mutations, see references/pr-review-thread-graphql.md. Important CLI quirk: use -F query=@/path/query.graphql for query files; -f query=@file can send a literal @file and fail with a GraphQL parse error.
For the OpenCode-backed PR feedback loop, including gather → OpenCode remediation artifact → commit/push → reply/resolve → re-query, see references/opencode-pr-feedback-fix-cycle.md.
3. Apply the requested fixes locally on the PR branch; include focused tests for the review point when possible. For Aaron's repos, route code changes through the active implementation workflow (OpenCode/Codex/etc.) rather than direct Hermes edits unless explicitly authorized.
4. Run targeted validation and diff hygiene before committing.
5. Commit and push follow-up fixes.
6. Reply to the inline comment/thread and add a top-level PR comment with what changed and validation evidence.
7. Resolve addressed review threads after verifying the fix and posting the reply:
gh api graphql \
-f threadId=<PRRT_...> \
-f query='mutation($threadId:ID!){ resolveReviewThread(input:{threadId:$threadId}){ thread{ id isResolved } } }'
- Re-check PR metadata/checks after pushing. If no checks are configured, report that explicitly;
gh pr checksmay exit nonzero withno checks reported, which is an informational state rather than a failed check.
6. Merging
With gh:
# Squash merge. Branch deletion belongs to worktree-cleanup: after the merge, run it from outside the branch's worktree (if it has one)
gh pr merge --squash
# Enable auto-merge (merges when all checks pass)
gh pr merge --auto --squash
With git + curl:
PR_NUMBER=<number>
# Merge the PR via API (squash)
curl -s -X PUT \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER/merge \
-d "{
\"merge_method\": \"squash\",
\"commit_title\": \"feat: add user authentication (#$PR_NUMBER)\"
}"
# Leave branch deletion to worktree cleanup. Deleting the branch here can remove
# a checked-out worktree and its lab claim before the lab is released.
# If this branch has a Paseo or aoe worktree and the worktree-cleanup skill is
# installed, run it from outside that worktree after the merge:
# python3 ~/.agents/skills/worktree-cleanup/scripts/worktree_cleanup.py --path <worktree>
git checkout main && git pull origin main
Merge methods: "merge" (merge commit), "squash", "rebase"
Enable Auto-Merge (curl)
# Auto-merge requires the repo to have it enabled in settings.
# This uses the GraphQL API since REST doesn't support auto-merge.
PR_NODE_ID=$(curl -s \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/pulls/$PR_NUMBER \
| python3 -c "import sys,json; print(json.load(sys.stdin)['node_id'])")
curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/graphql \
-d "{\"query\": \"mutation { enablePullRequestAutoMerge(input: {pullRequestId: \\\"$PR_NODE_ID\\\", mergeMethod: SQUASH}) { clientMutationId } }\"}"
7. Complete Workflow Example
# 1. Start from clean main
git checkout main && git pull origin main
# 2. Branch
git checkout -b fix/login-redirect-bug
# 3. (Agent makes code changes with file tools)
# 4. Commit
git add src/auth/login.py tests/test_login.py
git commit -m "fix: correct redirect URL after login
Preserves the ?next= parameter instead of always redirecting to /dashboard."
# 5. Push
git push -u origin HEAD
# 6. Create PR (picks gh or curl based on what's available)
# ... (see Section 3)
# 7. Monitor CI (see Section 4)
# 8. Merge when green (see Section 6)
Useful PR Commands Reference
| Action | gh | git + curl |
|---|---|---|
| List my PRs | gh pr list --author @me |
curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/pulls?state=open" |
| View PR diff | gh pr diff |
git diff main...HEAD (local) or curl -H "Accept: application/vnd.github.diff" ... |
| Add comment | gh pr comment N --body "..." |
curl -X POST .../issues/N/comments -d '{"body":"..."}' |
| Request review | gh pr edit N --add-reviewer user |
curl -X POST .../pulls/N/requested_reviewers -d '{"reviewers":["user"]}' |
| Close PR | gh pr close N |
curl -X PATCH .../pulls/N -d '{"state":"closed"}' |
| Check out someone's PR | gh pr checkout N |
git fetch origin pull/N/head:pr-N && git checkout pr-N |
04 同仓库更多 Skills
网页抓取受阻恢复
blocked-page-recovery
当抓取失败时使用:403/429 状态码、付费墙(paywall)、WAF、机器人验证墙(bot wall)。
软件实施计划编写
writing-plans
在创建或更新可执行的软件计划时使用。除非用户明确要求将计划注册到 Doct,否则请将计划保留为本地文件。
测试驱动开发
test-driven-development
TDD:强制执行「红-绿-重构」(RED-GREEN-REFACTOR)循环,先写测试再写代码。
系统化根因调试
systematic-debugging
四阶段根因调试:先理解缺陷,再着手修复。
技术预研验证
spike
在正式构建前,通过一次性(可丢弃的)实验来验证某个想法。
代码变更并行清理精简
simplify-code
并行使用 3 个智能体(agent)对近期代码变更进行清理精简。