[Schema Inaccuracy] <Describe Problem> #279
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for Spammy Issues | |
# **What it does**: This action closes low value pull requests in the open-source repository. | |
# **Why we have it**: We get lots of spam in the open-source repository. | |
# **Who does it impact**: Open-source contributors. | |
on: | |
issues: | |
types: [opened] | |
jobs: | |
spammy-title-check: | |
name: Remove issues with spammy titles | |
if: github.repository == 'github/rest-api-description' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const issue = context.payload.issue | |
const owner = 'github' | |
const repo = 'rest-api-description' | |
let titleWordCount = 0 | |
if (issue.title) { | |
titleWordCount = issue.title.trim().split(' ').length | |
} | |
const titleWordCountMin = 3 | |
let body = issue.body.replace(/<\!---.*?-->/g, ""); | |
body = body.replace(/^\s*(#)\s*(.+?)\s*\n/gm, ""); | |
let bodyWordCount = 0 | |
if (body) { | |
bodyWordCount = body.trim().split(' ').length | |
} | |
const bodyWordCountMin = 6 | |
if (issue.title.trim().startsWith('[Schema Inaccuracy] <Describe Problem>')) { | |
titleWordCount = bodyWordCount = 0; | |
} | |
try { | |
await github.teams.getMembershipForUserInOrg({ | |
org: 'github', | |
team_slug: 'employees', | |
username: context.payload.sender.login, | |
}); | |
// Do not perform this workflow with GitHub employees. This return | |
// statement only gets hit if the user is a GitHub employee | |
return | |
} catch (err) { | |
// An error will be thrown if the user is not a GitHub employee | |
// 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 | |
if (titleWordCount >= titleWordCountMin) { | |
return | |
} | |
if (bodyWordCount >= bodyWordCountMin) { | |
return | |
} | |
} | |
// | |
// Assuming the user is not a GitHub employee and the issue title or body | |
// does not contain the minimum number of words required, proceed. | |
// | |
// Close the issue and add the invalid label | |
await github.issues.update({ | |
owner: owner, | |
repo: repo, | |
issue_number: issue.number, | |
labels: ['invalid'], | |
state: 'closed' | |
}); | |
// Comment on the issue | |
await github.issues.createComment({ | |
owner: owner, | |
repo: repo, | |
issue_number: issue.number, | |
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.` | |
}); |