Skip to content

Commit 27c576d

Browse files
feat(*): next try
1 parent 117040f commit 27c576d

2 files changed

Lines changed: 40 additions & 15 deletions

File tree

lib/main.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ async function run() {
3737
core.debug(`reading git commit message to resolve the output variable, output variable will be true if commit message contains message "${skipOnCommitMsg}"`);
3838
const octokit = github.getOctokit(ghToken);
3939
octokit.rest;
40-
const { eventName, sha } = github.context;
40+
const { eventName } = github.context;
4141
core.info(`event name: ${eventName}`);
42+
let sha = '';
43+
switch (eventName) {
44+
case 'pull_request':
45+
core.info(JSON.stringify(github.context.payload.pull_request));
46+
sha = github.context.payload.pull_request?.head.sha ?? `unknown`;
47+
case 'push':
48+
sha = github.context.sha;
49+
break;
50+
default:
51+
core.setFailed(`no implementation for event name ${eventName}`);
52+
return;
53+
}
4254
core.info(`sha: ${sha}`);
4355
if (sha) {
4456
const q = `hash:${sha}`;

src/main.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as core from '@actions/core'
22
import * as github from '@actions/github'
33

4-
enum INPUT_PARAMS{
4+
enum INPUT_PARAMS {
55
SKIP_ON_COMMIT_MSG = 'skipOnCommitMsg',
66
GH_TOKEN = 'githubToken'
77
}
88

9-
enum OUTPUT_PARAMS{
9+
enum OUTPUT_PARAMS {
1010
SHOULD_EXECUTE = 'shouldExecute'
1111
}
1212

@@ -20,35 +20,48 @@ async function run() {
2020
const octokit = github.getOctokit(ghToken)
2121
octokit.rest
2222

23-
const {eventName, sha} = github.context
23+
const { eventName } = github.context
2424
core.info(`event name: ${eventName}`)
25+
let sha = ''
26+
switch (eventName) {
27+
case 'pull_request':
28+
core.info(JSON.stringify(github.context.payload.pull_request))
29+
sha = github.context.payload.pull_request?.head.sha ?? `unknown`
30+
case 'push':
31+
sha = github.context.sha
32+
break
33+
default:
34+
core.setFailed(`no implementation for event name ${eventName}`)
35+
return
36+
}
37+
2538
core.info(`sha: ${sha}`)
26-
if(sha){
39+
if (sha) {
2740
const q = `hash:${sha}`
28-
console.info(`q: ${q}`,)
29-
const response = await octokit.rest.search.commits({q})
41+
console.info(`q: ${q}`)
42+
const response = await octokit.rest.search.commits({ q })
3043
core.info(`count of commits ${response.data.total_count}`)
31-
for(const {commit} of response.data.items){
32-
core.info(`message: ${commit.url}`)
33-
core.info(`message: ${commit.message}`)
44+
for (const { commit } of response.data.items) {
45+
core.info(`message: ${commit.url}`)
46+
core.info(`message: ${commit.message}`)
3447
}
3548

36-
if(true){
49+
if (true) {
3750
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, true)
3851
return
3952
}
4053
}
4154

42-
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, false)
55+
core.setOutput(OUTPUT_PARAMS.SHOULD_EXECUTE, false)
4356
} catch (error) {
4457
core.error('there was an error')
45-
if(error instanceof Error){
58+
if (error instanceof Error) {
4659
core.setFailed(error.message)
4760
}
4861

49-
try{
62+
try {
5063
core.setFailed(JSON.stringify(error))
51-
}catch (err){
64+
} catch (err) {
5265
core.setFailed(`there was an error, can't print JSON.stringify failed`)
5366
}
5467
}

0 commit comments

Comments
 (0)