From 7d9f512c09de1478b40ab3d9743702f4cae7247d Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 6 Oct 2026 11:52:20 +0200 Subject: [PATCH] chore: support /approve-user in issues (#11512) --- .github/scripts/approve-contributor.js | 7 +------ .github/workflows/approve-contributor.yml | 4 ++-- CONTRIBUTING.md | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/scripts/approve-contributor.js b/.github/scripts/approve-contributor.js index 6925fd2f4..5cc0b19bc 100644 --- a/.github/scripts/approve-contributor.js +++ b/.github/scripts/approve-contributor.js @@ -3,18 +3,13 @@ const PATH = 'APPROVED_CONTRIBUTORS' /** * Adds a user to the list of approved contributors when a user with write access - * comments `/approve-user` or `/approve-user username` on a pull request. Sets the `approved` output when the user is on the list. + * comments `/approve-user` or `/approve-user username` on an issue or a pull request. Sets the `approved` output when the user is on the list. */ export default async function approveContributor({ github, context, core }) { const { owner, repo } = context.repo const comment = context.payload.comment const commenter = comment.user.login - if (!context.payload.issue?.pull_request) { - core.info('The comment is not on a pull request') - return - } - const match = /^\/approve-user(?: +@?([a-z\d][a-z\d-]{0,38}))?$/i.exec(comment.body.trim()) if (!match) { core.info('The comment is not an approval command') diff --git a/.github/workflows/approve-contributor.yml b/.github/workflows/approve-contributor.yml index d3e52b0e3..f2adc0d95 100644 --- a/.github/workflows/approve-contributor.yml +++ b/.github/workflows/approve-contributor.yml @@ -1,7 +1,7 @@ name: Approve Contributor # Adds a user to the list of approved contributors when a maintainer comments -# `/approve-user` or `/approve-user username` on a pull request, see "Pull Request Policy" in CONTRIBUTING.md. +# `/approve-user` or `/approve-user username` on an issue or a pull request, see "Pull Request Policy" in CONTRIBUTING.md. # # SECURITY: anyone can trigger this workflow with a comment. It must never check out # or run code from a pull request. The script trusts only the permission that the API @@ -23,7 +23,6 @@ jobs: # this only skips unrelated comments, the script validates the command and the commenter if: | github.repository == 'vitest-dev/vitest' && - github.event.issue.pull_request && startsWith(github.event.comment.body, '/approve-user') name: Approve Contributor runs-on: ubuntu-slim @@ -67,6 +66,7 @@ jobs: runs-on: ubuntu-slim timeout-minutes: 5 permissions: + issues: write # to react to a comment on an issue pull-requests: write # to react to a comment on a PR steps: - name: React diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2b33f4e06..bc9ffc8c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -250,7 +250,7 @@ flowchart TD The [`AI Policy`](./.github/workflows/ai-policy.yml) workflow applies the [pull request policy](#pull-request-policy) when a pull request is opened or reopened. It comments on the pull request, pointing to the linked issues or asking to open a new one, and closes it. It never touches pull requests from members of the `vitest-dev` organization, from repository collaborators, or from apps that push branches to this repository (for example, Renovate). Users with write access to the repository control the rest: - Reopen a pull request to keep it open. The workflow closes it again only if someone without write access reopens it. -- Comment `/approve-user` on a pull request to add its author to the approved contributors. Comment `/approve-user username` to add a specific user. It must be a regular comment on a pull request, not a review, and it must contain nothing but the command. The [`Approve Contributor`](./.github/workflows/approve-contributor.yml) workflow reacts to it with 🚀 when the user is on the list. +- Comment `/approve-user` on an issue or a pull request to add its author to the approved contributors. Comment `/approve-user username` to add a specific user. It must be a regular comment, not a review, and it must contain nothing but the command. The [`Approve Contributor`](./.github/workflows/approve-contributor.yml) workflow reacts to it with 🚀 when the user is on the list. - The list is the `APPROVED_CONTRIBUTORS` file on the [`approved-contributors`](https://github.com/vitest-dev/vitest/blob/approved-contributors/APPROVED_CONTRIBUTORS) branch. Each line is an account id followed by the login as a comment, for example `12345 # username`. Only the id counts, so a renamed account stays approved and nobody else can take its place; the login is there for people to read. Delete a line to remove a contributor. Both workflows fail, and no pull request is closed, if the branch or the file is missing. - Run the [`PR Redirect All`](./.github/workflows/pr-redirect-all.yml) workflow manually to close every open pull request that the policy would close. It skips pull requests that a maintainer reopened after they were closed. Keep the `dry-run` option on first to see which pull requests it would close. -- 2.54.0