|
| 1 | +name: Check for Spammy Issues |
| 2 | + |
| 3 | +# **What it does**: This action closes low value pull requests in the open-source repository. |
| 4 | +# **Why we have it**: We get lots of spam in the open-source repository. |
| 5 | +# **Who does it impact**: Open-source contributors. |
| 6 | + |
| 7 | +on: |
| 8 | + issues: |
| 9 | + types: [opened] |
| 10 | +jobs: |
| 11 | + spammy-title-check: |
| 12 | + name: Remove issues with spammy titles |
| 13 | + if: github.repository == 'github/rest-api-description' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d |
| 17 | + with: |
| 18 | + github-token: ${{ secrets.ISSUE_TRANSFER_TOKEN }} |
| 19 | + script: | |
| 20 | +
|
| 21 | + const issue = context.payload.issue |
| 22 | + const owner = 'github' |
| 23 | + const repo = 'rest-api-description' |
| 24 | +
|
| 25 | + const titleWordCount = issue.title.trim().split(' ').length |
| 26 | + const titleWordCountMin = 3 |
| 27 | +
|
| 28 | + const bodyWordCount = issue.body.trim().split(' ').length |
| 29 | + const bodyWordCountMin = 6 |
| 30 | +
|
| 31 | + try { |
| 32 | + await github.teams.getMembershipForUserInOrg({ |
| 33 | + org: 'github', |
| 34 | + team_slug: 'employees', |
| 35 | + username: context.payload.sender.login, |
| 36 | + }); |
| 37 | +
|
| 38 | + // Do not perform this workflow with GitHub employees. This return |
| 39 | + // statement only gets hit if the user is a GitHub employee |
| 40 | + return |
| 41 | + } catch (err) { |
| 42 | + // An error will be thrown if the user is not a GitHub employee |
| 43 | + // If a user is not a GitHub employee, we should check to see if title has at least the minimum required number of words in it and if it does, we can exit the workflow |
| 44 | +
|
| 45 | + if (titleWordCount >= titleWordCountMin) { |
| 46 | + return |
| 47 | + } |
| 48 | +
|
| 49 | + if (bodyWordCount >= bodyWordCountMin) { |
| 50 | + return |
| 51 | + } |
| 52 | + } |
| 53 | +
|
| 54 | + // |
| 55 | + // Assuming the user is not a GitHub employee and the issue title or body |
| 56 | + // does not contain the minimum number of words required, proceed. |
| 57 | + // |
| 58 | +
|
| 59 | + // Close the issue and add the invalid label |
| 60 | + await github.issues.update({ |
| 61 | + owner: owner, |
| 62 | + repo: repo, |
| 63 | + issue_number: issue.number, |
| 64 | + labels: ['invalid'], |
| 65 | + state: 'closed' |
| 66 | + }); |
| 67 | +
|
| 68 | + // Comment on the issue |
| 69 | + await github.issues.createComment({ |
| 70 | + owner: owner, |
| 71 | + repo: repo, |
| 72 | + issue_number: issue.number, |
| 73 | + body: `[This is an automated message] This issue may have been opened accidentally. I'm going to close it now, but feel free to open a new issue with a more descriptive title and body.` |
| 74 | + }); |
0 commit comments