Skip to content

Commit df8e0a9

Browse files
authored
[fix](ci) Change code-review workflow from approval-based to status-based tracking (#62469)
Replace GitHub PR review approval/request-changes mechanism with commit status tracking for code-review workflow. The workflow now: - Posts "pending" status on PR open/sync/reopen events - Updates to "success" status when /review comment triggers automated review - Removes decision-based approval logic and RESULT_START/RESULT_END parsing - Changes gh pr review --approve to --comment for final summary
1 parent 8719d70 commit df8e0a9

3 files changed

Lines changed: 14 additions & 72 deletions

File tree

.github/workflows/opencode-review-comment.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,14 @@ jobs:
8181
PR_NUMBER: ${{ needs.resolve-pr.outputs.pr_number }}
8282
HEAD_SHA: ${{ needs.resolve-pr.outputs.head_sha }}
8383
run: |
84-
REVIEWS=$(gh api --paginate repos/${REPO}/pulls/${PR_NUMBER}/reviews)
85-
review_state=$(printf '%s' "$REVIEWS" | jq -r --arg head_sha "$HEAD_SHA" '
86-
([ .[]
87-
| select(.user.login == "github-actions[bot]" or .user.login == "github-actions")
88-
| select(.commit_id == $head_sha)
89-
| select(.state == "APPROVED" or .state == "CHANGES_REQUESTED")
90-
]
91-
| sort_by(.submitted_at)
92-
| last
93-
| .state) // ""
94-
')
84+
state="pending"
85+
summary="Trigger /review to start automated review for ${HEAD_SHA}."
9586
96-
conclusion="failure"
97-
summary="No automated approve/request-changes review exists for ${HEAD_SHA}."
98-
99-
if [ "$review_state" = "APPROVED" ]; then
100-
conclusion="success"
101-
summary="Automated review approved the PR for ${HEAD_SHA}."
102-
elif [ "$review_state" = "CHANGES_REQUESTED" ]; then
103-
summary="Automated review requested changes for ${HEAD_SHA}."
87+
if [ "${{ needs.code-review.result }}" = "success" ]; then
88+
state="success"
89+
summary="Automated review was triggered for ${HEAD_SHA}."
10490
fi
10591
106-
state="failure"
107-
[ "$conclusion" = "success" ] && state="success"
108-
10992
gh api repos/${REPO}/statuses/${HEAD_SHA} \
11093
-X POST \
11194
-f state="${state}" \

.github/workflows/opencode-review-runner.yml

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,14 @@ jobs:
8282
8383
## Final response format
8484
- After completing the review, you MUST provide a final summary opinion based on the rules defined in AGENTS.md and the code-review skill. The summary must include conclusions for each applicable critical checkpoint.
85-
- If the overall quality of PR is good and there are no critical blocking issues (even if there are some tolerable minor issues), submit an opinion on approval using: gh pr review PLACEHOLDER_PR_NUMBER --approve --body "<summary>"
85+
- If the overall quality of PR is good and there are no critical blocking issues (even if there are some tolerable minor issues), submit an opinion on approval using: gh pr review PLACEHOLDER_PR_NUMBER --comment --body "<summary>"
8686
- If issues found, submit a review with inline comments plus a comprehensive summary body. Use GitHub Reviews API to ensure comments are inline:
8787
- Inline comment bodies may include GitHub suggested changes blocks when you can propose a precise patch.
8888
- Prefer suggested changes for small, self-contained fixes (for example typos, trivial refactors, or narrowly scoped code corrections).
8989
- Do not force suggested changes for broad, architectural, or multi-file issues; explain those normally.
9090
- Build a JSON array of comments like: [{ "path": "<file>", "position": <diff_position>, "body": "..." }]
9191
- Submit via: gh api repos/PLACEHOLDER_REPO/pulls/PLACEHOLDER_PR_NUMBER/reviews --input <json_file>
9292
- The JSON file should contain: {"event":"REQUEST_CHANGES","body":"<summary>","comments":[...]}
93-
- After publish your opinion, your final response MUST end with exactly one machine-readable result block in this format:
94-
RESULT_START
95-
{
96-
"decision": "APPROVE" | "REQUEST_CHANGES"
97-
}
98-
RESULT_END
9993
PROMPT
10094
sed -i "s|PLACEHOLDER_REPO|${REPO}|g" /tmp/review_prompt.txt
10195
sed -i "s|PLACEHOLDER_PR_NUMBER|${PR_NUMBER}|g" /tmp/review_prompt.txt
@@ -130,29 +124,6 @@ jobs:
130124
failure_reason="OpenCode exited with status $status"
131125
fi
132126
133-
result_json=$(awk '
134-
/^RESULT_START$/ {capture=1; current=""; next}
135-
/^RESULT_END$/ {capture=0; result=current; found=1; next}
136-
capture {current = current $0 ORS}
137-
END {
138-
if (found) {
139-
printf "%s", result
140-
}
141-
}
142-
' /tmp/opencode-review.log)
143-
144-
if [ -z "$failure_reason" ] && [ -z "$result_json" ]; then
145-
failure_reason="OpenCode did not emit a RESULT_START/RESULT_END result block"
146-
fi
147-
148-
if [ -z "$failure_reason" ] && ! printf '%s' "$result_json" > /tmp/opencode-review-result.json; then
149-
failure_reason="Failed to persist OpenCode review result"
150-
fi
151-
152-
if [ -z "$failure_reason" ] && ! jq -e '.decision == "APPROVE" or .decision == "REQUEST_CHANGES"' /tmp/opencode-review-result.json > /dev/null; then
153-
failure_reason="OpenCode emitted an invalid review decision"
154-
fi
155-
156127
if [ -n "$failure_reason" ]; then
157128
{
158129
echo "failure_reason<<EOF"
@@ -162,15 +133,8 @@ jobs:
162133
exit 1
163134
fi
164135
165-
decision=$(jq -r '.decision' /tmp/opencode-review-result.json)
166-
echo "decision=$decision" >> "$GITHUB_OUTPUT"
167-
168-
if [ "$decision" == "REQUEST_CHANGES" ]; then
169-
exit 1
170-
fi
171-
172136
- name: Comment PR on review failure
173-
if: ${{ always() && steps.review.outcome != 'success' && steps.review.outputs.decision != 'REQUEST_CHANGES' }}
137+
if: ${{ always() && steps.review.outcome != 'success' }}
174138
env:
175139
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176140
REVIEW_FAILURE_REASON: ${{ steps.review.outputs.failure_reason }}

.github/workflows/opencode-review.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,22 @@ jobs:
2121
PR_NUMBER: ${{ github.event.pull_request.number }}
2222
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
2323
run: |
24-
REVIEWS=$(gh api --paginate repos/${REPO}/pulls/${PR_NUMBER}/reviews)
25-
review_state=$(printf '%s' "$REVIEWS" | jq -r --arg head_sha "$HEAD_SHA" '
26-
([ .[]
27-
| select(.user.login == "github-actions[bot]" or .user.login == "github-actions")
28-
| select(.commit_id == $head_sha)
29-
| select(.state == "APPROVED" or .state == "CHANGES_REQUESTED")
24+
STATUSES=$(gh api --paginate repos/${REPO}/commits/${HEAD_SHA}/status)
25+
review_state=$(printf '%s' "$STATUSES" | jq -r '
26+
([ .statuses[]
27+
| select(.context == "code-review")
3028
]
31-
| sort_by(.submitted_at)
29+
| sort_by(.created_at)
3230
| last
3331
| .state) // ""
3432
')
3533
3634
state="pending"
3735
summary="Trigger /review to start automated review for ${HEAD_SHA}."
3836
39-
if [ "$review_state" = "APPROVED" ]; then
37+
if [ "$review_state" = "success" ]; then
4038
state="success"
41-
summary="Automated review approved the PR for ${HEAD_SHA}."
42-
elif [ "$review_state" = "CHANGES_REQUESTED" ]; then
43-
state="failure"
44-
summary="Automated review requested changes for ${HEAD_SHA}."
39+
summary="Automated review was triggered for ${HEAD_SHA}."
4540
fi
4641
4742
gh api repos/${REPO}/statuses/${HEAD_SHA} \

0 commit comments

Comments
 (0)