@torka/claude-workflows 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/github-pr-resolve.md +225 -467
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: '
|
|
2
|
+
description: 'Autonomously process, fix, and merge all open PRs with minimal user interaction'
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
IT IS CRITICAL THAT YOU FOLLOW THIS WORKFLOW EXACTLY.
|
|
@@ -16,569 +16,327 @@ Before any operations, verify the environment is safe:
|
|
|
16
16
|
|
|
17
17
|
3. **Detect default branch**: Run `gh repo view --json defaultBranchRef -q .defaultBranchRef.name`. Fallback to `main` if this fails.
|
|
18
18
|
|
|
19
|
-
4. **
|
|
19
|
+
4. **Detect repository merge strategy**:
|
|
20
|
+
- Run: `gh repo view --json squashMergeAllowed,mergeCommitAllowed,rebaseMergeAllowed`
|
|
21
|
+
- Determine preferred strategy in order: squash > merge > rebase
|
|
22
|
+
- Store for use in Phase 4 merge commands
|
|
23
|
+
- Default to `--squash` if detection fails
|
|
24
|
+
|
|
25
|
+
5. **Record current branch and worktree**:
|
|
20
26
|
- Run `git branch --show-current` to get current branch name
|
|
21
27
|
- **If empty (detached HEAD)**: Run `git rev-parse HEAD` to save the commit SHA instead
|
|
22
28
|
- Run `git rev-parse --show-toplevel` to record the current worktree path
|
|
23
|
-
- Track whether we started in detached HEAD state for Phase 5 restoration
|
|
24
|
-
|
|
25
|
-
5. **Build worktree inventory**: Run `git worktree list --porcelain` to detect all worktrees.
|
|
26
|
-
- Parse the output to build a map: `{ branch_name -> worktree_path }`
|
|
27
|
-
- For each branch, record if it's checked out in a worktree and where
|
|
28
29
|
|
|
29
|
-
6. **
|
|
30
|
-
- If output is non-empty, offer handling options:
|
|
31
|
-
```
|
|
32
|
-
You have uncommitted changes in your working directory.
|
|
30
|
+
6. **Build worktree inventory**: Run `git worktree list --porcelain` to detect all worktrees.
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
2. Proceed carefully (I'll warn before any checkout operation)
|
|
37
|
-
3. Let me commit/stash manually first (pause workflow)
|
|
38
|
-
```
|
|
39
|
-
- If stash chosen: Run `git stash push -m "github-pr-resolve: auto-stash"` and track `stash_used = true`
|
|
40
|
-
- Track stash state for restoration in Phase 5
|
|
32
|
+
7. **Check for uncommitted changes**: Run `git status --porcelain`.
|
|
33
|
+
- If output is non-empty, WARN the user but continue
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
- The todo list provides visibility to the user and keeps the workflow on track
|
|
35
|
+
8. **Initialize tracking**:
|
|
36
|
+
- Create counters: merged=0, skipped=0, failed=0, auto_fixed=0
|
|
37
|
+
- Create lists: merged_prs[], skipped_prs[], failed_prs[]
|
|
46
38
|
|
|
47
39
|
If gh authentication fails, STOP and clearly explain what the user needs to do.
|
|
48
40
|
|
|
49
41
|
---
|
|
50
42
|
|
|
51
|
-
## Phase 1: PR Discovery &
|
|
52
|
-
|
|
53
|
-
Gather comprehensive information about all open PRs:
|
|
43
|
+
## Phase 1: PR Discovery & Batch Planning
|
|
54
44
|
|
|
55
|
-
|
|
45
|
+
**Goal**: Assess all PRs and start batch processing immediately.
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
1. **Fetch all open PRs**:
|
|
48
|
+
```bash
|
|
49
|
+
gh pr list --state open --json number,title,headRefName,baseRefName,statusCheckRollup,reviewDecision,isDraft,url,author,mergeStateStatus,mergeable,state
|
|
50
|
+
```
|
|
61
51
|
|
|
62
|
-
|
|
52
|
+
2. **For each PR, categorize**:
|
|
63
53
|
|
|
64
|
-
| Category |
|
|
65
|
-
|
|
66
|
-
| Ready to Merge | CI passed,
|
|
67
|
-
|
|
|
68
|
-
| CI
|
|
69
|
-
| CI Failed |
|
|
70
|
-
|
|
|
71
|
-
| Conflicts |
|
|
54
|
+
| Category | Detection | Auto-Action |
|
|
55
|
+
|----------|-----------|-------------|
|
|
56
|
+
| Ready to Merge | CI passed, mergeable=true | Merge immediately |
|
|
57
|
+
| CI Pending | statusCheckRollup has IN_PROGRESS | Wait and poll |
|
|
58
|
+
| CI Failed - Lint | Failed with lint/format errors | Auto-fix |
|
|
59
|
+
| CI Failed - Other | Tests/types/build failed | Skip with log |
|
|
60
|
+
| Behind Main | mergeStateStatus=BEHIND | Update branch, wait for CI |
|
|
61
|
+
| Conflicts | mergeable=CONFLICTING | Skip, warn user |
|
|
62
|
+
| Draft | isDraft=true | Skip |
|
|
63
|
+
| Already Merged | state=MERGED | Log and skip |
|
|
72
64
|
|
|
73
|
-
|
|
65
|
+
3. **Present summary** (informational only, no blocking):
|
|
74
66
|
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
| # | Title |
|
|
78
|
-
|
|
79
|
-
| 42 |
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
67
|
+
Processing X open PRs...
|
|
68
|
+
|
|
69
|
+
| # | Title | Author | Status | Action |
|
|
70
|
+
|---|-------|--------|--------|--------|
|
|
71
|
+
| 42 | bump cross-env | dependabot | CI Passed | Will merge |
|
|
72
|
+
| 35 | bump sharp | dependabot | CI Pending | Will wait |
|
|
73
|
+
| 32 | bump linting | dependabot | CI Failed | Will auto-fix |
|
|
74
|
+
| 28 | new feature | user | Draft | Will skip |
|
|
75
|
+
| 25 | refactor auth | user | Conflicts | Will skip |
|
|
83
76
|
```
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## Phase 2: Review Comments Handling
|
|
93
|
-
|
|
94
|
-
For each PR with pending reviews or requested changes:
|
|
78
|
+
4. **Check for blockers** - ONLY pause if:
|
|
79
|
+
- There are PRs with merge conflicts (warn user which ones will be skipped)
|
|
80
|
+
- There are draft PRs (inform user they will be skipped)
|
|
81
|
+
- All PRs have non-auto-fixable failures
|
|
95
82
|
|
|
96
|
-
|
|
83
|
+
Otherwise, proceed automatically.
|
|
97
84
|
|
|
98
|
-
|
|
85
|
+
5. **Sort PRs by priority**:
|
|
86
|
+
1. Infrastructure PRs first (CI/workflow changes)
|
|
87
|
+
2. PRs with passing CI
|
|
88
|
+
3. PRs with pending CI
|
|
89
|
+
4. PRs needing fixes
|
|
99
90
|
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
gh pr view <number> --json reviews,reviewDecision
|
|
103
|
-
```
|
|
91
|
+
---
|
|
104
92
|
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
gh pr view <number> --json comments
|
|
108
|
-
```
|
|
93
|
+
## Phase 2: Review Comments Handling
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
gh api repos/{owner}/{repo}/pulls/{number}/comments
|
|
113
|
-
```
|
|
114
|
-
This returns comments attached to specific lines of code. These are the most actionable!
|
|
95
|
+
**Note**: This phase only runs if PRs have pending review comments. For batch processing of simple dependency bumps, this phase is typically skipped.
|
|
115
96
|
|
|
116
|
-
|
|
117
|
-
You MUST call the `/pulls/{number}/comments` API endpoint separately.
|
|
97
|
+
For PRs with `reviewDecision: CHANGES_REQUESTED`:
|
|
118
98
|
|
|
119
|
-
|
|
120
|
-
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
- Whether it's resolved/outdated
|
|
124
|
-
- Creation timestamp
|
|
99
|
+
1. Fetch review comments
|
|
100
|
+
2. If all comments are trivial (typos, formatting, docstrings) - auto-fix
|
|
101
|
+
3. If comments require logic changes - skip PR and inform user
|
|
102
|
+
4. Push fixes without asking for confirmation
|
|
125
103
|
|
|
126
|
-
|
|
104
|
+
---
|
|
127
105
|
|
|
128
|
-
|
|
106
|
+
## Phase 3: CI Loop (Autonomous)
|
|
129
107
|
|
|
130
|
-
**
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
134
|
-
- `dependabot[bot]`
|
|
135
|
-
- `renovate[bot]`
|
|
136
|
-
- `sonarcloud[bot]`
|
|
108
|
+
**Configuration:**
|
|
109
|
+
- Polling interval: 30 seconds
|
|
110
|
+
- Max wait per PR: 10 minutes
|
|
111
|
+
- Max fix attempts: 2 per PR
|
|
137
112
|
|
|
138
|
-
**
|
|
139
|
-
- Bot comments are often MORE actionable than they appear (security suggestions, code quality)
|
|
140
|
-
- ALWAYS expand/check bot comments even if they seem informational
|
|
141
|
-
- Display bot comments separately in the summary
|
|
113
|
+
**For each PR, process in a loop:**
|
|
142
114
|
|
|
143
|
-
### Step
|
|
115
|
+
### Step 1: Check Current State
|
|
116
|
+
```bash
|
|
117
|
+
gh pr view <number> --json state,statusCheckRollup,mergeStateStatus,mergeable
|
|
118
|
+
```
|
|
144
119
|
|
|
145
|
-
|
|
120
|
+
- If `state=MERGED`: Log `[X/N] PR #<number> - Already merged`, continue to next
|
|
121
|
+
- If `state=CLOSED`: Log and skip
|
|
146
122
|
|
|
147
|
-
|
|
148
|
-
|----------|-------------------|----------|
|
|
149
|
-
| Add comment/docstring | Yes | "Please add a comment explaining this", "Add JSDoc" |
|
|
150
|
-
| Rename variable/function | Yes | "Rename `x` to `count`", "Use more descriptive name" |
|
|
151
|
-
| Add type annotation | Yes | "Add type for this parameter" |
|
|
152
|
-
| Fix typo | Yes | "Typo: 'recieve' -> 'receive'" |
|
|
153
|
-
| Logic change | No - guided | "This should handle the null case" |
|
|
154
|
-
| Refactor request | No - guided | "Extract this into a separate function" |
|
|
155
|
-
| Question/clarification | No - guided | "Why is this needed?" |
|
|
156
|
-
| Approval/praise | Skip | "LGTM", "Nice work" |
|
|
123
|
+
### Step 2: Handle Branch Behind Main
|
|
157
124
|
|
|
158
|
-
|
|
125
|
+
If `mergeStateStatus=BEHIND`:
|
|
126
|
+
```
|
|
127
|
+
-> Updating branch to latest main...
|
|
128
|
+
```
|
|
129
|
+
```bash
|
|
130
|
+
gh api repos/{owner}/{repo}/pulls/{number}/update-branch -X PUT
|
|
131
|
+
```
|
|
132
|
+
Then wait 30s and re-check CI.
|
|
159
133
|
|
|
160
|
-
|
|
134
|
+
### Step 3: Wait for CI
|
|
161
135
|
|
|
136
|
+
While CI is pending and elapsed < 10 minutes:
|
|
162
137
|
```
|
|
163
|
-
|
|
164
|
-
Review status: Changes Requested
|
|
165
|
-
Reviewer: @reviewer-name
|
|
166
|
-
|
|
167
|
-
Comments: 5 total
|
|
168
|
-
- 3 auto-addressable (add docstring, rename var, fix typo)
|
|
169
|
-
- 2 need guidance (logic change, refactor request)
|
|
170
|
-
|
|
171
|
-
Options:
|
|
172
|
-
1. Auto-address 3 simple comments (Recommended)
|
|
173
|
-
2. Guide me through all 5 comments
|
|
174
|
-
3. View all comments first
|
|
175
|
-
4. Skip this PR
|
|
138
|
+
-> Waiting for CI... (Xs)
|
|
176
139
|
```
|
|
140
|
+
- Sleep 30 seconds
|
|
141
|
+
- Re-check status
|
|
177
142
|
|
|
178
|
-
### Step 4:
|
|
179
|
-
|
|
180
|
-
If user chooses auto-address:
|
|
181
|
-
|
|
182
|
-
1. **Checkout the PR branch** (if not already):
|
|
183
|
-
- Check if branch is in a worktree - if so, operate there with `git -C`
|
|
184
|
-
- Otherwise: `git checkout <branch>`
|
|
185
|
-
|
|
186
|
-
2. **For each auto-addressable comment**:
|
|
187
|
-
- Read the file at the specified path
|
|
188
|
-
- Identify the exact location (line number from review comment)
|
|
189
|
-
- Make the change based on the comment type:
|
|
190
|
-
- **Add comment/docstring**: Generate appropriate documentation
|
|
191
|
-
- **Rename**: Use find/replace for the identifier
|
|
192
|
-
- **Add type annotation**: Infer or use suggested type
|
|
193
|
-
- **Fix typo**: Apply the correction
|
|
194
|
-
- Show diff to user: "Change X to Y in file.ts:42"
|
|
195
|
-
- Ask: "Apply this change?" / "Skip" / "Edit manually"
|
|
196
|
-
|
|
197
|
-
3. **After all accepted changes**:
|
|
198
|
-
- Show consolidated diff
|
|
199
|
-
- Ask for confirmation before committing
|
|
200
|
-
- **Stage ONLY modified files explicitly** (NEVER use `git add .` or `git commit -a`):
|
|
201
|
-
```bash
|
|
202
|
-
git add <file1> <file2> ... # Only files that were actually modified
|
|
203
|
-
```
|
|
204
|
-
- Verify staging is correct: `git status --short`
|
|
205
|
-
- If unexpected files are staged, warn user and ask how to proceed
|
|
206
|
-
- Commit: `git commit -m "fix: address review comments"`
|
|
207
|
-
- **Check upstream tracking before push**:
|
|
208
|
-
```bash
|
|
209
|
-
# If no upstream set, use -u flag
|
|
210
|
-
git rev-parse --abbrev-ref --symbolic-full-name @{upstream} 2>/dev/null || git push -u origin <branch>
|
|
211
|
-
# Otherwise just push
|
|
212
|
-
git push
|
|
213
|
-
```
|
|
143
|
+
### Step 4: Handle CI Results
|
|
214
144
|
|
|
215
|
-
|
|
145
|
+
**If CI passes**: Proceed to Phase 4 (merge)
|
|
146
|
+
|
|
147
|
+
**If CI fails**:
|
|
148
|
+
1. Get failure logs:
|
|
149
|
+
```bash
|
|
150
|
+
gh run list --branch <branch> --status failure --limit 1 --json databaseId -q '.[0].databaseId'
|
|
151
|
+
gh run view <id> --log-failed 2>&1 | head -100
|
|
152
|
+
```
|
|
216
153
|
|
|
217
|
-
|
|
154
|
+
2. Analyze failure type:
|
|
218
155
|
|
|
219
|
-
|
|
220
|
-
1. Display the comment with full context:
|
|
156
|
+
**Lint/Formatting errors** (auto-fixable):
|
|
221
157
|
```
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
Reviewer: @reviewer-name
|
|
225
|
-
Comment: "This should handle the null case - what happens if user is undefined?"
|
|
226
|
-
|
|
227
|
-
Current code:
|
|
228
|
-
40 | const user = getUser(id);
|
|
229
|
-
41 | return user.name; // <- reviewer's concern
|
|
230
|
-
42 | }
|
|
158
|
+
X CI failed (lint errors)
|
|
159
|
+
-> Auto-fixing lint errors...
|
|
231
160
|
```
|
|
161
|
+
- Checkout branch (handle worktree)
|
|
162
|
+
- Run `npm install && npm run lint -- --fix`
|
|
163
|
+
- If changes exist:
|
|
164
|
+
```bash
|
|
165
|
+
git add -A
|
|
166
|
+
git commit -m "fix: auto-fix lint errors"
|
|
167
|
+
git push
|
|
168
|
+
```
|
|
169
|
+
- Wait for CI to re-run
|
|
170
|
+
- Decrement retry counter
|
|
171
|
+
- If this is the 2nd consecutive failure with same error: skip PR
|
|
232
172
|
|
|
233
|
-
|
|
173
|
+
**Type errors / Test failures / Build errors** (NOT auto-fixable):
|
|
234
174
|
```
|
|
235
|
-
|
|
236
|
-
1. Show me the file (I'll make the fix)
|
|
237
|
-
2. Suggest a fix (Claude will propose code)
|
|
238
|
-
3. Mark as resolved with reply
|
|
239
|
-
4. Skip for now
|
|
175
|
+
X CI failed (type errors) - skipping
|
|
240
176
|
```
|
|
177
|
+
- Add to skipped_prs with reason
|
|
178
|
+
- Continue to next PR immediately
|
|
241
179
|
|
|
242
|
-
|
|
243
|
-
-
|
|
244
|
-
-
|
|
245
|
-
- Show diff and ask for confirmation
|
|
246
|
-
- Apply if accepted
|
|
247
|
-
|
|
248
|
-
4. **If "Mark as resolved with reply"**:
|
|
249
|
-
- Ask user for reply text
|
|
250
|
-
- Post reply: `gh api repos/{owner}/{repo}/pulls/{number}/comments/{comment_id}/replies -f body="<reply>"`
|
|
251
|
-
|
|
252
|
-
### Step 6: Post-comment handling
|
|
253
|
-
|
|
254
|
-
After addressing comments:
|
|
255
|
-
- Ask: "Re-request review from @reviewer?" / "Mark ready for review?" / "Leave as-is"
|
|
256
|
-
- If re-request: `gh pr ready <number>` (if was draft) or comment @-mentioning reviewer
|
|
257
|
-
|
|
258
|
-
### Safety Guardrails
|
|
259
|
-
|
|
260
|
-
- NEVER auto-address comments that involve logic changes
|
|
261
|
-
- ALWAYS show diff before committing auto-addressed changes
|
|
262
|
-
- ALWAYS confirm before pushing
|
|
263
|
-
- Track which comments were addressed vs skipped for summary
|
|
264
|
-
- NEVER modify code that the comment doesn't directly reference
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
|
-
## Phase 3: CI Loop
|
|
269
|
-
|
|
270
|
-
For each open PR that needs CI verification:
|
|
271
|
-
|
|
272
|
-
**Configuration:**
|
|
273
|
-
- Max 3 fix attempts per PR
|
|
274
|
-
- Max 5 minute wait per CI run
|
|
275
|
-
- 30 second polling interval
|
|
276
|
-
|
|
277
|
-
### CI Wait Strategy
|
|
180
|
+
**Secrets unavailable** (Dependabot):
|
|
181
|
+
- Try updating branch first (may get new CI workflow)
|
|
182
|
+
- If still fails after update: skip with note
|
|
278
183
|
|
|
279
|
-
|
|
184
|
+
### Step 5: Timeout Handling
|
|
280
185
|
|
|
186
|
+
If 10 minutes elapsed and CI still pending:
|
|
281
187
|
```
|
|
282
|
-
|
|
283
|
-
- PR #39: CI running (2 min elapsed)
|
|
284
|
-
- PR #40: CI running (1 min elapsed)
|
|
285
|
-
- PR #41: CI running (just started)
|
|
286
|
-
|
|
287
|
-
Options:
|
|
288
|
-
1. Wait for all CIs before proceeding (slower but complete)
|
|
289
|
-
2. Process PRs as their CI completes (faster, may revisit)
|
|
290
|
-
3. Only process PRs with CI already complete
|
|
291
|
-
4. Check back in X minutes (pause workflow)
|
|
188
|
+
! CI timed out after 10 minutes - skipping
|
|
292
189
|
```
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
- "Wait for this PR's CI before continuing"
|
|
296
|
-
- "Continue with other ready PRs, check back later"
|
|
297
|
-
- "This PR is a prerequisite - wait for it, then re-check dependent PRs"
|
|
298
|
-
|
|
299
|
-
**Process:**
|
|
300
|
-
|
|
301
|
-
1. **Check CI status**: `gh pr view <pr-number> --json statusCheckRollup`
|
|
302
|
-
|
|
303
|
-
2. **If CI is running**:
|
|
304
|
-
- Display: "Waiting for CI on PR #<number>... (attempt X/3, Xs elapsed)"
|
|
305
|
-
- Wait 30 seconds
|
|
306
|
-
- Re-check (up to 5 minutes total)
|
|
307
|
-
|
|
308
|
-
3. **If CI passes**: Mark PR as ready for merge, proceed to Phase 4
|
|
309
|
-
|
|
310
|
-
4. **If CI fails**:
|
|
311
|
-
- Fetch and display the failure output
|
|
312
|
-
- Categorize the failure:
|
|
313
|
-
- **Lint/Formatting errors**: Offer to run `npm run lint -- --fix` automatically
|
|
314
|
-
- **Type errors**: Show errors, ask user: "Skip this PR", "I'll fix manually"
|
|
315
|
-
- **Test failures**: Show test output, ask user: "Skip this PR", "I'll fix manually"
|
|
316
|
-
- **Build errors**: Show error, ask user: "Skip this PR", "I'll fix manually"
|
|
317
|
-
- If auto-fix chosen (lint only):
|
|
318
|
-
- Checkout branch (handle worktree if needed)
|
|
319
|
-
- Run the fix command
|
|
320
|
-
- Show the diff to user
|
|
321
|
-
- Ask for confirmation before committing
|
|
322
|
-
- **Stage ONLY files that were actually fixed** (use explicit paths, never `git add .`)
|
|
323
|
-
- Commit with message: "fix: auto-fix lint errors"
|
|
324
|
-
- **Check upstream tracking before push** (use `-u` flag if needed)
|
|
325
|
-
- Push and decrement retry counter
|
|
326
|
-
- If manual fix chosen:
|
|
327
|
-
- Inform user and pause for this PR
|
|
328
|
-
- Ask: "Continue with other PRs?" or "Wait for manual fix?"
|
|
329
|
-
|
|
330
|
-
5. **If max retries exceeded**:
|
|
331
|
-
- Ask user: "Skip this PR", "Abort workflow", or "I'll fix manually"
|
|
332
|
-
- Handle accordingly
|
|
333
|
-
|
|
334
|
-
**IMPORTANT**: NEVER auto-fix test failures or type errors. Only lint/formatting issues are safe to auto-fix.
|
|
190
|
+
- Add to skipped_prs
|
|
191
|
+
- Continue to next PR
|
|
335
192
|
|
|
336
193
|
---
|
|
337
194
|
|
|
338
|
-
## Phase 4: Merge
|
|
339
|
-
|
|
340
|
-
For each PR that passed CI (and has no pending review comments):
|
|
341
|
-
|
|
342
|
-
### Merge Order Strategy
|
|
343
|
-
|
|
344
|
-
When multiple PRs are ready to merge, order matters:
|
|
345
|
-
|
|
346
|
-
1. **Check for file overlap** between PRs:
|
|
347
|
-
```bash
|
|
348
|
-
gh pr diff <pr1> --name-only > /tmp/pr1_files
|
|
349
|
-
gh pr diff <pr2> --name-only > /tmp/pr2_files
|
|
350
|
-
comm -12 <(sort /tmp/pr1_files) <(sort /tmp/pr2_files)
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
2. **Recommended merge order**:
|
|
354
|
-
| Priority | Criteria | Rationale |
|
|
355
|
-
|----------|----------|-----------|
|
|
356
|
-
| 1 | CI/infrastructure fixes | Unblocks other PRs |
|
|
357
|
-
| 2 | PRs with no file overlap | Independent, safe in any order |
|
|
358
|
-
| 3 | Dependency PRs first | If PR B depends on PR A's changes |
|
|
359
|
-
| 4 | Oldest PRs | Reduce stale PR backlog |
|
|
360
|
-
| 5 | Smallest PRs | Quick wins |
|
|
195
|
+
## Phase 4: Merge (No Confirmation Needed)
|
|
361
196
|
|
|
362
|
-
|
|
363
|
-
```
|
|
364
|
-
Recommended merge order:
|
|
365
|
-
1. PR #41 "Fix CI" (infrastructure - may unblock others)
|
|
366
|
-
2. PR #40 "Add feature X" (no conflicts)
|
|
367
|
-
3. PR #39 "Update component Y" (no conflicts)
|
|
368
|
-
|
|
369
|
-
Proceed with this order? [Yes / Let me reorder / Merge one at a time]
|
|
370
|
-
```
|
|
197
|
+
For each PR that passed CI:
|
|
371
198
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
1. Re-verify CI status (avoid race condition): `gh pr view <pr-number> --json statusCheckRollup`
|
|
377
|
-
2. Check merge state: `gh pr view <pr-number> --json mergeStateStatus,mergeable`
|
|
199
|
+
### Pre-merge Verification
|
|
200
|
+
```bash
|
|
201
|
+
gh pr view <number> --json state,mergeStateStatus,mergeable
|
|
202
|
+
```
|
|
378
203
|
|
|
379
|
-
|
|
204
|
+
- If `state=MERGED`: Log and continue (already merged)
|
|
205
|
+
- If `mergeable=CONFLICTING`: Skip (conflicts appeared)
|
|
380
206
|
|
|
381
|
-
|
|
382
|
-
- Ask user: "Update branch via GitHub" or "Skip this PR"
|
|
383
|
-
- If update chosen:
|
|
384
|
-
- Run: `gh api repos/{owner}/{repo}/pulls/{pr-number}/update-branch -X PUT`
|
|
385
|
-
- If the API call fails (e.g., merge conflicts), inform user and offer to skip
|
|
386
|
-
- Wait for CI to re-run after update
|
|
387
|
-
- Re-check merge state
|
|
207
|
+
### Execute Merge
|
|
388
208
|
|
|
389
|
-
|
|
209
|
+
```bash
|
|
210
|
+
gh pr merge <number> --squash --delete-branch
|
|
211
|
+
```
|
|
390
212
|
|
|
391
|
-
|
|
392
|
-
- STOP - cannot auto-merge
|
|
393
|
-
- Show the PR URL
|
|
394
|
-
- Ask user: "Skip this PR" or "I'll resolve conflicts manually"
|
|
395
|
-
- If manual resolution, wait for user confirmation then re-check
|
|
213
|
+
(Use detected strategy from Phase 0: --squash, --merge, or --rebase)
|
|
396
214
|
|
|
397
|
-
|
|
215
|
+
**Handle results:**
|
|
216
|
+
- Success: Log `Merged`, increment counter
|
|
217
|
+
- "Already merged" error: Log as success, continue
|
|
218
|
+
- Other error: Log error, add to failed_prs, continue to next PR
|
|
398
219
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
220
|
+
**Output format:**
|
|
221
|
+
```
|
|
222
|
+
[1/8] PR #42 "bump cross-env"
|
|
223
|
+
-> CI passed -> merged
|
|
403
224
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
225
|
+
[2/8] PR #35 "bump sharp"
|
|
226
|
+
-> Waiting for CI... (45s)
|
|
227
|
+
-> CI passed -> merged
|
|
407
228
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
-
|
|
411
|
-
|
|
412
|
-
|
|
229
|
+
[3/8] PR #32 "bump linting group"
|
|
230
|
+
X CI failed (lint errors)
|
|
231
|
+
-> Auto-fixing lint errors...
|
|
232
|
+
-> Pushed fix, waiting for CI... (30s)
|
|
233
|
+
-> CI passed -> merged
|
|
413
234
|
|
|
414
|
-
|
|
235
|
+
[4/8] PR #28 "new feature"
|
|
236
|
+
- Skipped (draft PR)
|
|
415
237
|
|
|
416
|
-
|
|
417
|
-
-
|
|
238
|
+
[5/8] PR #25 "refactor auth"
|
|
239
|
+
- Skipped (merge conflicts)
|
|
240
|
+
```
|
|
418
241
|
|
|
419
242
|
---
|
|
420
243
|
|
|
421
|
-
## Phase 5:
|
|
244
|
+
## Phase 5: Cleanup & Summary (Automatic)
|
|
422
245
|
|
|
423
|
-
### Step
|
|
246
|
+
### Step 1: Auto-cleanup (no prompts)
|
|
424
247
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
```
|
|
429
|
-
Could not automatically restore your stashed changes.
|
|
430
|
-
Your changes are still in the stash. Run `git stash list` to see them.
|
|
431
|
-
Restore manually with: `git stash pop` or `git stash apply`
|
|
248
|
+
1. Prune remote refs:
|
|
249
|
+
```bash
|
|
250
|
+
git fetch --prune
|
|
432
251
|
```
|
|
433
|
-
3. Show `git status` to confirm restoration
|
|
434
252
|
|
|
435
|
-
|
|
253
|
+
2. For each merged PR's branch, delete local if exists:
|
|
254
|
+
```bash
|
|
255
|
+
git branch -d <branch> 2>/dev/null || true
|
|
256
|
+
```
|
|
436
257
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
Worktree at '<path>' is now on merged branch '<branch>'.
|
|
258
|
+
3. Prune worktrees:
|
|
259
|
+
```bash
|
|
260
|
+
git worktree prune
|
|
261
|
+
```
|
|
442
262
|
|
|
443
|
-
|
|
444
|
-
1. Remove worktree (Recommended)
|
|
445
|
-
2. Keep worktree (switch to <default-branch>)
|
|
446
|
-
```
|
|
447
|
-
- If remove: `git worktree remove <path>`
|
|
448
|
-
- If keep: `git -C <path> checkout <default-branch>`
|
|
263
|
+
### Step 2: Return to original context
|
|
449
264
|
|
|
450
|
-
|
|
265
|
+
- If original branch exists: `git checkout <original-branch>`
|
|
266
|
+
- If it was merged: checkout default branch
|
|
267
|
+
- If was detached HEAD: `git checkout <original-sha>`
|
|
451
268
|
|
|
452
|
-
|
|
453
|
-
- Delete local branch if it exists: `git branch -d <branch>`
|
|
454
|
-
- Skip if branch is checked out in a remaining worktree
|
|
269
|
+
### Step 3: Display Final Summary
|
|
455
270
|
|
|
456
|
-
|
|
271
|
+
```
|
|
272
|
+
=====================================================
|
|
273
|
+
PR Resolution Complete
|
|
274
|
+
=====================================================
|
|
457
275
|
|
|
458
|
-
|
|
459
|
-
|
|
276
|
+
RESULTS:
|
|
277
|
+
Merged: X PRs
|
|
278
|
+
- #42 "bump cross-env"
|
|
279
|
+
- #35 "bump sharp"
|
|
280
|
+
- #32 "bump linting group" (auto-fixed lint)
|
|
460
281
|
|
|
461
|
-
|
|
282
|
+
Skipped: X PRs
|
|
283
|
+
- #28 "new feature" (draft)
|
|
284
|
+
- #25 "refactor auth" (merge conflicts)
|
|
462
285
|
|
|
463
|
-
|
|
464
|
-
-
|
|
465
|
-
- If the original branch was merged and deleted, inform user: "Your original branch '<branch>' was merged. You are now on '<default-branch>'."
|
|
286
|
+
Failed: X PRs
|
|
287
|
+
- #20 "breaking change" (type errors - needs manual fix)
|
|
466
288
|
|
|
467
|
-
|
|
289
|
+
AUTO-FIXES APPLIED:
|
|
290
|
+
- X lint errors fixed automatically
|
|
468
291
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
=====================================================
|
|
292
|
+
REMAINING WORK:
|
|
293
|
+
- PR #25 has merge conflicts at: src/auth.ts
|
|
294
|
+
- PR #20 needs manual fix for type errors
|
|
473
295
|
|
|
474
|
-
PRs PROCESSED:
|
|
475
|
-
✓ Merged X PRs
|
|
476
|
-
- PR #42: "Add user authentication"
|
|
477
|
-
- PR #43: "Fix login bug"
|
|
478
|
-
○ Skipped X PRs (CI failed / conflicts)
|
|
479
|
-
- PR #45: "Refactor" (merge conflicts)
|
|
480
|
-
|
|
481
|
-
REVIEW COMMENTS:
|
|
482
|
-
✓ Auto-addressed X comments
|
|
483
|
-
✓ Manually resolved X comments
|
|
484
|
-
○ Skipped X comments
|
|
485
|
-
|
|
486
|
-
CI FIXES:
|
|
487
|
-
✓ Auto-fixed X lint issues
|
|
488
|
-
○ X PRs need manual fixes
|
|
489
|
-
|
|
490
|
-
CLEANUP:
|
|
491
|
-
✓ Deleted X remote branches
|
|
492
|
-
✓ Deleted X local branches
|
|
493
|
-
✓ Removed X worktrees
|
|
494
|
-
|
|
495
|
-
CURRENT STATE:
|
|
496
|
-
Branch: <current-branch>
|
|
497
|
-
Worktree: <current-worktree-path>
|
|
498
|
-
|
|
499
|
-
REMAINING OPEN PRs:
|
|
500
|
-
- PR #45: "Refactor" - merge conflicts, needs manual resolution
|
|
501
|
-
- PR #46: "Draft feature" - draft, skipped
|
|
502
|
-
|
|
503
|
-
WARNINGS (if any):
|
|
504
|
-
- PR #45 has merge conflicts at src/auth/login.ts
|
|
505
296
|
=====================================================
|
|
506
297
|
```
|
|
507
298
|
|
|
508
299
|
</workflow>
|
|
509
300
|
|
|
510
|
-
##
|
|
511
|
-
|
|
512
|
-
If the workflow fails at any point, display:
|
|
513
|
-
|
|
514
|
-
1. **Operations completed successfully** (from the operation log)
|
|
515
|
-
2. **The operation that failed** and the error message
|
|
516
|
-
3. **Current repository state**:
|
|
517
|
-
- Current branch: `git branch --show-current`
|
|
518
|
-
- Uncommitted changes: `git status --porcelain`
|
|
519
|
-
- Any in-progress operations: check for rebase/merge/cherry-pick
|
|
301
|
+
## Safety Rules
|
|
520
302
|
|
|
521
|
-
|
|
303
|
+
### ALWAYS Auto-fix
|
|
304
|
+
- Lint errors (`npm run lint -- --fix`)
|
|
305
|
+
- Formatting errors
|
|
522
306
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
307
|
+
### NEVER Auto-fix
|
|
308
|
+
- Type errors (TypeScript)
|
|
309
|
+
- Test failures
|
|
310
|
+
- Build errors
|
|
311
|
+
- Logic changes in review comments
|
|
528
312
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
- Push: `git push`
|
|
313
|
+
### Branch Safety
|
|
314
|
+
- NEVER use force push
|
|
315
|
+
- ALWAYS preserve user's starting context
|
|
316
|
+
- ALWAYS use detected merge strategy
|
|
534
317
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
318
|
+
### Timing
|
|
319
|
+
- 30 second polling interval
|
|
320
|
+
- 10 minute max wait per PR
|
|
321
|
+
- 2 max fix attempts before skipping
|
|
539
322
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
323
|
+
### Error Handling
|
|
324
|
+
- "Already merged" is a success, not an error
|
|
325
|
+
- Continue to next PR on any error
|
|
326
|
+
- Log all failures for summary
|
|
327
|
+
- Never block on a single PR failure
|
|
544
328
|
|
|
545
|
-
|
|
546
|
-
- Local branch may be deleted but remote still exists (or vice versa)
|
|
547
|
-
- Check: `git branch -a | grep <branch>`
|
|
548
|
-
- Manual cleanup if needed
|
|
329
|
+
---
|
|
549
330
|
|
|
550
|
-
|
|
331
|
+
## Error Recovery
|
|
551
332
|
|
|
552
|
-
|
|
333
|
+
If the workflow fails at any point:
|
|
553
334
|
|
|
554
|
-
|
|
335
|
+
1. **Show completed operations**
|
|
336
|
+
2. **Show current state**: `git branch --show-current`, `git status --porcelain`
|
|
337
|
+
3. **Re-run is safe**: The workflow is idempotent - merged PRs show as "Already merged"
|
|
555
338
|
|
|
556
|
-
|
|
557
|
-
-
|
|
558
|
-
-
|
|
559
|
-
-
|
|
560
|
-
- ALWAYS respect retry limits
|
|
561
|
-
|
|
562
|
-
### Review Comment Safety Rules
|
|
563
|
-
- NEVER auto-address comments that involve logic changes
|
|
564
|
-
- ALWAYS show diff before committing changes
|
|
565
|
-
- ALWAYS confirm before pushing
|
|
566
|
-
- NEVER modify code that the comment doesn't directly reference
|
|
567
|
-
- ALWAYS track which comments were addressed for summary
|
|
568
|
-
|
|
569
|
-
### Branch Safety Rules
|
|
570
|
-
- NEVER use force push (`--force` or `-f`)
|
|
571
|
-
- ALWAYS preserve the user's working context (return to original branch)
|
|
572
|
-
|
|
573
|
-
### Commit Safety Rules
|
|
574
|
-
- NEVER use `git commit -a` or `git add .` without first reviewing what will be staged
|
|
575
|
-
- ALWAYS use explicit file paths when staging: `git add <specific-file>`
|
|
576
|
-
- ALWAYS run `git status` before committing to verify staged files
|
|
577
|
-
- If the commit includes unexpected files, STOP and ask user before proceeding
|
|
578
|
-
- ALWAYS check upstream tracking before push (use `-u` flag if no upstream)
|
|
579
|
-
|
|
580
|
-
### Worktree Safety Rules
|
|
581
|
-
- NEVER remove a worktree with uncommitted changes without explicit user confirmation
|
|
582
|
-
- ALWAYS check worktree status before operations
|
|
583
|
-
- ALWAYS run `git worktree prune` after removing worktrees
|
|
584
|
-
- ALWAYS use `git -C <path>` for operations in linked worktrees
|
|
339
|
+
**Common issues:**
|
|
340
|
+
- "Already merged" - Normal, PR was auto-merged externally
|
|
341
|
+
- CI timeout - Re-run later or check GitHub Actions
|
|
342
|
+
- Merge conflicts - Resolve manually, then re-run
|