11const emoji = require ( "node-emoji" ) ;
22const fs = require ( "fs" ) ;
33const reader = require ( "./jsonReader" ) ;
4- const {
5- Console
6- } = require ( "console" ) ;
4+ const { Console } = require ( "console" ) ;
75
86stopwords = [ "a" , "the" ] ;
97
108const suggestCommitMsgCb = ( conf ) => {
11-
129 const issue_labels = conf . current_issue . labels ;
1310 const issue_title = conf . current_issue . title ;
1411 const issue_number = conf . current_issue . number ;
1512 const commitGuidelines = conf . commit_guidelines ;
1613 const customBoolean = conf . custom_guidelines ;
17- const commitTypeContent = conf . selected_commit_type . match ( / ( [ A - Z a - z \s \- ] + ) \w + / g) . join ( ) . trim ( ) ;
14+ const commitTypeContent = conf . selected_commit_type
15+ . match ( / ( [ A - Z a - z \s \- ] + ) \w + / g)
16+ . join ( )
17+ . trim ( ) ;
1818 const emojiBool = conf . use_emojis ;
1919 var commitTypeEmoji ;
2020 var commitGuideNum ;
2121 var commitMsg ;
2222 var commitPrefix ;
2323
24-
25-
2624 const messageBlock = {
2725 "Initial commit" : {
2826 emoji : conf . emojis . initial_commit ,
29- prefix : ''
27+ prefix : "" ,
3028 } ,
3129 "Adding a new user-facing feature" : {
3230 emoji : conf . emojis . feature ,
33- prefix : ' feat'
31+ prefix : " feat" ,
3432 } ,
3533 "Improving UI" : {
3634 emoji : conf . emojis . ui ,
37- prefix : ' feat'
35+ prefix : " feat" ,
3836 } ,
3937 "Refactoring or improving code" : {
4038 emoji : conf . emojis . code_quality ,
41- prefix : ' chore'
39+ prefix : " chore" ,
4240 } ,
4341 "Improving performance" : {
4442 emoji : conf . emojis . security ,
45- prefix : ' chore'
43+ prefix : " chore" ,
4644 } ,
4745 "Updating configs" : {
4846 emoji : conf . emojis . config ,
49- prefix : ' chore'
47+ prefix : " chore" ,
5048 } ,
5149 "Improving accessibility" : {
5250 emoji : conf . emojis . accessibility ,
53- prefix : ' chore'
51+ prefix : " chore" ,
5452 } ,
5553 "Improving dev tools" : {
5654 emoji : conf . emojis . dev_tools ,
57- prefix : ' feat'
55+ prefix : " feat" ,
5856 } ,
5957 "Writing docs" : {
6058 emoji : conf . emojis . docs ,
61- prefix : ' chore'
59+ prefix : " chore" ,
6260 } ,
6361 "New release" : {
6462 emoji : conf . emojis . release ,
65- prefix : ' chore'
63+ prefix : " chore" ,
6664 } ,
6765 "Fixing a bug" : {
6866 emoji : conf . emojis . bug_fix ,
69- prefix : ' fix'
67+ prefix : " fix" ,
7068 } ,
7169 "Fixing a crash" : {
7270 emoji : conf . emojis . crash ,
73- prefix : ' fix'
71+ prefix : " fix" ,
7472 } ,
7573 "Removing code/files" : {
7674 emoji : conf . emojis . cleanup ,
77- prefix : ' chore'
75+ prefix : " chore" ,
7876 } ,
79- " WIP" : {
77+ WIP : {
8078 emoji : conf . emojis . wip ,
81- prefix : ' chore'
79+ prefix : " chore" ,
8280 } ,
83-
84- }
81+ } ;
8582
8683 var details = messageBlock [ commitTypeContent ] ;
8784 commitPrefix = details . prefix ;
88- commitTypeEmoji = emoji . get ( ':' + details . emoji + ':' ) ;
85+ commitTypeEmoji = emoji . get ( ":" + details . emoji + ":" ) ;
8986
9087 switch ( commitGuidelines [ 0 ] ) {
9188 case `fix:` :
@@ -103,74 +100,67 @@ const suggestCommitMsgCb = (conf) => {
103100
104101 if ( customBoolean == false ) {
105102 switch ( commitGuideNum ) {
106- case 1 : {
103+ case 1 :
104+ {
105+ if ( emojiBool == true ) {
106+ commitMsg = `${ commitTypeEmoji } ${ commitPrefix } : ${ issue_title } ` ;
107+ conf . current_commit_message = commitMsg ;
108+ } else {
109+ commitMsg = `${ commitPrefix } : ${ issue_title } ` ;
110+ conf . current_commit_message = commitMsg ;
111+ }
112+ }
113+ break ;
114+
115+ case 2 :
116+ {
117+ if ( emojiBool == true ) {
118+ commitMsg = `${ commitTypeEmoji } fix #${ issue_number } ${ issue_title } ` ;
119+ conf . current_commit_message = commitMsg ;
120+ } else {
121+ commitMsg = `fix #${ issue_number } ${ issue_title } ` ;
122+ conf . current_commit_message = commitMsg ;
123+ }
124+ }
125+ break ;
126+ case 3 : {
107127 if ( emojiBool == true ) {
108- commitMsg = `${ commitTypeEmoji } ${ commitPrefix } : ${ issue_title } ` ;
128+ commitMsg = `${ commitTypeEmoji } ${ issue_title } fix # ${ issue_number } ` ;
109129 conf . current_commit_message = commitMsg ;
110-
111130 } else {
112- commitMsg = `${ commitPrefix } : ${ issue_title } ` ;
131+ commitMsg = `${ issue_title } fix # ${ issue_number } ` ;
113132 conf . current_commit_message = commitMsg ;
114-
115133 }
116-
117- }
118- break ;
119-
120- case 2 : {
121- if ( emojiBool == true ) {
122- commitMsg = `${ commitTypeEmoji } fix #${ issue_number } ${ issue_title } ` ;
123- conf . current_commit_message = commitMsg ;
124-
125- } else {
126- commitMsg = `fix #${ issue_number } ${ issue_title } ` ;
127- conf . current_commit_message = commitMsg ;
128-
129134 }
130135 }
131- break ;
132- case 3 : {
133- if ( emojiBool == true ) {
134- commitMsg = `${ commitTypeEmoji } ${ issue_title } fix #${ issue_number } ` ;
135- conf . current_commit_message = commitMsg ;
136-
137- } else {
138- commitMsg = `${ issue_title } fix #${ issue_number } ` ;
139- conf . current_commit_message = commitMsg ;
140-
141- }
142- }
143- }
144136 } else {
145- var customPrefix = issue_labels . length > 0 ? issue_labels [ 0 ] + ":" : '' ;
137+ var customPrefix = issue_labels . length > 0 ? issue_labels [ 0 ] + ":" : "" ;
146138 if ( emojiBool == true ) {
147139 commitMsg = `${ commitTypeEmoji } ${ customPrefix } ${ issue_title } ` ;
148140 conf . current_commit_message = commitMsg ;
149-
150141 } else {
151142 commitMsg = `${ customPrefix } ${ issue_title } ` ;
152143 conf . current_commit_message = commitMsg ;
153-
154144 }
155145 }
156146 fs . writeFile ( "./.gitgo" , JSON . stringify ( conf , null , 2 ) , ( err ) => {
157147 if ( err ) console . log ( "Error writing file:" , err ) ;
158148 } ) ;
159149
160150 return commitMsg ;
161- }
151+ } ;
162152
163153module . exports = {
164154 suggestCommitMsg : ( ) => {
165155 setTimeout ( ( ) => {
166- reader . jsonReader ( ' ./.gitgo' , ( err , conf ) => {
156+ reader . jsonReader ( " ./.gitgo" , ( err , conf ) => {
167157 if ( err ) {
168- console . log ( err )
169- return
158+ console . log ( err ) ;
159+ return ;
170160 }
171161 const retVal = suggestCommitMsgCb ( conf ) ;
172- } )
162+ } ) ;
173163 } , 4000 ) ;
174164 } ,
175- suggestCommitMsgCb
176- }
165+ suggestCommitMsgCb,
166+ } ;
0 commit comments