Skip to content

Commit

Permalink
feat(main): #81 prepend ticket (#87)
Browse files Browse the repository at this point in the history
add prepend ticket config with never, prompt, and always

DEPRECATED: append_ticket has been deprecated, see prepend_ticket

Closes: #81
  • Loading branch information
Everduin94 authored Mar 22, 2024
1 parent 470aa06 commit 3ef2a5d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .better-commits.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
]
},
"check_ticket": {
"append_hashtag": true
"prepend_hashtag": "Always"
},
"branch_pre_commands": [
"git stash",
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
"confirm_ticket": true,
"add_to_title": true,
"append_hashtag": false,
"prepend_hashtag": "Never",
"surround": "",
"title_position": "start"
},
Expand Down Expand Up @@ -263,8 +264,14 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o

</details>

> [!NOTE]<br>
> Some properties use sets of string values
> See *confile file explanations* for possible values
### 🔭 Config File Explanations

Expand to see explanations and possible values

<details>
<summary>Expand / Collapse</summary>

Expand Down Expand Up @@ -297,7 +304,8 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
| `check_ticket.infer_ticket` | If true infer ticket from branch name |
| `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.append_hashtag` | **Deprecated**: see prepend_hashtag |
| `check_ticket.prepend_hashtag` | "Never" (default), "Prompt", or "Always" |
| `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... |
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export async function main(config: z.infer<typeof Config>) {
.filter(v => v != null)
.map(v => v && v.length >= 2 ? v[1] : '')
if (found.length && found[0]) {
commit_state.ticket = config.check_ticket.append_hashtag ? '#' + found[0] : found[0]
commit_state.ticket = config.check_ticket.append_hashtag
|| config.check_ticket.prepend_hashtag === 'Prompt'
? '#' + found[0] : found[0]
}
} catch(err: any) {
// Can't find branch, fail silently
Expand All @@ -115,6 +117,12 @@ export async function main(config: z.infer<typeof Config>) {
commit_state.ticket = user_commit_ticket ?? '';
}

if (config.check_ticket.prepend_hashtag === 'Always'
&& commit_state.ticket
&& !commit_state.ticket.startsWith('#')) {
commit_state.ticket = '#' + commit_state.ticket;
}

const commit_title = await p.text(
{
message: 'Write a brief title describing the commit',
Expand Down
1 change: 1 addition & 0 deletions src/zod-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const Config = z
confirm_ticket: z.boolean().default(true),
add_to_title: z.boolean().default(true),
append_hashtag: z.boolean().default(false),
prepend_hashtag: z.enum(['Never', 'Always', 'Prompt']).default("Never"),
surround: z.enum(["", "()", "[]", "{}"]).default(""),
title_position: z.enum(["start", "end", "before-colon"]).default("start"),
})
Expand Down

0 comments on commit 3ef2a5d

Please sign in to comment.