Skip to content

Commit 2ddf5c7

Browse files
author
Ando
authored
Merge pull request #113 from iamando/develop
bugfix: check if ticket is enabled avoid show to ticket input if not enabled
2 parents 74ca28c + 11993a7 commit 2ddf5c7

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commitizen-cli",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Command-line interface tool that helps enforce standardized commit message formats in Git repositories.",
55
"type": "module",
66
"license": "MIT",
@@ -50,6 +50,7 @@
5050
},
5151
"devDependencies": {
5252
"@types/dedent": "^0.7.0",
53+
"@types/lodash": "^4.14.196",
5354
"@types/node": "^20.2.5",
5455
"@typescript-eslint/eslint-plugin": "^5.59.8",
5556
"@typescript-eslint/parser": "^5.59.8",
@@ -66,6 +67,7 @@
6667
"@clack/prompts": "^0.6.3",
6768
"cleye": "^1.3.2",
6869
"dedent": "^0.7.0",
69-
"kolorist": "^1.8.0"
70+
"kolorist": "^1.8.0",
71+
"lodash": "^4.17.21"
7072
}
7173
}

src/utils/commiter.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import _ from 'lodash'
12
import { cancel, intro, group, confirm, outro } from '@clack/prompts'
23
import { bgYellow, black } from 'kolorist'
34
import dedent from 'dedent'
45

56
import { CANCELED_OP_MSG } from './constants'
6-
import { type, message, hasTicket, ticket } from './prompts'
7+
import { type, message, ticket } from './prompts'
78
import { handleCliError, CliError } from './cli-errror'
89
import { log } from './log'
910
import { formatCommitWithEmojiByType } from './emojis'
@@ -14,11 +15,10 @@ export const commiter = async () => {
1415

1516
await isTreeClean()
1617

17-
const values = await group(
18+
const values: any = await group(
1819
{
1920
type: () => type(),
2021
message: () => message(),
21-
hasTicket: () => hasTicket(),
2222
ticket: () => ticket(),
2323
},
2424
{
@@ -41,11 +41,10 @@ export const commiter = async () => {
4141
commit = formatCommitWithEmojiByType({
4242
type: values.type,
4343
message: values.message,
44-
hasTicket: values.hasTicket,
4544
ticket: values.ticket,
4645
})
4746
} else {
48-
if (values.hasTicket) {
47+
if (!_.isEmpty(values.ticket)) {
4948
commit = `${values.type}(${values.ticket}): ${values.message}`
5049
} else {
5150
commit = `${values.type}: ${values.message}`

src/utils/emojis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import _ from 'lodash'
2+
13
export const formatCommitWithEmojiByType = ({
24
type,
35
message,
4-
hasTicket,
56
ticket,
67
}: {
78
type: string
89
message: string
9-
hasTicket?: boolean
1010
ticket?: string
1111
}): string => {
1212
const emojiByType: Record<string, any> = {
@@ -22,7 +22,7 @@ export const formatCommitWithEmojiByType = ({
2222

2323
let commit: string
2424

25-
if (hasTicket) {
25+
if (!_.isEmpty(ticket)) {
2626
commit = `${emojiByType[type]} ${type}(${ticket}): ${message}`
2727
} else {
2828
commit = `${emojiByType[type]} ${type}: ${message}`

src/utils/prompts.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ export const message = () =>
2323
},
2424
}) as Promise<string>
2525

26-
export const hasTicket = () =>
27-
confirm({
26+
export const ticket = async () => {
27+
const hasTicket = await confirm({
2828
message: 'Has Ticket ?',
2929
initialValue: false,
30-
}) as Promise<boolean>
30+
})
31+
32+
if (!hasTicket) return
3133

32-
export const ticket = () =>
3334
text({
3435
message: 'Insert your Ticket name',
3536
validate: value => {
3637
if (value.length === 0) return 'Ticket name required'
3738
},
3839
}) as Promise<string>
40+
}

0 commit comments

Comments
 (0)