Skip to content

Commit 19ee665

Browse files
authored
Add artifact check for review info in workflow
1 parent 0df107c commit 19ee665

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/test-review-handler.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,38 @@ jobs:
4444
echo "=== pull_requests array ==="
4545
echo "$PULL_REQUESTS"
4646
47+
- name: Check for review artifact
48+
id: check-artifact
49+
env:
50+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
ARTIFACT_NAME=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts" \
53+
--jq '.artifacts[] | select(.name == "review-info") | .name')
54+
if [[ -n "$ARTIFACT_NAME" ]]; then
55+
echo "exists=true" >> $GITHUB_OUTPUT
56+
echo "review-info artifact found"
57+
else
58+
echo "exists=false" >> $GITHUB_OUTPUT
59+
echo "No review-info artifact found — expected for non-changes_requested reviews"
60+
fi
61+
4762
- name: Download review info
48-
id: download
63+
if: steps.check-artifact.outputs.exists == 'true'
4964
uses: actions/download-artifact@v4
50-
continue-on-error: true
5165
with:
5266
name: review-info
5367
github-token: ${{ secrets.GITHUB_TOKEN }}
5468
run-id: ${{ github.event.workflow_run.id }}
5569

5670
- name: Log artifact contents
57-
if: steps.download.outcome == 'success'
71+
if: steps.check-artifact.outputs.exists == 'true'
5872
run: |
5973
echo "=== Artifact contents ==="
6074
echo "pr_number.txt: $(cat pr_number.txt)"
6175
echo "review_state.txt: $(cat review_state.txt)"
6276
6377
- name: Read and validate review info
64-
if: steps.download.outcome == 'success'
78+
if: steps.check-artifact.outputs.exists == 'true'
6579
id: review
6680
run: |
6781
PR_NUMBER=$(cat pr_number.txt)
@@ -72,11 +86,17 @@ jobs:
7286
exit 1
7387
fi
7488
89+
if [[ "$REVIEW_STATE" != "changes_requested" && "$REVIEW_STATE" != "approved" && \
90+
"$REVIEW_STATE" != "commented" && "$REVIEW_STATE" != "dismissed" ]]; then
91+
echo "::error::Invalid review state: $REVIEW_STATE"
92+
exit 1
93+
fi
94+
7595
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
7696
echo "review_state=$REVIEW_STATE" >> $GITHUB_OUTPUT
7797
7898
- name: Comment on PR
79-
if: steps.download.outcome == 'success'
99+
if: steps.check-artifact.outputs.exists == 'true'
80100
uses: actions/github-script@v7
81101
env:
82102
PR_NUMBER: ${{ steps.review.outputs.pr_number }}

0 commit comments

Comments
 (0)