Skip to content

Commit ee0b8fd

Browse files
feat(*): implement commit message fetch
1 parent d368410 commit ee0b8fd

2 files changed

Lines changed: 62 additions & 20 deletions

File tree

lib/main.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,50 @@ var __importStar = (this && this.__importStar) || function (mod) {
2020
};
2121
Object.defineProperty(exports, "__esModule", { value: true });
2222
const core = __importStar(require("@actions/core"));
23-
// import * as git from '@actions/github'
24-
const INPUT = 'skipOnCommitMsg';
23+
const github = __importStar(require("@actions/github"));
24+
var INPUT_PARAMS;
25+
(function (INPUT_PARAMS) {
26+
INPUT_PARAMS["SKIP_ON_COMMIT_MSG"] = "skipOnCommitMsg";
27+
INPUT_PARAMS["GH_TOKEN"] = "githubToken";
28+
})(INPUT_PARAMS || (INPUT_PARAMS = {}));
29+
var OUTPUT_PARAMS;
30+
(function (OUTPUT_PARAMS) {
31+
OUTPUT_PARAMS["SHOULD_EXECUTE"] = "shouldExecute";
32+
})(OUTPUT_PARAMS || (OUTPUT_PARAMS = {}));
2533
async function run() {
2634
try {
27-
core.debug('start working');
28-
const skipOnCommitMsg = core.getInput(INPUT);
29-
console.log(`skip CI on commit message ${skipOnCommitMsg}`);
30-
core.setOutput('shouldExecute', false);
31-
// `<!--stopping here, because the commit message contains the provided input <${skipOnCommitMsg}>-->`)
32-
// const ghToken = core.getInput()
33-
// git.getOctokit()
34-
// console.log(git.context.payload)
35-
// const commitMessage = git.context.payload.comment
36-
// console.log('commit message', commitMessage)
37-
// if (commitMessage.includes(skipOnCommitMsg)) {
38-
// core.setFailed(`stopping here, because the commit message contains the provided input <${skipOnCommitMsg}>`)
39-
// }
35+
const skipOnCommitMsg = core.getInput(INPUT_PARAMS.SKIP_ON_COMMIT_MSG);
36+
const ghToken = core.getInput(INPUT_PARAMS.GH_TOKEN);
37+
core.debug(`reading git commit message to resolve the output variable, output variable will be true if commit message contains message "${skipOnCommitMsg}"`);
38+
const octokit = github.getOctokit(ghToken);
39+
octokit.rest;
40+
const { eventName, sha } = github.context;
41+
core.info(`event name: ${eventName}`);
42+
core.info(`sha: ${sha}`);
43+
if (sha) {
44+
const q = encodeURIComponent(`hash:${sha}`);
45+
core.info(`q: ${q}`);
46+
const commit = await octokit.rest.search.commits({ q });
47+
core.info(`count of commits ${commit.data.total_count}`);
48+
core.info(`message: ${commit.data.items[0].commit.message}`);
49+
if (true) {
50+
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, true);
51+
return;
52+
}
53+
}
54+
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, false);
4055
}
4156
catch (error) {
57+
core.error('there was an error');
4258
if (error instanceof Error) {
4359
core.setFailed(error.message);
4460
}
61+
try {
62+
core.setFailed(JSON.stringify(error));
63+
}
64+
catch (err) {
65+
core.setFailed(`there was an error, can't print JSON.stringify failed`);
66+
}
4567
}
4668
}
4769
run();

src/main.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ enum INPUT_PARAMS{
55
SKIP_ON_COMMIT_MSG = 'skipOnCommitMsg',
66
GH_TOKEN = 'githubToken'
77
}
8+
9+
enum OUTPUT_PARAMS{
10+
SHOULD_EXECUTE = 'shouldExecute'
11+
}
12+
813
async function run() {
914
try {
1015
const skipOnCommitMsg = core.getInput(INPUT_PARAMS.SKIP_ON_COMMIT_MSG)
@@ -15,18 +20,33 @@ async function run() {
1520
const octokit = github.getOctokit(ghToken)
1621
octokit.rest
1722

18-
if(true){
19-
core.setOutput('shouldExecute', false)
20-
} else {
21-
core.setOutput('shouldExecute', true)
23+
const {eventName, sha} = github.context
24+
core.info(`event name: ${eventName}`)
25+
core.info(`sha: ${sha}`)
26+
if(sha){
27+
const q = encodeURIComponent(`hash:${sha}`)
28+
core.info(`q: ${q}`,)
29+
const commit = await octokit.rest.search.commits({q})
30+
core.info(`count of commits ${commit.data.total_count}`)
31+
core.info(`message: ${commit.data.items[0].commit.message}`)
32+
if(true){
33+
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, true)
34+
return
35+
}
2236
}
37+
38+
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, false)
2339
} catch (error) {
2440
core.error('there was an error')
2541
if(error instanceof Error){
2642
core.setFailed(error.message)
2743
}
2844

29-
core.setFailed(error)
45+
try{
46+
core.setFailed(JSON.stringify(error))
47+
}catch (err){
48+
core.setFailed(`there was an error, can't print JSON.stringify failed`)
49+
}
3050
}
3151
}
3252

0 commit comments

Comments
 (0)