fix(ci): handle clean internal-docs sync PRs#901
fix(ci): handle clean internal-docs sync PRs#901Nikhil (shadowfax92) wants to merge 2 commits intodevfrom
Conversation
|
Greptile (@greptileai) review |
|
Claude (@claude) review |
|
Claude finished Nikhil (@shadowfax92)'s task in 1m 38s —— View job Code Review
Overall this is a solid, well-scoped fix. The design correctly addresses the root cause, and the helper function is clean. A few things worth considering: The good
Issues / things to consider 1. If run 1 sets auto-merge on an open PR (non- Since auto-merge is inherently async, the safest approach is to cancel any pending auto-merge before force-pushing, or to simply not reuse a PR that already has auto-merge enabled. You could check: AUTO_MERGE=$(gh pr view "$PR_URL" --json autoMergeRequest --jq '.autoMergeRequest // empty')
if [ -n "$AUTO_MERGE" ]; then
gh pr merge --disable-auto "$PR_URL"
fibefore the push, then re-enable at the end. 2. After 5 polls (15s total), if if [ "$attempt" = "5" ] && [ "$merge_state" = "UNKNOWN" ]; then
echo "Merge state still UNKNOWN after 5 attempts; falling back to auto-merge."
fi3. Timing window between PR check and The check for an existing open PR (line 78) and the 4. Static branch + closed PR scenario If 5. Minor: Line 115 passes Verdict The core fix is correct and the code is clearly written. Item #1 above is the most interesting failure mode worth addressing before merge; items #2–#5 are lower priority but would make the workflow more robust. Happy to look at a follow-up or inline fix. |
Greptile SummaryThis PR fixes the
Confidence Score: 3/5Safe to merge after addressing the missing --limit on gh pr list, which can cause the workflow to fail in repos with many open PRs. One P1 finding (missing --limit 100 on gh pr list breaks the reuse-existing-PR guarantee when >30 PRs are open) lowers confidence from the P1 ceiling of 4; the overall fix logic is sound and well-structured. .github/workflows/sync-internal-docs.yml — specifically the gh pr list call at line 78. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Workflow triggered] --> B{Submodule configured?}
B -- No --> C[Exit 0]
B -- Yes --> D[git submodule update --remote]
D --> E{Any changes?}
E -- No --> C
E -- Yes --> F[gh pr list open sync PRs]
F --> G{Existing PR found?}
G -- Yes --> H[Reuse branch + PR URL]
G -- No --> I[Use new branch 'bot/sync-internal-docs']
H --> J[git checkout -B branch]
I --> J
J --> K[git add + commit]
K --> L{Branch exists on origin?}
L -- Yes --> M[fetch remote SHA\ngit push --force-with-lease]
L -- No --> N[git push]
M --> O{PR URL set?}
N --> O
O -- No --> P[gh pr create]
O -- Yes --> Q[call merge_or_enable_auto_merge]
P --> Q
Q --> R[Poll mergeStateStatus\nup to 5x3s]
R --> S{State?}
S -- CLEAN --> T[gh pr merge --squash\n--match-head-commit]
S -- other --> U[gh pr merge --auto --squash\n--match-head-commit]
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
.github/workflows/sync-internal-docs.yml:78-82
**`gh pr list` default limit may miss the existing sync PR**
`gh pr list` defaults to returning at most 30 results. If the repo has more than 30 open PRs and the sync PR falls outside that window, `EXISTING_SYNC_PR` will be empty and the workflow will attempt `gh pr create` with a head branch that already has an open PR — causing the step to fail. Adding `--limit 100` (or a similar safe upper bound) ensures the existing bot PR is always found.
```suggestion
EXISTING_SYNC_PR=$(gh pr list \
--base dev \
--state open \
--limit 100 \
--json headRefName,url \
--jq 'map(select(.headRefName | startswith("bot/sync-internal-docs"))) | first // empty | [.url, .headRefName] | @tsv')
```
### Issue 2 of 2
.github/workflows/sync-internal-docs.yml:45-53
**Unnecessary `echo`+`sleep` executed on the final loop iteration**
When `mergeStateStatus` remains `UNKNOWN` after all 5 attempts, the `echo` and `sleep 3` at the bottom of the loop body still run on iteration 5 before the `for` exits — adding a wasted 3-second delay and a misleading "attempt 5/5" message. Guarding with `[ "$attempt" -lt 5 ]` avoids this.
Reviews (1): Last reviewed commit: "fix(ci): handle clean internal-docs sync..." | Re-trigger Greptile |
|
Review follow-up pushed in acde1ed: added |
Summary
gh pr merge --autoexits when GitHub reports a newly created sync PR asCLEAN.Design
The workflow now creates or updates one
bot/sync-internal-docsPR, then inspectsmergeStateStatusbefore merging.CLEANPRs are merged directly with squash; non-clean PRs use auto-merge so branch requirements can finish first. Existing sync branches are updated with--force-with-leaseand--match-head-commitprevents merging a PR head that changed unexpectedly.Test plan
ruby -ryaml -e 'YAML.load_file(".github/workflows/sync-internal-docs.yml"); puts "yaml ok"'ruby -ryaml -e 'workflow = YAML.load_file(".github/workflows/sync-internal-docs.yml"); puts workflow.fetch("jobs").fetch("sync").fetch("steps").last.fetch("run")' | bash -ngit diff --checkmergeStateStatus: CLEAN.