@@ -4,9 +4,9 @@ const helpers = require('./helpers')
44
55//require octokit rest.js
66//more info at https://github.com/octokit/rest.js
7- const Octokit = require ( '@octokit/rest' )
7+ const { Octokit } = require ( '@octokit/rest' )
88const octokit = new Octokit ( {
9- auth : `token ${ process . env . GITHUB_TOKEN } `
9+ auth : `token ${ process . env . GITHUB_TOKEN } ` ,
1010} )
1111
1212//set eventOwner and eventRepo based on action's env variables
@@ -15,35 +15,34 @@ const eventOwner = helpers.getOwner(eventOwnerAndRepo)
1515const eventRepo = helpers . getRepo ( eventOwnerAndRepo )
1616
1717async function commitChecker ( ) {
18- //read contents of action's event.json
19- const eventData = await helpers . readFilePromise (
20- '..' + process . env . GITHUB_EVENT_PATH
21- )
22- const eventJSON = JSON . parse ( eventData )
23-
24- //check if branch name starts with an issue number
25- const branchIssueNumber = helpers . getIssueFromBranch ( eventJSON . ref )
26-
27- if ( branchIssueNumber ) {
28- //for each commit, check commit message for comment
29- eventJSON . commits . forEach ( commit => {
30- const commitComment = helpers . checkForCommitActions ( commit . message )
31-
32- //if comment in commit message, add comment to related issue
33- if ( commitComment ) {
34- const comment = `${ commitComment } *from @${
35- commit . author . username
36- } in [${ commit . id . substring ( 0 , 6 ) } ](${ commit . url } )*`
37-
38- helpers . addComment (
39- octokit ,
40- eventOwner ,
41- eventRepo ,
42- branchIssueNumber ,
43- comment
44- )
18+ try {
19+ //read contents of action's event.json
20+ const eventData = await helpers . readFilePromise ( '..' + process . env . GITHUB_EVENT_PATH )
21+
22+ if ( eventData ) {
23+ const eventJSON = JSON . parse ( eventData )
24+
25+ //check if branch name starts with an issue number
26+ const branchIssueNumber = helpers . getIssueFromBranch ( eventJSON . ref )
27+
28+ if ( branchIssueNumber ) {
29+ //for each commit, check commit message for comment
30+ eventJSON . commits . forEach ( ( commit ) => {
31+ const commitComment = helpers . checkForCommitActions ( commit . message )
32+
33+ //if comment in commit message, add comment to related issue
34+ if ( commitComment ) {
35+ const comment = `${ commitComment } *from @${
36+ commit . author . username
37+ } in [${ commit . id . substring ( 0 , 6 ) } ](${ commit . url } )*`
38+
39+ helpers . addComment ( octokit , eventOwner , eventRepo , branchIssueNumber , comment )
40+ }
41+ } )
4542 }
46- } )
43+ }
44+ } catch ( error ) {
45+ console . log ( error )
4746 }
4847}
4948
0 commit comments