@@ -74,17 +74,23 @@ jobs:
7474
7575 for n in "${prs[@]}"; do
7676 echo "::group::PR #$n"
77+ echo "Considering https://github.com/$REPO/pull/$n"
7778
7879 mergeable=""
7980 state=""
8081 # Poll until GitHub finishes computing the merge state (it is lazy
8182 # and returns UNKNOWN right after a base change).
8283 for attempt in $(seq 1 "$POLL_ATTEMPTS"); do
83- read -r mergeable state < < (
84+ if ! out=$ (
8485 gh pr view "$n" --repo "$REPO" \
8586 --json mergeable,mergeStateStatus \
8687 --jq '"\(.mergeable) \(.mergeStateStatus)"'
87- )
88+ ); then
89+ echo "Failed to fetch merge state for PR #$n; skipping."
90+ mergeable="UNKNOWN"; state="UNKNOWN"
91+ break
92+ fi
93+ read -r mergeable state <<<"$out"
8894 echo "attempt $attempt: mergeable=$mergeable mergeStateStatus=$state"
8995 if [ "$mergeable" != "UNKNOWN" ] && [ "$state" != "UNKNOWN" ]; then
9096 break
@@ -117,11 +123,46 @@ jobs:
117123 continue
118124 fi
119125
120- echo "PR #$n is behind but passing. Updating its branch..."
121- gh api \
126+ # Skip PRs with unresolved review conversations. A branch update
127+ # won't unblock them, and we should not flywheel a PR that still has
128+ # open feedback toward an auto-merge.
129+ owner="${REPO%/*}"; name="${REPO#*/}"
130+ if ! unresolved=$(
131+ gh api graphql \
132+ -f owner="$owner" -f name="$name" -F number="$n" \
133+ -f query='
134+ query($owner:String!, $name:String!, $number:Int!) {
135+ repository(owner: $owner, name: $name) {
136+ pullRequest(number: $number) {
137+ reviewThreads(first: 100) {
138+ nodes { isResolved }
139+ pageInfo { hasNextPage }
140+ }
141+ }
142+ }
143+ }' \
144+ --jq '[ .data.repository.pullRequest.reviewThreads.nodes[]
145+ | select(.isResolved == false) ] | length'
146+ ); then
147+ echo "Failed to fetch review threads for PR #$n; skipping."
148+ echo "::endgroup::"
149+ continue
150+ fi
151+ if [ "$unresolved" -gt 0 ]; then
152+ echo "PR #$n has $unresolved unresolved conversation(s); skipping."
153+ echo "::endgroup::"
154+ continue
155+ fi
156+
157+ echo "PR #$n is behind, passing, and has no open conversations. Updating its branch..."
158+ if ! gh api \
122159 --method PUT \
123160 -H "Accept: application/vnd.github+json" \
124- "/repos/$REPO/pulls/$n/update-branch"
161+ "/repos/$REPO/pulls/$n/update-branch"; then
162+ echo "Failed to update PR #$n; skipping."
163+ echo "::endgroup::"
164+ continue
165+ fi
125166
126167 echo "Updated PR #$n. Done (one per run)."
127168 echo "::endgroup::"
0 commit comments