Skip to content

Commit 7456796

Browse files
authored
✨ feat(branch): added enable prop to branch options (#38)
added branch_ticket.enable, branch_type.enable, branch_user.enable, default is true. references: #37
1 parent 1f14ac7 commit 7456796

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

.better-commits.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
},
3232
"check_ticket": {
3333
"append_hashtag": true
34-
}
34+
},
35+
"branch_pre_commands": ["git checkout main", "git pull -r origin main", "npm install"]
3536
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,16 @@ All properties are optional, they can be removed from your configuration and wil
189189
"branch_pre_commands": [],
190190
"branch_post_commands": [],
191191
"branch_user": {
192+
"enable": true,
192193
"required": false,
193194
"separator": "/"
194195
},
195196
"branch_type": {
197+
"enable": true,
196198
"separator": "/"
197199
},
198200
"branch_ticket": {
201+
"enable": true,
199202
"required": false,
200203
"separator": "-"
201204
},

src/branch.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@ main(load_setup(' better-branch '))
1313

1414
async function main(config: z.infer<typeof Config>) {
1515
const branch_state = BranchState.parse({});
16-
const cache_user_name = get_user_from_cache()
17-
const user_name_required = config.branch_user.required
18-
const user_name = await p.text({
19-
message: `Type your git username ${user_name_required ? '' : OPTIONAL_PROMPT} ${CACHE_PROMPT}`.trim(),
20-
placeholder: '',
21-
initialValue: cache_user_name,
22-
validate: (val) => {
23-
if (user_name_required && !val) return 'Please enter a username'
24-
}
25-
})
26-
if (p.isCancel(user_name)) process.exit(0)
27-
branch_state.user = user_name?.replace(/\s+/g, '-')?.toLowerCase() ?? '';
28-
set_user_cache(branch_state.user)
2916

30-
if (config.commit_type.enable) {
17+
if (config.branch_user.enable) {
18+
const cache_user_name = get_user_from_cache()
19+
const user_name_required = config.branch_user.required
20+
const user_name = await p.text({
21+
message: `Type your git username ${user_name_required ? '' : OPTIONAL_PROMPT} ${CACHE_PROMPT}`.trim(),
22+
placeholder: '',
23+
initialValue: cache_user_name,
24+
validate: (val) => {
25+
if (user_name_required && !val) return 'Please enter a username'
26+
}
27+
})
28+
if (p.isCancel(user_name)) process.exit(0)
29+
branch_state.user = user_name?.replace(/\s+/g, '-')?.toLowerCase() ?? '';
30+
set_user_cache(branch_state.user)
31+
}
32+
33+
if (config.branch_type.enable) {
3134
let initial_value = config.commit_type.initial_value
3235
const commit_type = await p.select(
3336
{
34-
message: `Select a commit type`,
37+
message: `Select a branch type`,
3538
initialValue: initial_value,
3639
options: config.commit_type.options,
3740
}
@@ -40,17 +43,19 @@ async function main(config: z.infer<typeof Config>) {
4043
branch_state.type = commit_type;
4144
}
4245

43-
const ticked_required = config.branch_ticket.required
44-
const ticket = await p.text({
45-
message: `Type ticket / issue number ${ticked_required ? '' : OPTIONAL_PROMPT}`.trim(),
46-
placeholder: '',
47-
validate: (val) => {
48-
if (ticked_required && !val) return 'Please enter a ticket / issue'
49-
}
50-
})
51-
if (p.isCancel(ticket)) process.exit(0)
52-
branch_state.ticket = ticket;
53-
46+
if (config.branch_ticket.enable) {
47+
const ticked_required = config.branch_ticket.required
48+
const ticket = await p.text({
49+
message: `Type ticket / issue number ${ticked_required ? '' : OPTIONAL_PROMPT}`.trim(),
50+
placeholder: '',
51+
validate: (val) => {
52+
if (ticked_required && !val) return 'Please enter a ticket / issue'
53+
}
54+
})
55+
if (p.isCancel(ticket)) process.exit(0)
56+
branch_state.ticket = ticket;
57+
}
58+
5459

5560
const description_max_length = config.branch_description.max_length
5661
const description = await p.text({

src/zod-state.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ export const Config = z.object({
7575
branch_pre_commands: z.array(z.string()).default([]),
7676
branch_post_commands: z.array(z.string()).default([]),
7777
branch_user: z.object({
78+
enable: z.boolean().default(true),
7879
required: z.boolean().default(false),
7980
separator: z.enum(['/', '-', '_']).default('/')
8081
}).default({}),
8182
branch_type: z.object({
83+
enable: z.boolean().default(true),
8284
separator: z.enum(['/', '-', '_']).default('/')
8385
}).default({}),
8486
branch_ticket: z.object({
87+
enable: z.boolean().default(true),
8588
required: z.boolean().default(false),
8689
separator: z.enum(['/', '-', '_']).default('-')
8790
}).default({}),

0 commit comments

Comments
 (0)