mcpField
P
pr-descriptions

pr-descriptions

github.com/zenobi-us開発6836 回インストール今日更新
リポジトリ

pr-descriptions について

pr-descriptionsは、`gh pr edit`で変更が保存されない場合に、GitHubのプルリクエスト説明を確実に更新するためのスキルです。本文ファイルを先に試し、GitHub REST APIに切り替えて結果を確認する手順を案内します。

主な機能

  1. 01`gh pr edit`の無反応な失敗に対応
  2. 02REST APIを代替手段として利用
  3. 03heredocで複数行テキストを保持
  4. 04更新の保存状態を確認

活用シーン

  1. 01複数行のPR説明を更新
  2. 02保存されない編集を修正
  3. 03複雑なPRテンプレートの書式を維持

インストール

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

$npx skills add https://github.com/zenobi-us/dotfiles --skill pr-descriptions

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

詳細

PR の説明を更新する

概要

一部の GitHub インスタンスや設定では、gh pr edit --body がサイレントに失敗することがあります。コマンドは受け付けられても、変更が保存されません。GitHub REST API を使うと、標準的な CLI ツールが期待どおりに動作しない場合に、信頼性の高い代替手段となります。

使用する場面

  • gh pr edit --body はコマンドを受け付けるものの、変更が保存されない(サイレントな失敗)
  • 複数行のコンテンツで PR の説明をプログラムから更新する必要がある
  • 複雑な PR テンプレートを使用しており、編集内容が反映されない
  • 次に進む前に、確実に変更を保存する必要がある

次の場合は不要です:

  • gh pr edit --body-file で PR が正常に更新される
  • タイトルまたは単純なフィールドだけを更新する

基本パターン

gh pr edit で変更が保存されない場合:

# Step 1: Get current PR details to verify number
gh pr view --json number -q '.number'

# Step 2: Try standard approach first
gh pr edit <PR_NUMBER> --body "$(cat <<'EOF'
[new body content]
EOF
)"

# Step 3: If no error but changes don't persist, use API directly
gh api repos/OWNER/REPO/pulls/<PR_NUMBER> -X PATCH -f body="$(cat <<'EOF'
[new body content]
EOF
)"

パターンの主な要素

<<"EOF" ではなく <<'EOF' を指定してヒアドキュメントを使う

シングルクォートを使うと、シェルによる展開を防げます:

# ✅ Correct - preserves backticks, $variables, special chars
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$(cat <<'EOF'
Contains `backticks` and $special chars
EOF
)"

# ❌ Wrong - shell expands variables before API call
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$(cat <<"EOF"
Contains `backticks` and $special (expands!)
EOF
)"
PR 番号が不明な場合に取得する
# From current branch (if tracking remote PR)
gh pr view --json number -q '.number'
API 呼び出しが成功したことを確認する

返された JSON に本文が含まれていることを確認します:

gh api repos/owner/repo/pulls/123 -X PATCH -f body="new content" | grep -q "new content" && echo "Success"

実装

シンプルな更新
PR_NUMBER=$(gh pr view --json number -q '.number')

gh api repos/Reckon-Limited/reckon-frontend/pulls/$PR_NUMBER -X PATCH -f body="$(cat <<'EOF'
# Summary

This PR implements feature X.

## Features
- Feature A
- Feature B

# Testing

EOF
)"
確認を含む更新
PR_NUMBER=$(gh pr view --json number -q '.number')
NEW_BODY="# Summary

This PR implements employee list actions."

gh api repos/Reckon-Limited/reckon-frontend/pulls/$PR_NUMBER -X PATCH -f body="$NEW_BODY"

# Verify by checking the returned body matches
gh pr view $PR_NUMBER --json body -q '.body' | head -1

よくある間違い

間違い 1:ヒアドキュメントで誤った引用符を使う

# ❌ Wrong - variables expand, breaks formatting
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$(cat <<"EOF"
Variables like $VAR and $(commands) will expand
EOF
)"

# ✅ Correct
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$(cat <<'EOF'
Variables like $VAR and $(commands) stay literal
EOF
)"

間違い 2:成功したと判断する前に戻り値を確認しない

# ❌ Command returns 200 but changes don't persist
gh pr edit 123 --body "new content"  # exits 0, no error

# ✅ Use API and check response
gh api repos/owner/repo/pulls/123 -X PATCH -f body="new content" | grep -q "new content"

間違い 3:中間手順として --body-file を使い忘れる

# ✅ Best practice order:
# 1. Try gh pr edit --body-file (file-based, more reliable than inline)
# 2. If that fails, use gh api (always works)
gh pr edit 123 --body-file my_body.md  # Try this first

間違い 4:特殊文字を含む本文文字列を誤って組み立てる

# ❌ Wrong - newlines lost, special chars cause issues
BODY="# Summary\nNew content"
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$BODY"

# ✅ Correct - use heredoc to preserve formatting
gh api repos/owner/repo/pulls/123 -X PATCH -f body="$(cat <<'EOF'
# Summary

New content
EOF
)"

トラブルシューティング

API 呼び出しで 422 Unprocessable Entity が返される場合:

  • PR 番号が正しいことを確認します:gh pr view --json number
  • リポジトリのパス(OWNER/REPO)を確認します:gh api repos/Reckon-Limited/reckon-frontend --json nameWithOwner
  • 認証を確認します:gh auth status

本文は更新されるものの、エスケープされた改行が含まれていたり、書式に問題があったりする場合:

  • シングルクォートを使ったヒアドキュメントを使用します:<<"EOF" ではなく <<'EOF'
  • 複雑なコンテンツにはインライン文字列を使わず、ヒアドキュメントを使用します

コマンドは成功するものの、gh pr view に古い本文が表示される場合:

  • 少し待ちます(GitHub API の結果整合性による遅延)
  • ローカルキャッシュをクリアします:gh pr view --refresh
  • GitHub のウェブ UI で確認します(ブラウザーのキャッシュが原因の場合があります)

実際の効果

gh pr edit がサイレントに失敗した場合に API を代替手段として使うことで、自動化スクリプトで PR の説明を確実に更新できます。これにより、手作業でのフォローアップを減らし、レビュー担当者向けに正確な PR ドキュメントを提供できます。

コメント