From 2e033512487f35ea755c8a42116c420568b8e14c Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 14 Jun 2025 13:53:01 +0200 Subject: [PATCH] workflows/labels: count approving reviewers, not reviews A single reviewer approving a Pull Request multiple times should only count once. --- .github/workflows/labels.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index 1a85953529507..d29df9002b449 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -96,7 +96,7 @@ jobs: name == '12.approved-by: package-maintainer' ) - const approvals = + const approvals = new Set( (await github.paginate(github.rest.pulls.listReviews, { owner: context.repo.owner, repo: context.repo.repo, @@ -104,15 +104,16 @@ jobs: })) .filter(review => review.state == 'APPROVED') .map(review => review.user.id) + ) - const maintainers = Object.keys( + const maintainers = new Set(Object.keys( JSON.parse(await readFile('comparison/maintainers.json', 'utf-8')) - ) + )) // And the labels that should be there const after = JSON.parse(await readFile('comparison/changed-paths.json', 'utf-8')).labels - if (approvals.length > 0) after.push(`12.approvals: ${approvals.length > 2 ? '3+' : approvals.length}`) - if (maintainers.some(id => approvals.includes(id))) after.push('12.approved-by: package-maintainer') + if (approvals.size > 0) after.push(`12.approvals: ${approvals.size > 2 ? '3+' : approvals.size}`) + if (Array.from(maintainers).some(approvals.has)) after.push('12.approved-by: package-maintainer') // Remove the ones not needed anymore await Promise.all(