-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
51 lines (39 loc) · 1.36 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
const core = require("@actions/core");
const { getOctokit, context } = require("@actions/github");
async function run() {
const githubToken = core.getInput("github-token", { required: true });
const fileNames = JSON.parse(core.getInput("file-names", { required: true }));
if (typeof fileNames !== "object" || !fileNames.length) {
core.setFailed("Please fill in the correct file names");
}
const client = getOctokit(githubToken);
const [ base, head ] = (() => {
if (context.eventName === "pull_request") {
const pr = context.payload.pull_request;
return [pr.base.sha, pr.head.sha];
} else {
const compareURL = context.payload.compare;
const endPoint = compareURL.lastIndexOf("/");
if (endPoint === -1) {
core.setFailed("Not found endpoint");
}
return compareURL.substring(endPoint + 1).split("...");
}
})();
const changedFileNames = (await client.repos.compareCommits({
...context.repo,
base,
head
})).data.files.map(f => f.filename);
const isAllIncluded = fileNames.every(fileName =>changedFileNames.includes(fileName));
if (isAllIncluded) {
core.setOutput("success", true);
} else {
core.setFailed(`
Please check your changed files
Expect: ${JSON.stringify(fileNames, null, 2)}
Actual: ${JSON.stringify(changedFileNames, null, 2)}
`);
}
}
run();