diff --git a/.github/workflows/external-plugin-approval-command.yml b/.github/workflows/external-plugin-approval-command.yml index 21f088f0..eaa0e3a4 100644 --- a/.github/workflows/external-plugin-approval-command.yml +++ b/.github/workflows/external-plugin-approval-command.yml @@ -3,6 +3,8 @@ name: External Plugin Approval Commands on: issue_comment: types: [created] + pull_request: + types: [closed] permissions: contents: write @@ -13,6 +15,7 @@ jobs: handle-command: runs-on: ubuntu-latest if: >- + github.event_name == 'issue_comment' && !github.event.issue.pull_request && (contains(github.event.comment.body, '/approve') || contains(github.event.comment.body, '/reject')) steps: @@ -407,6 +410,65 @@ jobs: }); } + sync-merged-pr-labels: + runs-on: ubuntu-latest + if: >- + github.event_name == 'pull_request' && + github.event.action == 'closed' && + github.event.pull_request.merged == true && + contains(github.event.pull_request.labels.*.name, 'external-plugin') + steps: + - name: Normalize merged external plugin PR labels + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 + with: + script: | + const prNumber = context.payload.pull_request.number; + const staleLabels = ['awaiting-review', 'awaiting-approval', 'ready-for-review', 'rejected']; + + try { + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: 'approved', + color: '1D76DB', + description: 'Submission was approved by a maintainer' + }); + } catch (error) { + if (error.status !== 422) { + throw error; + } + } + + const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + per_page: 100 + }); + const labelNames = new Set(currentLabels.map((label) => label.name)); + + if (!labelNames.has('approved')) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: ['approved'] + }); + } + + for (const labelName of staleLabels) { + if (!labelNames.has(labelName)) { + continue; + } + + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: labelName + }); + } + - name: Finalize rejection if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'reject' uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0