Skip to content

Commit 46336fe

Browse files
authored
feat(main): Everduin94#72 customize ticket (Everduin94#77)
Added surround prop to add brackets, parens, curly braces, around ticket. Added new ticket position 'before-colon'. Closes: Everduin94#72
1 parent a18ef9f commit 46336fe

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
192192
"confirm_ticket": true,
193193
"add_to_title": true,
194194
"append_hashtag": false,
195-
"title_position": "start"
195+
"title_position": "start",
196+
"surround": ""
196197
},
197198
"commit_title": {
198199
"max_size": 70
@@ -283,7 +284,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
283284
| `check_ticket.confirm_ticket` | If true manually confirm inference |
284285
| `check_ticket.add_to_title` | If true add ticket to title |
285286
| `check_ticket.append_hashtag` | If true add hashtag to ticket (Ideal for Github Issues) |
286-
| `check_ticket.title_position` | If "start" ticket at start if "end" ticket at end |
287+
| `check_ticket.title_position` | "start" (of description) (default), "end", "before-colon" |
288+
| `check_ticket.surround` | "" (default), "[]", "()", "{}" - Wraps ticket in title |
287289
| `commit_title.max_size` | Max size of title including scope, type, etc... |
288290
| `commit_body.enable` | If true include body |
289291
| `commit_body.required` | If true body is required |

src/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,40 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>,
247247
commit_string += `(${scope})`
248248
}
249249

250+
let title_ticket = commit_state.ticket;
251+
const surround = config.check_ticket.surround;
252+
if (commit_state.ticket && surround) {
253+
const open_token = surround.charAt(0);
254+
const close_token = surround.charAt(1);
255+
title_ticket = `${open_token}${commit_state.ticket}${close_token}`
256+
}
257+
258+
const position_before_colon = config.check_ticket.title_position === "before-colon"
259+
if (title_ticket && config.check_ticket.add_to_title && position_before_colon) {
260+
const spacing = commit_state.scope || (commit_state.type && !config.check_ticket.surround) ? ' ' : '';
261+
commit_string += colorize ? color.magenta(spacing + title_ticket) : spacing + title_ticket
262+
}
263+
250264
if (commit_state.breaking_title && config.breaking_change.add_exclamation_to_title) {
251265
commit_string += colorize ? color.red('!') : '!'
252266
}
253267

254-
if (commit_state.scope || commit_state.type) {
268+
if (commit_state.scope || commit_state.type || (title_ticket && position_before_colon)) {
255269
commit_string += ': '
256270
}
257271

258272
const position_start = config.check_ticket.title_position === "start"
259273
const position_end = config.check_ticket.title_position === "end"
260-
261-
if(commit_state.ticket && config.check_ticket.add_to_title && position_start) {
262-
commit_string += colorize ? color.magenta(commit_state.ticket) + ' ' : commit_state.ticket + ' '
274+
if(title_ticket && config.check_ticket.add_to_title && position_start) {
275+
commit_string += colorize ? color.magenta(title_ticket) + ' ' : title_ticket + ' '
263276
}
264277

265278
if (commit_state.title) {
266279
commit_string += colorize ? color.reset(commit_state.title) : commit_state.title
267280
}
268281

269-
if(commit_state.ticket && config.check_ticket.add_to_title && position_end) {
270-
commit_string += ' ' + (colorize ? color.magenta(commit_state.ticket) : commit_state.ticket)
282+
if(title_ticket && config.check_ticket.add_to_title && position_end) {
283+
commit_string += ' ' + (colorize ? color.magenta(title_ticket) : title_ticket)
271284
}
272285

273286
if (commit_state.body) {
@@ -314,7 +327,6 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>,
314327
commit_string = commit_string.replaceAll('"', '\\"')
315328
}
316329

317-
318330
return commit_string;
319331
}
320332

src/zod-state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export const Config = z
9595
confirm_ticket: z.boolean().default(true),
9696
add_to_title: z.boolean().default(true),
9797
append_hashtag: z.boolean().default(false),
98-
title_position: z.enum(["start", "end"]).default("start"),
98+
surround: z.enum(["", "()", "[]", "{}"]).default(""),
99+
title_position: z.enum(["start", "end", "before-colon"]).default("start"),
99100
})
100101
.default({}),
101102
commit_title: z

0 commit comments

Comments
 (0)