|
| 1 | +name: Auto close spam issues from new users |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + issues: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + close_if_new_user: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Close issue if opened by a new user |
| 15 | + uses: actions/github-script@v7 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const issue = context.payload.issue |
| 19 | + const assoc = issue.author_association || "" |
| 20 | + const labels = (issue.labels || []).map(l => (typeof l === "string" ? l : l.name)) |
| 21 | + const exemptLabels = new Set(["allow", "do-not-close", "not-spam", "triage"]) |
| 22 | + const isExempt = labels.some(l => exemptLabels.has(l)) |
| 23 | +
|
| 24 | + const newUserAssocs = new Set(["NONE", "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR"]) |
| 25 | + const isNewUser = newUserAssocs.has(assoc) |
| 26 | +
|
| 27 | + if (!isNewUser || isExempt) { |
| 28 | + core.info(`Not closing. author_association=${assoc}, exempt=${isExempt}`) |
| 29 | + return |
| 30 | + } |
| 31 | +
|
| 32 | + const message = |
| 33 | + "Hi. This issue was auto closed because it looks like spam or low signal from a new account. " + |
| 34 | + "If you believe this is a mistake, reply to this issue with clear details and we will review and reopen if appropriate." |
| 35 | +
|
| 36 | + await github.rest.issues.addLabels({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + issue_number: issue.number, |
| 40 | + labels: ["spam"] |
| 41 | + }) |
| 42 | +
|
| 43 | + await github.rest.issues.createComment({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + issue_number: issue.number, |
| 47 | + body: message |
| 48 | + }) |
| 49 | +
|
| 50 | + await github.rest.issues.update({ |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + issue_number: issue.number, |
| 54 | + state: "closed" |
| 55 | + }) |
0 commit comments