@@ -3,13 +3,50 @@ const github = require('@actions/github');
33
44try {
55 // `who-to-greet` input defined in action metadata file
6- const nameToGreet = core . getInput ( 'who-to-greet' ) ;
7- console . log ( `Hello ${ nameToGreet } !` ) ;
8- const time = ( new Date ( ) ) . toTimeString ( ) ;
9- core . setOutput ( "time" , time ) ;
6+ // const nameToGreet = core.getInput('who-to-greet');
7+ // console.log(`Hello ${nameToGreet}!`);
8+ // const time = (new Date()).toTimeString();
9+ // core.setOutput("time", time);
1010 // Get the JSON webhook payload for the event that triggered the workflow
11- const payload = JSON . stringify ( github . context . payload , undefined , 2 )
12- console . log ( `The event payload: ${ payload } ` ) ;
11+ // const payload = JSON.stringify(github.context.payload, undefined, 2)
12+ // console.log(`The event payload: ${payload}`);
13+
14+
15+
16+ let event = github . context . eventName ;
17+
18+ if ( event !== "push" ) {
19+ // error how to core
20+ core . setFailed ( "This action only works on push events" ) ;
21+ return ;
22+ }
23+
24+ let ref = github . context . ref ;
25+ let branch = res . replace ( / ^ r e f s \/ ( h e a d s | t a g s ) \/ / , '' ) ;
26+
27+ let username = github . context . actor ;
28+ let repo = github . context . repo . repo ;
29+
30+
31+ let commitMessage = github . context . payload . commits [ 0 ] . message ;
32+ // explode commit message on new line
33+ let commitMessageArray = commitMessage . split ( "\n\n" ) ;
34+
35+ let title = commitMessageArray [ 0 ] ;
36+ let body = commitMessageArray [ 1 ] ;
37+
38+ let info = {
39+ "title" : title ,
40+ "body" : body ,
41+ "username" : username ,
42+ "repo" : repo ,
43+ "branch" : branch ,
44+ "timestamp" : new Date ( ) . toTimeString ( )
45+ } ;
46+
47+ core . setOutput ( "info" , JSON . stringify ( info ) ) ;
48+ console . log ( JSON . stringify ( info ) ) ;
49+
1350} catch ( error ) {
1451 core . setFailed ( error . message ) ;
1552}
0 commit comments