96
96
env :
97
97
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
98
98
PR : ${{ steps.pr.outputs.number }}
99
+ QUERY : |-
100
+ query ($owner: String!, $name: String!, $pr: Int!) {
101
+ repository(owner: $owner, name: $name) {
102
+ pullRequest(number: $pr) {
103
+ reviewDecision
104
+ commits(last: 1) {
105
+ nodes {
106
+ commit {
107
+ checkSuites(last: 100) {
108
+ nodes {
109
+ conclusion
110
+ workflowRun {
111
+ workflow {
112
+ name
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
99
123
run : |
100
124
attempt=0
101
125
max_attempts=5
@@ -105,41 +129,33 @@ jobs:
105
129
do
106
130
attempt=$(( attempt + 1 ))
107
131
108
- approved=false
109
- complete=false
110
- mergeable=false
111
-
112
- review_data="$(
113
- gh api \
114
- --header 'Accept: application/vnd.github+json' \
115
- --header 'X-GitHub-Api-Version: 2022-11-28' \
116
- "repos/$GH_REPO/pulls/$PR/reviews"
132
+ query_response="$(
133
+ gh api graphql \
134
+ --field owner='{owner}' \
135
+ --field name='{repo}' \
136
+ --field pr="$PR" \
137
+ --raw-field query="$QUERY" \
138
+ --jq '.data.repository.pullRequest'
117
139
)"
118
- if jq --exit-status 'any(.[].state; .== "APPROVED")' <<< "$review_data" &&
119
- jq --exit-status 'all(.[].state; .!= "CHANGES_REQUESTED" )' <<< "$review_data"
120
- then
121
- approved=true
122
- fi
123
-
124
- if gh pr checks "$PR"
125
- then
126
- complete=true
127
- fi
128
140
129
- pr_data="$(
141
+ approved="$(
142
+ jq --raw-output '.reviewDecision == "APPROVED"' <<< "$query_response"
143
+ )"
144
+ complete="$(
145
+ jq --raw-output \
146
+ '.commits.nodes[].commit.checkSuites.nodes |
147
+ map(select(.workflowRun.workflow.name == "CI")) |
148
+ last | .conclusion == "SUCCESS"' <<< "$query_response"
149
+ )"
150
+ # See https://github.com/octokit/octokit.net/issues/1763 for possible `mergeable_state` values.
151
+ mergeable="$(
130
152
gh api \
131
153
--header 'Accept: application/vnd.github+json' \
132
154
--header 'X-GitHub-Api-Version: 2022-11-28' \
133
- "repos/$GH_REPO/pulls/$PR"
155
+ "repos/{owner}/{repo}/pulls/$PR" \
156
+ --jq '(.mergeable_state == "clean") and (.draft | not)'
134
157
)"
135
158
136
- # See https://github.com/octokit/octokit.net/issues/1763 for possible values.
137
- if jq --exit-status '.mergeable_state == "clean"' <<< "$pr_data" &&
138
- jq --exit-status '.draft | not' <<< "$pr_data"
139
- then
140
- mergeable=true
141
- fi
142
-
143
159
if [[ "$approved" = "true" ]] &&
144
160
[[ "$complete" = "true" ]] &&
145
161
[[ "$mergeable" = "true" ]] ||
0 commit comments