-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (43 loc) · 1.54 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
// Copyright (c) 2023 Jasper Harrison.
// This file is licensed under the terms of the Apache License, version 2.0
const core = require("@actions/core");
const github = require("@actions/github");
async function main() {
// Create the RegExp object, and load the octokit
const pattern = core.getInput('pattern');
const token = core.getInput('token')
// Make sure the inputs have loaded properly
if (!pattern) {
core.setFailed("Unable to load pattern.");
return 1;
} else if (!token) {
core.setFailed("Unable to load token")
return 1;
}
const re = RegExp(pattern);
const octokit = github.getOctokit(token);
// Fetch the workflow run object
octokit.actions.getWorkflowRun(
{
owner: github.context.repo.owner,
repo: github.context.repo.repo,
run_id: github.context.runId
}
).then(action => {
// Extract the commit message from the commit which triggered the workflow run
const commit_message = action.data.head_commit.message;
// And check for the pattern.
let match = commit_message.search(re);
if (match !== -1) {
core.setOutput("canSkip", "true");
console.log(`Skipping; match found: ${match}`)
} else {
core.setOutput("canSkip", "false")
console.log("Not skipping, no match found.")
}
}).catch(e => {
console.log(e);
core.setFailed(e.message);
});
}
main().catch((e) => core.setFailed(e.message))