-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
32 lines (31 loc) · 1.25 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
const core = require('@actions/core');
const github = require('@actions/github');
const Octokit = require("@octokit/rest");
const minimatch = require('minimatch');
try {
const ghToken = core.getInput('github_token');
const octokit = new Octokit(ghToken ? { auth: ghToken } : {});
const paths = core.getInput('paths').split(',');
const returnFiles = core.getInput('return_files') === 'true';
const ref = github.context.payload.head_commit.id;
const [owner, repo] = github.context.payload.repository.full_name.split('/');
octokit.repos.getCommit({ owner, repo, ref })
.then(({ data: { files } }, err) => {
if (err) throw new Error(err);
if (Array.isArray(files)) {
const modifiedPaths = files.map(f => f.filename);
if(!returnFiles) {
const modified = paths.some(p => minimatch.match(modifiedPaths, p).length);
core.setOutput('modified', modified);
} else {
const modified_files = paths.flatMap(p => minimatch.match(modifiedPaths, p));
core.setOutput('modified', modified_files.length > 0);
core.setOutput('modified_files', modified_files);
}
} else {
core.setOutput('modified', false);
}
});
} catch (error) {
core.setFailed(error.message);
}