From c12b4a15654c6a40b4109b35c3035e46d8e6bf63 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Sat, 16 Aug 2025 23:06:57 +0300 Subject: [PATCH] ci: add a spam closing workflow --- .github/scripts/close_spam.js | 38 +++++++++++++++++++++++++++++++++++ .github/workflows/spam.yml | 29 ++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/scripts/close_spam.js create mode 100644 .github/workflows/spam.yml diff --git a/.github/scripts/close_spam.js b/.github/scripts/close_spam.js new file mode 100644 index 00000000..7b58f6ab --- /dev/null +++ b/.github/scripts/close_spam.js @@ -0,0 +1,38 @@ +module.exports = async ({ github, context }) => { + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ + ...context.repo, + username: context.actor + }); + if (!data.permission.includes("triage")) { + await github.log.error("Workflow called with insufficient permissions!"); + return; + } + + let target = context.payload.issue; + if (target) { + await github.rest.issues.update({ + ...context.repo, + issue_number: target.number, + state: "closed", + state_reason: "not_planned", + title: "[spam]", + body: "", + type: null, + }); + } else { + target = context.payload.pull_request; + await github.rest.pulls.update({ + ...context.repo, + pull_number: target.number, + state: "closed", + title: "[spam]", + body: "", + }); + } + + await github.rest.issues.lock({ + ...context.repo, + issue_number: target.number, + lock_reason: "spam", + }); +}; diff --git a/.github/workflows/spam.yml b/.github/workflows/spam.yml new file mode 100644 index 00000000..cc581e0b --- /dev/null +++ b/.github/workflows/spam.yml @@ -0,0 +1,29 @@ +name: Close as spam + +on: + issues: + types: [labeled] + pull_request_target: + types: [labeled] + +permissions: + issues: write + pull-requests: write + +jobs: + spam: + runs-on: ubuntu-latest + if: github.event.label.name == 'spam' + steps: + - name: Checkout script + uses: actions/checkout@v5 + with: + sparse-checkout: .github/scripts/close_spam.js + sparse-checkout-cone-mode: false + + - name: Run script + uses: actions/github-script@v7 + with: + script: | + const script = require('./.github/scripts/close_spam.js') + await script({github, context})