-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
73 lines (63 loc) · 2.25 KB
/
main.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 core = require('@actions/core');
const github = require('@actions/github');
const glob = require('@actions/glob')
const path = require("path")
const { findPreviousComment, createComment, updateComment, EXTENSIONS_TO_CHECK, checkAlex, getExt } = require("./utils");
async function run() {
try {
const context = github.context
const repo = context.repo;
const number = context.payload.pull_request.number;
const githubToken = core.getInput("GITHUB_TOKEN", {required: true});
const messageId = core.getInput("message_id");
const prOnly = JSON.parse(core.getInput("pr_only").toLowerCase())
const globPattern = core.getInput("glob_pattern")
if (!number) {
core.setFailed("This action only works for pull_request");
return;
}
const octokit = github.getOctokit(githubToken);
const globber = await glob.create(globPattern)
let files = await globber.glob()
if (prOnly) {
const prInfo = await octokit.graphql(
`
query prInfo($owner: String!, $name: String!, $prNumber: Int!) {
repository(owner: $owner, name: $name) {
pullRequest(number: $prNumber) {
files(first: 100) {
nodes {
path
}
}
}
}
}
`,
{
owner: context.repo.owner,
name: context.repo.repo,
prNumber: context.issue.number
}
);
let prFiles = prInfo.repository.pullRequest.files.nodes.map(f => path.resolve(f.path));
files = files.filter(x => prFiles.includes(x))
}
const filesToCheck = files
.filter(f => {
return EXTENSIONS_TO_CHECK.hasOwnProperty(getExt(f))
})
const noBinary = core.getInput('no_binary')
const profanitySureness = core.getInput('profanity_sureness')
const checkComment = checkAlex(filesToCheck, noBinary, profanitySureness)
const previous = await findPreviousComment(octokit, repo, number, messageId);
if (previous) {
await updateComment(octokit, repo, previous.id, messageId, checkComment)
} else {
await createComment(octokit, repo, number, messageId, checkComment);
}
} catch ({ message }) {
core.setFailed(message);
}
}
run();