Skip to content

Commit 9668585

Browse files
Test written for Branch name suggestion (#58)
* 📦 cli: refactoring code with functions having return value * 📦cli: refactor function branchname with return value * :plus: cli: added generate test file * 🚀 cli: test written for branch name suggestion Co-authored-by: agg-shambhavi <[email protected]>
1 parent aa07ffa commit 9668585

File tree

3 files changed

+238
-184
lines changed

3 files changed

+238
-184
lines changed

lib/funcs/commit-gen.js

Lines changed: 161 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -11,156 +11,189 @@ const suggestCommitMsgCb = (conf) => {
1111
const issue_number = conf.current_issue.number;
1212
const commitGuidelines = conf.commit_guidelines;
1313
const customBoolean = conf.custom_guidelines;
14-
const commitTypeContent = conf.selected_commit_type
15-
.match(/([A-Za-z\s\-]+)\w+/g)
16-
.join()
17-
.trim();
14+
const commitTypeContent = conf.selected_commit_type.match(/([A-Za-z\s\-]+)\w+/g).join().trim();
1815
const emojiBool = conf.use_emojis;
1916
var commitTypeEmoji;
2017
var commitGuideNum;
2118
var commitMsg;
2219
var commitPrefix;
2320

2421
const messageBlock = {
25-
"Initial commit": {
26-
emoji: conf.emojis.initial_commit,
27-
prefix: "",
28-
},
29-
"Adding a new user-facing feature": {
30-
emoji: conf.emojis.feature,
31-
prefix: "feat",
32-
},
33-
"Improving UI": {
34-
emoji: conf.emojis.ui,
35-
prefix: "feat",
36-
},
37-
"Refactoring or improving code": {
38-
emoji: conf.emojis.code_quality,
39-
prefix: "chore",
40-
},
41-
"Improving performance": {
42-
emoji: conf.emojis.security,
43-
prefix: "chore",
44-
},
45-
"Updating configs": {
46-
emoji: conf.emojis.config,
47-
prefix: "chore",
48-
},
49-
"Improving accessibility": {
50-
emoji: conf.emojis.accessibility,
51-
prefix: "chore",
52-
},
53-
"Improving dev tools": {
54-
emoji: conf.emojis.dev_tools,
55-
prefix: "feat",
56-
},
57-
"Writing docs": {
58-
emoji: conf.emojis.docs,
59-
prefix: "chore",
60-
},
61-
"New release": {
62-
emoji: conf.emojis.release,
63-
prefix: "chore",
64-
},
65-
"Fixing a bug": {
66-
emoji: conf.emojis.bug_fix,
67-
prefix: "fix",
68-
},
69-
"Fixing a crash": {
70-
emoji: conf.emojis.crash,
71-
prefix: "fix",
72-
},
73-
"Removing code/files": {
74-
emoji: conf.emojis.cleanup,
75-
prefix: "chore",
76-
},
77-
WIP: {
78-
emoji: conf.emojis.wip,
79-
prefix: "chore",
80-
},
81-
};
22+
"Initial commit" :
23+
{
24+
emoji : conf.emojis.initial_commit,
25+
prefix : ''
26+
},
27+
"Adding a new user-facing feature" :
28+
{
29+
emoji : conf.emojis.feature,
30+
prefix : 'feat'
31+
},
32+
"Improving UI" :
33+
{
34+
emoji : conf.emojis.ui,
35+
prefix : 'feat'
36+
},
37+
"Refactoring or improving code" :
38+
{
39+
emoji : conf.emojis.code_quality,
40+
prefix : 'chore'
41+
},
42+
"Improving performance" :
43+
{
44+
emoji : conf.emojis.security,
45+
prefix : 'chore'
46+
},
47+
"Updating configs" :
48+
{
49+
emoji : conf.emojis.config,
50+
prefix : 'chore'
51+
},
52+
"Improving accessibility" :
53+
{
54+
emoji : conf.emojis.accessibility,
55+
prefix : 'chore'
56+
},
57+
"Improving dev tools" :
58+
{
59+
emoji : conf.emojis.dev_tools,
60+
prefix : 'feat'
61+
},
62+
"Writing docs" :
63+
{
64+
emoji : conf.emojis.docs,
65+
prefix : 'chore'
66+
},
67+
"New release" :
68+
{
69+
emoji : conf.emojis.release,
70+
prefix : 'chore'
71+
},
72+
"Fixing a bug" :
73+
{
74+
emoji : conf.emojis.bug_fix,
75+
prefix : 'fix'
76+
},
77+
"Fixing a crash" :
78+
{
79+
emoji : conf.emojis.crash,
80+
prefix : 'fix'
81+
},
82+
"Removing code/files" :
83+
{
84+
emoji : conf.emojis.cleanup,
85+
prefix : 'chore'
86+
},
87+
"WIP" :
88+
{
89+
emoji : conf.emojis.wip,
90+
prefix : 'chore'
91+
},
92+
}
8293

8394
var details = messageBlock[commitTypeContent];
8495
commitPrefix = details.prefix;
85-
commitTypeEmoji = emoji.get(":" + details.emoji + ":");
96+
commitTypeEmoji = emoji.get(':'+details.emoji+':');
8697

87-
switch (commitGuidelines[0]) {
88-
case `fix:`:
89-
commitGuideNum = 1;
90-
break;
91-
case `fix #`:
92-
commitGuideNum = 2;
98+
switch(commitGuidelines[0])
99+
{
100+
case `fix:`:
101+
commitGuideNum = 1;
93102
break;
94-
case `...(fix #)`:
95-
commitGuideNum = 3;
103+
case `fix #`:
104+
commitGuideNum = 2;
96105
break;
97-
default:
98-
commitGuideNum = 4;
106+
case `...(fix #)`:
107+
commitGuideNum = 3;
108+
break;
109+
default: commitGuideNum = 4;
99110
}
100111

101-
if (customBoolean == false) {
102-
switch (commitGuideNum) {
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;
112+
if (customBoolean == false)
113+
{
114+
switch(commitGuideNum)
115+
{
116+
case 1:
117+
{
118+
if (emojiBool == true)
119+
{
120+
commitMsg = `${commitTypeEmoji} ${commitPrefix}: ${issue_title}`;
121+
conf.current_commit_message = commitMsg;
122+
123+
}
124+
else
125+
{
126+
commitMsg = `${commitPrefix}: ${issue_title}`;
127+
conf.current_commit_message = commitMsg;
128+
129+
}
130+
}
131+
break;
132+
case 2:
133+
{
134+
if (emojiBool == true)
135+
{
136+
commitMsg = `${commitTypeEmoji} fix #${issue_number} ${issue_title}`;
137+
conf.current_commit_message = commitMsg;
138+
139+
}
140+
else
141+
{
142+
commitMsg = `fix #${issue_number} ${issue_title}`;
143+
conf.current_commit_message = commitMsg;
144+
145+
}
146+
}
147+
break;
148+
case 3:
149+
{
150+
if (emojiBool == true)
151+
{
152+
commitMsg = `${commitTypeEmoji} ${issue_title} fix #${issue_number}`;
153+
conf.current_commit_message = commitMsg;
154+
155+
}
156+
else
157+
{
158+
commitMsg = `${issue_title} fix #${issue_number}`;
159+
conf.current_commit_message = commitMsg;
160+
}
161+
}
162+
}
163+
}
164+
else
165+
{
166+
var customPrefix = issue_labels.length>0? issue_labels[0]+":": '';
167+
if (emojiBool == true)
168+
{
169+
commitMsg = `${commitTypeEmoji} ${customPrefix} ${issue_title}`;
170+
conf.current_commit_message = commitMsg;
171+
111172
}
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;
173+
else
174+
{
175+
commitMsg = `${customPrefix} ${issue_title}`;
176+
conf.current_commit_message = commitMsg;
177+
123178
}
124-
}
125-
break;
126-
case 3: {
127-
if (emojiBool == true) {
128-
commitMsg = `${commitTypeEmoji} ${issue_title} fix #${issue_number}`;
129-
conf.current_commit_message = commitMsg;
130-
} else {
131-
commitMsg = `${issue_title} fix #${issue_number}`;
132-
conf.current_commit_message = commitMsg;
133-
}
134-
}
135-
}
136-
} else {
137-
var customPrefix = issue_labels.length > 0 ? issue_labels[0] + ":" : "";
138-
if (emojiBool == true) {
139-
commitMsg = `${commitTypeEmoji} ${customPrefix} ${issue_title}`;
140-
conf.current_commit_message = commitMsg;
141-
} else {
142-
commitMsg = `${customPrefix} ${issue_title}`;
143-
conf.current_commit_message = commitMsg;
144-
}
145179
}
146180
fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), (err) => {
147181
if (err) console.log("Error writing file:", err);
148182
});
149-
150183
return commitMsg;
151-
};
184+
}
152185

153186
module.exports = {
154-
suggestCommitMsg: () => {
155-
setTimeout(() => {
156-
reader.jsonReader("./.gitgo", (err, conf) => {
157-
if (err) {
158-
console.log(err);
159-
return;
160-
}
161-
const retVal = suggestCommitMsgCb(conf);
162-
});
163-
}, 4000);
187+
suggestCommitMsg:() => {
188+
setTimeout(()=>{
189+
reader.jsonReader('./.gitgo', (err, conf) => {
190+
if (err) {
191+
console.log(err)
192+
return
193+
}
194+
const retVal = suggestCommitMsgCb(conf);
195+
})
196+
}, 6000);
164197
},
165-
suggestCommitMsgCb,
166-
};
198+
suggestCommitMsgCb
199+
}

0 commit comments

Comments
 (0)