@@ -20,28 +20,50 @@ var __importStar = (this && this.__importStar) || function (mod) {
2020} ;
2121Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2222const 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 = { } ) ) ;
2533async 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}
4769run ( ) ;
0 commit comments