-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
73 lines (64 loc) · 2.77 KB
/
index.js
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
const { languageList } = require('./data/language');
const { Toolkit } = require('actions-toolkit')
// Create variables to hold values
let user = '';
let title = '';
let body = '';
let issue_number = '';
// Run your GitHub Action!
Toolkit.run(async tools => {
// Print out the context in Actions dashboard
console.log(tools.context);
// Assign data to variables
const owner = tools.context.payload.repository.owner.login;
const repo = tools.context.payload.repository.name;
const actor = tools.context.actor;
// Expends we are looking to act upon
const expected_events = ['opened', 'edited', 'reopened']
if (expected_events.includes(tools.context.payload.action) && tools.context.payload.issue) {
// Issue details
const action = tools.context.payload.issue.action
title = tools.context.payload.issue.title
user = tools.context.payload.issue.user
body = tools.context.payload.issue.body
issue_number = tools.context.payload.issue.number
} else if (expected_events.includes(tools.context.payload.action) && tools.context.payload.pull_request) {
// Pull Request details
const action = tools.context.payload.pull_request.action
title = tools.context.payload.pull_request.title
user = tools.context.payload.pull_request.user
body = tools.context.payload.pull_request.body
}
// Combine title and body and split into array of substrings
let combined_string = `${title} ${body}`.toLowerCase();
let combined_array = combined_string.split(" ");
// Check if a word was found in the list
let errorFound = false;
for (let word of combined_array) {
errorFound = errorFound || (languageList.indexOf(word) != -1);
}
// If a word was found submit a comment suggesting a change
if (errorFound) {
const inclusionMsg = `
Hi there, ${actor}! 👋
\n\n
We are happy to see you being active in our GitHub organization and want to encourage that activity!\n
We are also mindful of cultivating an inclusive space and encourage you to avoid language that detracts from
that inclusivity. Words such as "guys", "dumb" and "crazy" detract from the overall culture where everyone feels valued
and appreciated in our community.\n
Please review your recent contribution and revise for inclusivity.\n
If you are interested in reading more, we recommend this guide from the Government of British Columbia:
https://www2.gov.bc.ca/assets/gov/careers/all-employees/working-with-others/words-matter.pdf
\n\n
Thank you for helping us create a space where all want to contribute! 💙
`;
await tools.github.issues.createComment({
owner: owner,
repo: repo,
issue_number: issue_number,
body: inclusionMsg
});
} else {
console.log("No language violations found!");
}
});