-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (42 loc) · 1.37 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
const { getOctokit } = require("@actions/github/lib/github");
const core = require("@actions/core");
const github = require("@actions/github");
async function main() {
try {
const token = core.getInput("token");
const migration_directory = core.getInput("migration-directory");
const githubClient = getOctokit(token);
const githubContext = github.context;
const pullRequest = githubContext.issue;
const endpointOptions = githubClient.pulls.listFiles.endpoint.merge({
owner: pullRequest.owner,
repo: pullRequest.repo,
pull_number: pullRequest.number,
});
let hasOneOrMoreMigration = false;
let hasOtherChange = false;
const files = await githubClient.paginate(endpointOptions, (response) => {
response.data.map((file) => {
if (file.filename.indexOf(migration_directory) !== -1) {
hasOneOrMoreMigration = true;
} else {
hasOtherChange = true;
}
return file.filename;
});
});
if (hasOneOrMoreMigration && hasOtherChange) {
core.setFailed(
"This PR contains migrations and other changes. Migrations must be shipped independently."
);
} else {
core.setOutput(
"Either the PR contains no migrations or only migrations.",
JSON.stringify(files)
);
}
} catch (error) {
core.setFailed(error.message);
}
}
main();