From 50bbf5bf5dff5055c2780b86e2fe469d73b4f7f2 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Fri, 14 Aug 2026 02:35:24 +0300 Subject: [PATCH] Add PR approval workflow (#732) --- .github/workflows/pr-approve.yml | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/pr-approve.yml diff --git a/.github/workflows/pr-approve.yml b/.github/workflows/pr-approve.yml new file mode 100644 index 00000000..b91c69a4 --- /dev/null +++ b/.github/workflows/pr-approve.yml @@ -0,0 +1,74 @@ +name: PR Approve (Comment Triggered) + +on: + issue_comment: + types: [created] + +permissions: + contents: read + +jobs: + approve: + runs-on: ubuntu-latest + if: github.event.issue.pull_request != null + permissions: + contents: read + issues: write + pull-requests: write + + steps: + - name: Approve PR + uses: actions/github-script@v9 + with: + script: | + const comment = context.payload.comment.body.trim(); + + const ALLOWED_USERS = ['flaminel']; + + if (comment !== '/approve') { + console.log(`Comment "${comment}" is not the approve command, skipping.`); + return; + } + + const login = context.payload.comment.user.login; + if (!ALLOWED_USERS.includes(login.toLowerCase())) { + console.log(`User ${login} is not allowed to approve, skipping.`); + return; + } + + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }); + + if (pr.data.state !== 'open') { + console.log('PR is not open, skipping.'); + return; + } + + if (pr.data.draft) { + console.log('PR is a draft, skipping.'); + return; + } + + await github.rest.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.data.number, + event: 'APPROVE', + body: `Approved on behalf of @${login}.` + }); + + console.log(`${login} approved PR #${pr.data.number} @ ${pr.data.head.sha}.`); + + try { + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '+1' + }); + } catch (e) { + console.log(`Could not add reaction: ${e}`); + }