mcpField
G
github-pr-workflow

github-pr-workflow

github.com/nousresearch開発258.1k331 回インストール今日更新
リポジトリ

github-pr-workflow について

コーディングエージェント向けに、ブランチ作成やコミットから CI の確認・修正、マージまで、GitHub のプルリクエストの流れを案内するスキルです。`gh` と、代替手段の `git` と `curl` の両方を説明します。

主な機能

  1. 01ブランチと規約に沿ったコミットの作成
  2. 02プルリクエストの作成と管理
  3. 03CI チェックとログの監視
  4. 04CI 失敗の診断と修正
  5. 05複数の方式によるマージ

活用シーン

  1. 01機能ブランチの PR の準備と提出
  2. 02失敗した CI チェックの調査と修正
  3. 03オープン中の PR の確認、更新、マージ

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/nousresearch/hermes-agent --skill github-pr-workflow

インストール後、Claude Code で/github-pr-workflowを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
ci-troubleshooting.md
conventional-commits.md
templates/
pr-body-bugfix.md
pr-body-feature.md

詳細

GitHub Pull Request ワークフロー

PR のライフサイクルを管理するための完全ガイドです。各セクションでは、まず gh を使う方法を紹介し、次に gh がインストールされていないマシン向けの git + curl による代替方法を紹介します。

前提条件

  • GitHub で認証済みであること(github-auth スキルを参照)
  • GitHub のリモートが設定された git リポジトリ内にいること
認証状態をすばやく確認する
# 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 _hermes_env="${HERMES_HOME:-$HOME/.hermes}/.env"; [ -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=$(uv run python "${HERMES_HOME:-$HOME/.hermes}/skills/github/github-auth/scripts/git-credential-token.py")
    fi
  fi
fi
echo "Using: $AUTH"
Git リモートから Owner/Repo を抽出する

多くの curl コマンドでは owner/repo が必要です。git リモートから抽出します。

# 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. ブランチの作成

ここでは git のみを使用します。どちらの方法でも同じです。

# 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

ブランチの命名規則:

  • feat/description — 新機能
  • fix/description — バグ修正
  • refactor/description — コードの再構成
  • docs/description — ドキュメント
  • ci/description — CI/CD の変更

2. コミットの作成

エージェントのファイルツール(write_file、patch)を使って変更を加え、コミットします。

# 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"

コミットメッセージの形式(Conventional Commits):

type(scope): short description

Longer explanation if needed. Wrap at 72 characters.

種類:feat、fix、refactor、docs、test、ci、chore、perf

3. プッシュして PR を作成する

ブランチをプッシュする(どちらの方法でも同じ)
git push -u origin HEAD
PR を作成する

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"

オプション:--draft、--reviewer user1,user2、--label "enhancement"、--base develop

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\"
  }"

レスポンス JSON には PR の number が含まれています。後続のコマンドで使うため、保存しておいてください。

ドラフトとして作成するには、JSON ボディに "draft": true を追加します。

4. CI ステータスの監視

CI ステータスを確認する

gh を使用する場合:

# One-shot check
gh pr checks

# Watch until all checks finish (polls every 10s)
gh pr checks --watch

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 \
  | python -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 \
  | python -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'}\")"
完了するまでポーリングする(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 \
    | python -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. CI の失敗を自動修正する

CI が失敗したら、原因を診断して修正します。このループはどちらの認証方法でも使用できます。

ステップ 1:失敗の詳細を取得する

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

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" \
  | python -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
ステップ 2:修正してプッシュする

問題を特定したら、ファイルツール(patch、write_file)を使って修正します。

git add <fixed_files>
git commit -m "fix: resolve CI failure in <check_name>"
git push
ステップ 3:確認する

上記のセクション 4 のコマンドを使って、CI ステータスを再確認します。

自動修正ループのパターン

CI の自動修正を依頼された場合は、次のループに従います。

  1. CI ステータスを確認 → 失敗を特定する
  2. 失敗ログを読む → エラーを把握する
  3. read_file + patch/write_file を使う → コードを修正する
  4. git add . && git commit -m "fix: ..." && git push
  5. CI を待つ → ステータスを再確認する
  6. まだ失敗している場合は繰り返す(最大 3 回まで。それ以降はユーザーに確認する)

6. マージ

gh を使用する場合:

# Squash merge + delete branch (cleanest for feature branches)
gh pr merge --squash --delete-branch

# Enable auto-merge (merges when all checks pass)
gh pr merge --auto --squash --delete-branch

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)\"
  }"

# Delete the remote branch after merge
BRANCH=$(git branch --show-current)
git push origin --delete $BRANCH

# Switch back to main locally
git checkout main && git pull origin main
git branch -d $BRANCH

マージ方法:"merge"(マージコミット)、"squash"、"rebase"

オートマージを有効にする(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 \
  | python -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. ワークフロー全体の例

# 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)

便利な PR コマンド一覧

操作ghgit + curl
自分の PR を一覧表示するgh pr list --author @mecurl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$OWNER/$REPO/pulls?state=open"
PR の差分を表示するgh pr diffgit diff main...HEAD(ローカル)または curl -H "Accept: application/vnd.github.diff" ...
コメントを追加するgh pr comment N --body "..."curl -X POST .../issues/N/comments -d '{"body":"..."}'
レビューを依頼するgh pr edit N --add-reviewer usercurl -X POST .../pulls/N/requested_reviewers -d '{"reviewers":["user"]}'
PR をクローズするgh pr close Ncurl -X PATCH .../pulls/N -d '{"state":"closed"}'
他の人の PR をチェックアウトするgh pr checkout Ngit fetch origin pull/N/head:pr-N && git checkout pr-N

コメント