Update achievement to link to attached leaderboard (and with specific… #4360
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Approvals | |
| on: {} | |
| # pull_request_review: | |
| # types: [submitted] | |
| # pull_request: | |
| # types: [opened, reopened, synchronize] | |
| permissions: | |
| pull-requests: read | |
| contents: read | |
| statuses: write | |
| jobs: | |
| enforce-approvals: | |
| name: Enforce Approvals | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const ME = context.payload.pull_request.user.login; | |
| const OWNER = 'tahminator'; | |
| const GUARDIANS_OF_THE_GALAXY = (() => { | |
| let initialGuardians = ['Arshadul-Monir', 'arklian']; | |
| return initialGuardians; | |
| })(); | |
| const { data: reviews } = await github.rest.pulls.listReviews({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| }); | |
| reviews.sort((a, b) => new Date(a.submitted_at) - new Date(b.submitted_at)); | |
| const latest = {}; | |
| for (const r of reviews) { | |
| latest[r.user.login] = r.state.toUpperCase(); | |
| } | |
| const approved = Object.keys(latest).filter(u => latest[u] === 'APPROVED'); | |
| const hasOwner = ME === OWNER || approved.includes(OWNER); | |
| const guardiansWhoCanApprove = GUARDIANS_OF_THE_GALAXY.filter(u => u !== ME); | |
| const hasGuardian = guardiansWhoCanApprove.length === 0 || guardiansWhoCanApprove.some(u => approved.includes(u)); | |
| let state, description; | |
| if (hasOwner && hasGuardian) { | |
| console.log('All approvals received.'); | |
| state = 'success'; | |
| description = 'All approvals received.'; | |
| } else { | |
| state = 'failure'; | |
| const missing = []; | |
| if (!hasGuardian) | |
| missing.push(`1 guardian of the galaxy (${GUARDIANS_OF_THE_GALAXY.filter(u => !approved.includes(u)).join(', ')})`); | |
| if (!hasOwner) missing.push(`1 owner (${OWNER})`); | |
| console.log(`Missing ${missing.join(' and ')}`); | |
| description = `Missing ${missing.join(' and ')}`; | |
| } | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: context.payload.pull_request.head.sha, | |
| state, | |
| context: 'Approvals Check', | |
| description, | |
| }); |