diff --git a/readme.md b/readme.md index bddaf06..c477ebb 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -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 | diff --git a/src/index.ts b/src/index.ts index 799e607..779a1f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -247,27 +247,40 @@ function build_commit_string(commit_state: z.infer, 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) { @@ -314,7 +327,6 @@ function build_commit_string(commit_state: z.infer, commit_string = commit_string.replaceAll('"', '\\"') } - return commit_string; } diff --git a/src/zod-state.ts b/src/zod-state.ts index c48cb30..d3eef20 100644 --- a/src/zod-state.ts +++ b/src/zod-state.ts @@ -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