Skip to content

Commit

Permalink
feat(main): #72 customize ticket (#77)
Browse files Browse the repository at this point in the history
Added surround prop to add brackets, parens, curly braces, around ticket. Added new ticket position 'before-colon'.

Closes: #72
  • Loading branch information
Everduin94 authored Jan 25, 2024
1 parent a18ef9f commit 46336fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
"confirm_ticket": true,
"add_to_title": true,
"append_hashtag": false,
"title_position": "start"
"title_position": "start",
"surround": ""
},
"commit_title": {
"max_size": 70
Expand Down Expand Up @@ -283,7 +284,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
| `check_ticket.confirm_ticket` | If true manually confirm inference |
| `check_ticket.add_to_title` | If true add ticket to title |
| `check_ticket.append_hashtag` | If true add hashtag to ticket (Ideal for Github Issues) |
| `check_ticket.title_position` | If "start" ticket at start if "end" ticket at end |
| `check_ticket.title_position` | "start" (of description) (default), "end", "before-colon" |
| `check_ticket.surround` | "" (default), "[]", "()", "{}" - Wraps ticket in title |
| `commit_title.max_size` | Max size of title including scope, type, etc... |
| `commit_body.enable` | If true include body |
| `commit_body.required` | If true body is required |
Expand Down
26 changes: 19 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,40 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>,
commit_string += `(${scope})`
}

let title_ticket = commit_state.ticket;
const surround = config.check_ticket.surround;
if (commit_state.ticket && surround) {
const open_token = surround.charAt(0);
const close_token = surround.charAt(1);
title_ticket = `${open_token}${commit_state.ticket}${close_token}`
}

const position_before_colon = config.check_ticket.title_position === "before-colon"
if (title_ticket && config.check_ticket.add_to_title && position_before_colon) {
const spacing = commit_state.scope || (commit_state.type && !config.check_ticket.surround) ? ' ' : '';
commit_string += colorize ? color.magenta(spacing + title_ticket) : spacing + title_ticket
}

if (commit_state.breaking_title && config.breaking_change.add_exclamation_to_title) {
commit_string += colorize ? color.red('!') : '!'
}

if (commit_state.scope || commit_state.type) {
if (commit_state.scope || commit_state.type || (title_ticket && position_before_colon)) {
commit_string += ': '
}

const position_start = config.check_ticket.title_position === "start"
const position_end = config.check_ticket.title_position === "end"

if(commit_state.ticket && config.check_ticket.add_to_title && position_start) {
commit_string += colorize ? color.magenta(commit_state.ticket) + ' ' : commit_state.ticket + ' '
if(title_ticket && config.check_ticket.add_to_title && position_start) {
commit_string += colorize ? color.magenta(title_ticket) + ' ' : title_ticket + ' '
}

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

if(commit_state.ticket && config.check_ticket.add_to_title && position_end) {
commit_string += ' ' + (colorize ? color.magenta(commit_state.ticket) : commit_state.ticket)
if(title_ticket && config.check_ticket.add_to_title && position_end) {
commit_string += ' ' + (colorize ? color.magenta(title_ticket) : title_ticket)
}

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


return commit_string;
}

3 changes: 2 additions & 1 deletion src/zod-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export const Config = z
confirm_ticket: z.boolean().default(true),
add_to_title: z.boolean().default(true),
append_hashtag: z.boolean().default(false),
title_position: z.enum(["start", "end"]).default("start"),
surround: z.enum(["", "()", "[]", "{}"]).default(""),
title_position: z.enum(["start", "end", "before-colon"]).default("start"),
})
.default({}),
commit_title: z
Expand Down

0 comments on commit 46336fe

Please sign in to comment.