forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
82 lines (69 loc) · 2.9 KB
/
check-for-spammy-issues.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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]
permissions:
contents: none
jobs:
spammy-title-check:
name: Remove issues with spammy titles
if: github.repository == 'github/docs'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
with:
github-token: ${{ secrets.DOCUBOT_READORG_REPO_WORKFLOW_SCOPES }}
script: |
const issue = context.payload.issue
const owner = 'github'
const repo = 'docs'
const titleWordCount = issue.title.trim().split(' ').length
const titleWordCountMin = 3
try {
await github.rest.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
}
}
//
// Assuming the user is not a GitHub employee and the issue title
// does not contain the minimum number of words required, proceed.
//
// Close the issue and add the invalid label
await github.rest.issues.update({
owner: owner,
repo: repo,
issue_number: issue.number,
labels: ['invalid'],
state: 'closed'
});
// Comment on the issue
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: issue.number,
body: `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 or ask any questions in [discussions](https://github.com/github/docs/discussions)!`
});
// Add the issue to the Done column on the triage board
try {
await github.rest.projects.createCard({
column_id: 11167427,
content_id: context.payload.issue.id,
content_type: "Issue"
});
} catch (error) {
console.log(error);
}