Skip to content

Commit

Permalink
🩹 fix(prompt): use better ai prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannchie committed Sep 13, 2023
1 parent c67eabb commit 2fc18e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface CommitMessageData {
message: string
}

export async function generateByAI(config: Config, type: string, scope: string, message: string) {
export async function generateByAI(config: Config, type: string, scope: string) {
const typeList = Object.keys(config.data)
const verbose = config.verbose
const s = spinner()
Expand Down Expand Up @@ -96,7 +96,7 @@ Based on the information above, type, scope and message respectively:
scope = data.scope.toLowerCase()
if (type === '')
type = data.type.toLowerCase()
message = data.message
let message = data.message
message = message[0].toLowerCase() + message.slice(1)
const cmd = getCMD({ type, scope, body: message, icon: config.showIcon ? config.data[type].emoji : '' })
s.stop('Generated')
Expand All @@ -108,6 +108,7 @@ Based on the information above, type, scope and message respectively:
}
if (config.dryRun) {
log.info(`Dry run: ${cmd}`)
process.exit(0)
}
else {
await new Promise<void>((resolve, reject) => {
Expand All @@ -121,6 +122,7 @@ Based on the information above, type, scope and message respectively:
resolve()
})
})
process.exit(0)
}
}
catch (e) {
Expand Down
16 changes: 6 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ program
.option('-no-i, --no-icon', 'Do not show icon')
.option('-v, --verbose', 'Verbose mode')
.version(`v${version}`, '-V, --version', 'Output the current version')
.arguments('[type] [body|scope] [body]').action(async (type, scope = '', body = '') => {
.arguments('[type] [body|scope] [body]').action(async (type = '', scope = '', body = '') => {
const options = program.opts()
if (body === '') {
body = scope
scope = ''
}
if (!type)
type = ''
config.showIcon = !options.noIcon
config.verbose = options.verbose
config.ai.enabled = options.ai
Expand All @@ -57,9 +51,13 @@ program
intro(`@gitcm/cli - v${version}`)
if (config.ai.enabled) {
checkAI()
await generateByAI(config, type, scope, body)
await generateByAI(config, type, scope)
}
else {
if (body === '') {
body = scope
scope = ''
}
await waitPrompt(config, type, scope, body)
}
})
Expand Down Expand Up @@ -147,8 +145,6 @@ function isType(key: string) {
}

async function waitPrompt(config: Config, type: string, scope: string, body: string) {
intro(`@gitcm/cli - v${version}`)

if (type !== '' && !isType(type)) {
log.error(`Invalid commit type: ${type}. ` + `Commit type must be one of ${typeList.join(', ')}`)
process.exit(1)
Expand Down

0 comments on commit 2fc18e2

Please sign in to comment.