Skip to content

Commit 6b932f4

Browse files
chiedolee-dohmheiskrjaniceilene
authored
Create a workflow that closes issues with short titles (#17501)
Create a workflow that closes issues with short titles Co-authored-by: chiedo <[email protected]> Co-authored-by: Lee Dohm <[email protected]> Co-authored-by: Kevin Heis <[email protected]> Co-authored-by: Janice <[email protected]>
1 parent c02c9d6 commit 6b932f4

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Check for Spammy Issues
2+
on:
3+
issues:
4+
types: [opened]
5+
jobs:
6+
spammy-title-check:
7+
name: Remove issues with spammy titles
8+
if: github.repository == 'github/docs'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
12+
with:
13+
github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }}
14+
script: |
15+
16+
const issue = context.payload.issue
17+
const owner = 'github'
18+
const repo = 'docs'
19+
20+
const titleWordCount = issue.title.trim().split(' ').length
21+
const titleWordCountMin = 2
22+
23+
try {
24+
await github.teams.getMembershipForUserInOrg({
25+
org: 'github',
26+
team_slug: 'employees',
27+
username: context.payload.sender.login,
28+
});
29+
30+
// Do not perform this workflow with GitHub employees. This return
31+
// statement only gets hit if the user is a GitHub employee
32+
return
33+
} catch(err) {
34+
// An error will be thrown if the user is not a GitHub employee
35+
// 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
36+
37+
if(titleWordCount > titleWordCountMin) {
38+
return
39+
}
40+
}
41+
42+
//
43+
// Assuming the user is not a GitHub employee and the issue title
44+
// has the minimum number of words required, proceed.
45+
//
46+
47+
// Add the invalid label
48+
await github.issues.addLabels({
49+
owner: owner,
50+
repo: repo,
51+
issue_number: issue.number,
52+
labels: ['invalid'],
53+
});
54+
55+
// Remove triage label
56+
await github.issues.removeLabel({
57+
owner: owner,
58+
repo: repo,
59+
issue_number: issue.number,
60+
name: 'triage',
61+
});
62+
63+
// Comment on the issue
64+
await github.issues.createComment({
65+
owner: owner,
66+
repo: repo,
67+
issue_number: issue.number,
68+
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](https://github.com/github/docs/discussions)!"
69+
});
70+
71+
// Close the issue
72+
await github.issues.update({
73+
owner: owner,
74+
repo: repo,
75+
issue_number: issue.number,
76+
state: 'closed'
77+
});

0 commit comments

Comments
 (0)