From 68aa36b2c6b2a2211682a6d4298726112363e91e Mon Sep 17 00:00:00 2001 From: Alena Sviridenko Date: Wed, 12 May 2021 14:22:34 +0300 Subject: [PATCH] Added workflow step to check for spammy issue (#3370) --- .github/workflows/issue-triager.yml | 38 +++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/issue-triager.yml b/.github/workflows/issue-triager.yml index c948a620a..5fa072bd2 100644 --- a/.github/workflows/issue-triager.yml +++ b/.github/workflows/issue-triager.yml @@ -19,8 +19,42 @@ jobs: repo-token: "${{ secrets.GITHUB_TOKEN }}" configuration-path: "./triage-rules.yml" - - if: always() - uses: actions/github-script@0.4.0 + - uses: actions/github-script@v4 + id: check-if-spammy + name: Check if new issue is spammy + with: + github-token: ${{secrets.GITHUB_TOKEN}} + result-encoding: string + script: | + const issue = context.payload.issue; + const minTitleLength = 2; + const titleLength = issue.title.trim().split(' ').length; + const isEmptyToolRequest = !!(issue.title.includes('[tool name]') && issue.body.includes('Tool name: ')); + + if (isEmptyToolRequest || titleLength < minTitleLength) { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + body: "This issue appears to have been opened accidentally. I'm going to close it now, but feel free to open a new issue or ask any questions in discussions!" + }); + + await github.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['Invalid'], + issue_number: issue.number, + state: 'closed' + }); + + return true; + } + + return false; + + - if: ${{ steps.check-if-spammy.outputs.result == 'false' }} + uses: actions/github-script@v4 + name: Assign labels to issue with: github-token: ${{secrets.GITHUB_TOKEN}} script: |