workflows/labels: manage "needs: reviewer" label (#422069)

authored by Wolfgang Walther and committed by GitHub ee63ec60 2efd012b

+25 -6
+25 -6
.github/workflows/labels.yml
··· 133 133 pull_number 134 134 })).data 135 135 136 - const approvals = new Set( 137 - (await github.paginate(github.rest.pulls.listReviews, { 136 + const reviews = await github.paginate(github.rest.pulls.listReviews, { 138 137 ...context.repo, 139 138 pull_number 140 - })) 139 + }) 140 + 141 + const approvals = new Set( 142 + reviews 141 143 .filter(review => review.state == 'APPROVED') 142 144 .map(review => review.user?.id) 143 145 ) ··· 169 171 [ 'NONE', 'FIRST_TIMER', 'FIRST_TIME_CONTRIBUTOR' ].includes(pull_request.author_association), 170 172 } 171 173 172 - const run_id = (await github.rest.actions.listWorkflowRuns({ 174 + const { id: run_id, conclusion } = (await github.rest.actions.listWorkflowRuns({ 173 175 ...context.repo, 174 176 workflow_id: 'pr.yml', 175 177 event: 'pull_request_target', 176 178 exclude_pull_requests: true, 177 179 head_sha: pull_request.head.sha 178 - })).data.workflow_runs[0]?.id ?? 180 + })).data.workflow_runs[0] ?? 179 181 // TODO: Remove this after 2025-09-17, at which point all eval.yml artifacts will have expired. 180 182 (await github.rest.actions.listWorkflowRuns({ 181 183 ...context.repo, ··· 185 187 status: 'success', 186 188 exclude_pull_requests: true, 187 189 head_sha: pull_request.head.sha 188 - })).data.workflow_runs[0]?.id 190 + })).data.workflow_runs[0] ?? {} 189 191 190 192 // Newer PRs might not have run Eval to completion, yet. 191 193 // Older PRs might not have an eval.yml workflow, yet. 192 194 // In either case we continue without fetching an artifact on a best-effort basis. 193 195 log('Last eval run', run_id ?? '<n/a>') 196 + 197 + if (conclusion === 'success') { 198 + Object.assign(prLabels, { 199 + // We only set this label if the latest eval run was successful, because if it was not, it 200 + // *could* have requested reviewers. We will let the PR author fix CI first, before "escalating" 201 + // this PR to "needs: reviewer". 202 + // Since the first Eval run on a PR always sets rebuild labels, the same PR will be "recently 203 + // updated" for the next scheduled run. Thus, this label will still be set within a few minutes 204 + // after a PR is created, if required. 205 + // Note that a "requested reviewer" disappears once they have given a review, so we check 206 + // existing reviews, too. 207 + '9.needs: reviewer': 208 + !pull_request.draft && 209 + pull_request.requested_reviewers.length == 0 && 210 + reviews.length == 0, 211 + }) 212 + } 194 213 195 214 const artifact = run_id && (await github.rest.actions.listWorkflowRunArtifacts({ 196 215 ...context.repo,