1+ const emoji = require ( 'node-emoji' ) ;
2+
3+ const reader = require ( './jsonReader' ) ;
4+
5+ stopwords = [ 'a' , 'the' ] ;
6+
7+ function suggestCommitMsg ( ) {
8+ reader . jsonReader ( '../../.gitgo' , ( err , conf ) => {
9+ if ( err ) {
10+ console . log ( err )
11+ return
12+ }
13+
14+ var issue_labels = conf . current_issue . labels ;
15+ var issue_title = conf . current_issue . title ;
16+ var issue_number = conf . current_issue . number ;
17+ var commitGuidelines = conf . commit_guidelines ;
18+ var customBoolean = conf . custom_guidelines ;
19+ var commitTypeContent = String ( conf . selected_commit_type . match ( / ( [ A - Z a - z \s \- ] + ) \w + / g) ) . trim ( ) ;
20+ var commitTypeEmoji ;
21+ var emojiBool = conf . use_emojis ;
22+ var commitGuideNum ;
23+ var commitMsg ;
24+ var prefix ;
25+
26+
27+
28+
29+ switch ( commitTypeContent )
30+ {
31+ case 'Initial commit' :
32+ {
33+ commitTypeEmoji = conf . emojis . initial_commit ;
34+ }
35+ break ;
36+ case 'Adding a new user-facing feature' :
37+ {
38+ commitTypeEmoji = conf . emojis . feature ;
39+ prefix = 'feat' ;
40+ }
41+ break ;
42+ case 'Improving UI' :
43+ {
44+ commitTypeEmoji = conf . emojis . ui ;
45+ prefix = 'feat' ;
46+ }
47+ break ;
48+ case 'Refactoring or improving code' :
49+ {
50+ commitTypeEmoji = conf . emojis . code_quality ;
51+ prefix = 'chore' ;
52+ }
53+ break ;
54+ case 'Improving performance' :
55+ {
56+ commitTypeEmoji = conf . emojis . performance ;
57+ prefix = 'chore' ;
58+ }
59+ break ;
60+ case 'Improving security' :
61+ {
62+ commitTypeEmoji = conf . emojis . security ;
63+ prefix = 'chore' ;
64+ }
65+ break ;
66+ case 'Updating configs' :
67+ {
68+ commitTypeEmoji = conf . emojis . config ;
69+ prefix = 'chore' ;
70+ }
71+ break ;
72+ case 'Improving accessibility' :
73+ {
74+ commitTypeEmoji = conf . emojis . accessibility ;
75+ prefix = 'chore' ;
76+ }
77+ break ;
78+ case 'Improving dev tools' :
79+ {
80+ commitTypeEmoji = conf . emojis . dev_tools ;
81+ prefix = 'feat' ;
82+ }
83+ break ;
84+ case 'Writing docs' :
85+ {
86+ commitTypeEmoji = conf . emojis . docs ;
87+ prefix = 'chore' ;
88+ }
89+ break ;
90+ case 'New release' :
91+ {
92+ commitTypeEmoji = conf . emojis . release ;
93+ prefix = 'chore' ;
94+ }
95+ break ;
96+ case 'Fixing a bug' :
97+ {
98+ commitTypeEmoji = conf . emojis . bug_fix ;
99+ prefix = 'fix' ;
100+ }
101+ break ;
102+ case 'Fixing a crash' :
103+ {
104+ commitTypeEmoji = conf . emojis . crash ;
105+ prefix = 'fix' ;
106+ }
107+ break ;
108+ case 'Removing code/files' :
109+ {
110+ commitTypeEmoji = conf . emojis . cleanup ;
111+ prefix = 'chore' ;
112+ }
113+ break ;
114+ case 'WIP' :
115+ {
116+ commitTypeEmoji = conf . emojis . wip ;
117+ prefix = 'chore' ;
118+ }
119+ break ;
120+ // default:
121+ // {
122+ // commitTypeEmoji = conf.emojis.feature;
123+ // }
124+
125+ }
126+ commitTypeEmoji = emoji . get ( ':' + commitTypeEmoji + ':' ) ;
127+
128+ switch ( commitGuidelines [ 0 ] )
129+ {
130+ case `fix:` :
131+ commitGuideNum = 1 ;
132+ break ;
133+ case `fix #` :
134+ commitGuideNum = 2 ;
135+ break ;
136+ case `...(fix #)` :
137+ commitGuideNum = 3 ;
138+ break ;
139+ default : commitGuideNum = 4 ;
140+ }
141+
142+ if ( customBoolean == false )
143+ {
144+ switch ( commitGuideNum )
145+ {
146+ case 1 :
147+ {
148+ if ( emojiBool == true )
149+ {
150+ commitMsg = `${ commitTypeEmoji } ${ prefix } : ${ issue_title } ` ;
151+ console . log ( commitMsg ) ;
152+ }
153+ else
154+ {
155+ commitMsg = `${ prefix } : ${ issue_title } ` ;
156+ console . log ( commitMsg ) ;
157+ }
158+
159+ }
160+ break ;
161+
162+ case 2 :
163+ {
164+ if ( emojiBool == true )
165+ {
166+ commitMsg = `${ commitTypeEmoji } fix #${ issue_number } ` ;
167+ console . log ( commitMsg ) ;
168+ }
169+ else
170+ {
171+ commitMsg = `fix #${ issue_number } ` ;
172+ console . log ( commitMsg ) ;
173+ }
174+ }
175+ break ;
176+ case 3 :
177+ {
178+ if ( emojiBool == true )
179+ {
180+ commitMsg = `${ commitTypeEmoji } ${ issue_title } fix #${ issue_number } ` ;
181+ console . log ( commitMsg ) ;
182+ }
183+ else
184+ {
185+ commitMsg = `${ issue_title } fix #${ issue_number } ` ;
186+ console . log ( commitMsg ) ;
187+ }
188+ }
189+ }
190+ }
191+ else
192+ {
193+ prefix = issue_labels . length > 0 ? issue_labels [ 0 ] + ":" : '' ;
194+ if ( emojiBool == true )
195+ {
196+ commitMsg = `${ commitTypeEmoji } ${ prefix } ${ issue_title } ` ;
197+ console . log ( commitMsg ) ;
198+ }
199+ else
200+ {
201+ commitMsg = `${ prefix } ${ issue_title } ` ;
202+ console . log ( commitMsg ) ;
203+ }
204+
205+ }
206+
207+ } ) ;
208+ } ;
209+
210+
211+ suggestCommitMsg ( )
0 commit comments