ci: PRコメント /resolve でコンフリクト解決・レビュー指摘修正を行うワークフローを追加
This commit is contained in:
parent
252c337456
commit
09fda82677
228
.github/workflows/cc-resolve.yml
vendored
Normal file
228
.github/workflows/cc-resolve.yml
vendored
Normal file
@ -0,0 +1,228 @@
|
||||
name: CC Resolve
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
resolve:
|
||||
# Uncomment to allow organization members or collaborators:
|
||||
# || github.event.comment.author_association == 'MEMBER'
|
||||
# || github.event.comment.author_association == 'COLLABORATOR'
|
||||
if: |
|
||||
github.event.issue.pull_request &&
|
||||
contains(github.event.comment.body, '/resolve') &&
|
||||
github.event.comment.author_association == 'OWNER'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Acknowledge
|
||||
run: |
|
||||
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \
|
||||
-f content=rocket
|
||||
gh pr comment ${{ github.event.issue.number }} \
|
||||
--body "🚀 cc-resolve started: [View logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get PR branch
|
||||
id: pr
|
||||
run: |
|
||||
echo "branch=$(gh pr view ${{ github.event.issue.number }} --json headRefName -q .headRefName)" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.pr.outputs.branch }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Merge main (detect conflicts)
|
||||
id: merge
|
||||
run: |
|
||||
git fetch origin main
|
||||
if git merge origin/main --no-edit 2>/dev/null; then
|
||||
echo "conflicts=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "conflicts=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Collect PR review comments
|
||||
id: reviews
|
||||
run: |
|
||||
PR_NUMBER=${{ github.event.issue.number }}
|
||||
COMMENTS=$(gh pr view "$PR_NUMBER" --json comments -q '.comments[].body' 2>/dev/null || echo "")
|
||||
REVIEWS=$(gh api "repos/${{ github.repository }}/pulls/${PR_NUMBER}/reviews" --jq '.[].body' 2>/dev/null || echo "")
|
||||
REVIEW_COMMENTS=$(gh api "repos/${{ github.repository }}/pulls/${PR_NUMBER}/comments" --jq '.[] | "**\(.path):\(.line // .original_line)** \(.body)"' 2>/dev/null || echo "")
|
||||
|
||||
{
|
||||
echo "review_context<<REVIEW_EOF"
|
||||
if [ -n "$REVIEWS" ]; then
|
||||
echo "## PR Reviews"
|
||||
echo "$REVIEWS"
|
||||
fi
|
||||
if [ -n "$REVIEW_COMMENTS" ]; then
|
||||
echo "## PR Review Comments (inline)"
|
||||
echo "$REVIEW_COMMENTS"
|
||||
fi
|
||||
if [ -n "$COMMENTS" ]; then
|
||||
echo "## PR Comments"
|
||||
echo "$COMMENTS"
|
||||
fi
|
||||
echo "REVIEW_EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install Claude Code
|
||||
run: npm install -g @anthropic-ai/claude-code
|
||||
|
||||
- name: Resolve
|
||||
run: |
|
||||
claude -p "$(cat <<'PROMPT'
|
||||
このPRのコンフリクトおよびレビュー指摘を解決してください。
|
||||
|
||||
原則: 差分を読み、疑い、判断根拠を書いてから解決する。妄信的に片方を採用しない。
|
||||
|
||||
---
|
||||
|
||||
## 状況判定
|
||||
|
||||
まず現在の状態を確認してください。
|
||||
|
||||
1. `git status` でコンフリクトの有無を確認
|
||||
2. コンフリクトがあれば「コンフリクト解決モード」
|
||||
3. コンフリクトがなければ「レビュー指摘対応モード」
|
||||
4. 両方あれば、コンフリクト解決を先に行い、その後レビュー指摘に対応
|
||||
|
||||
---
|
||||
|
||||
## コンフリクト解決モード
|
||||
|
||||
### 1. コンテキストを把握する
|
||||
|
||||
並列で実行:
|
||||
- `git log --oneline HEAD -5` で HEAD 側の最近の変更を確認
|
||||
- `git log --oneline MERGE_HEAD -5` で取り込み側の最近の変更を確認
|
||||
- 両ブランチの関係性を理解する
|
||||
|
||||
### 2. コンフリクトファイルを列挙する
|
||||
|
||||
```bash
|
||||
git diff --name-only --diff-filter=U
|
||||
```
|
||||
|
||||
### 3. 各ファイルを分析する(核心)
|
||||
|
||||
ファイルごとに以下を必ず実行する。省略しない。
|
||||
|
||||
1. ファイル全体を読む(コンフリクトマーカー付きの状態)
|
||||
2. 各コンフリクトブロック(`<<<<<<<` 〜 `>>>>>>>`)について:
|
||||
- HEAD 側の内容を具体的に読む
|
||||
- theirs 側の内容を具体的に読む
|
||||
- 差分が何を意味するか分析する
|
||||
- 判断に迷う場合は `git log --oneline -- {file}` で変更履歴を確認
|
||||
3. 判断を書く:
|
||||
- HEAD 側: {具体的な内容}
|
||||
- theirs 側: {具体的な内容}
|
||||
- 分析: {差分の意味}
|
||||
- 判断: {HEAD / theirs / 両方統合} を採用({理由})
|
||||
|
||||
疑うべきポイント:
|
||||
- 「〇〇側が新しいから」だけで判断していないか?
|
||||
- theirs を採用すると、HEAD 側の作業が消えないか?
|
||||
- 両方の変更を統合すべきケースではないか?
|
||||
|
||||
### 4. 解決を実施する
|
||||
|
||||
- 片方採用が明確: `git checkout --ours {file}` / `git checkout --theirs {file}`(分析済みファイルのみ)
|
||||
- 統合が必要: コンフリクトマーカーを除去し両方を結合
|
||||
- 解決したファイルを `git add {file}`
|
||||
- `<<<<<<<` マーカーの取り残しがないか確認
|
||||
|
||||
---
|
||||
|
||||
## レビュー指摘対応モード
|
||||
|
||||
### 1. レビューコメントを分析する
|
||||
|
||||
各指摘について:
|
||||
- 指摘箇所のコードを実際に読む
|
||||
- 指摘の意図を理解する
|
||||
- 現状コードの問題点を分析する
|
||||
|
||||
### 2. 各指摘に対して判断する
|
||||
|
||||
- 修正: 指摘が妥当 → コードを修正
|
||||
- 部分修正: 一部妥当 → 妥当な部分のみ修正
|
||||
- 反論: 指摘が不適切 → 理由を明記してスキップ
|
||||
|
||||
判断根拠を必ず記録する。
|
||||
|
||||
### 3. 修正を実施する
|
||||
|
||||
指摘ごとにコードを修正し、修正内容を記録する。
|
||||
|
||||
---
|
||||
|
||||
## 波及影響確認(両モード共通)
|
||||
|
||||
- ビルド確認(`npm run build` 等)
|
||||
- テスト確認(`npm test` 等)
|
||||
- 修正対象外ファイルとの矛盾がないか確認
|
||||
|
||||
問題が見つかった場合はここで修正する。
|
||||
|
||||
---
|
||||
|
||||
## 絶対原則
|
||||
|
||||
- 差分を読まずに解決しない
|
||||
- 「〇〇優先」を盲従しない
|
||||
- 判断根拠を省略しない(何が・なぜ・どちらを)
|
||||
- 波及を確認する
|
||||
|
||||
## 禁止事項
|
||||
|
||||
- 分析なしで `git checkout --ours .` / `git checkout --theirs .` を実行しない
|
||||
- 全ファイルを一括解決しない
|
||||
- コンフリクトマーカーを残さない
|
||||
- `git merge --abort` を実行しない
|
||||
PROMPT
|
||||
)" --verbose
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
git add -A
|
||||
if ! git diff --cached --quiet; then
|
||||
git commit -m "fix: resolve conflicts and review comments"
|
||||
git push
|
||||
else
|
||||
echo "No changes to commit"
|
||||
fi
|
||||
|
||||
- name: Report result
|
||||
if: always()
|
||||
run: |
|
||||
PR_NUMBER=${{ github.event.issue.number }}
|
||||
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
if [ "${{ job.status }}" = "success" ]; then
|
||||
gh pr comment "$PR_NUMBER" --body "✅ cc-resolve completed. [View logs](${RUN_URL})"
|
||||
else
|
||||
gh pr comment "$PR_NUMBER" --body "❌ cc-resolve failed. [View logs](${RUN_URL})"
|
||||
fi
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
Loading…
x
Reference in New Issue
Block a user