Skip to content

Commit

Permalink
💡 feat: add commit description input
Browse files Browse the repository at this point in the history
this is for those who needs description
  • Loading branch information
unickowl committed Feb 29, 2024
1 parent cd897e7 commit b39853c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
38 changes: 28 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
const config = fs.readFileSync(`${__dirname}/cz_config.json`)
defaultProjectValue = JSON.parse(config).defaultProject
} catch (e) {
console.log(picocolors.yellow(' 💡 You can try `cz -i` to choose a default project prefix. '))
console.log(picocolors.yellow(picocolors.italic(' 💡 You can try `cz -i` to choose a default project prefix. ')))
defaultProjectValue = ''
}

Expand Down Expand Up @@ -45,6 +45,19 @@ const step_message = {
}
}

const step_description = {
type: 'text',
name: 'commit_description',
message: 'Commit description (optional)',
initial: '',
validate: value => {
if (value.length > 100) {
return 'Description is too long.'
}
return true
}
}

const step_is_jira = {
type: 'confirm',
name: 'is_jira',
Expand Down Expand Up @@ -86,7 +99,7 @@ const step_jira_id = {
name: 'jira_id',
message: 'Jira issue id',
onRender () {
this.msg = picocolors.bgBlueBright.white(' Jira issue ID ')
this.msg = picocolors.bgCyan(picocolors.white(' Jira issue ID '))
},
validate: value => {
if (!value) {
Expand All @@ -101,6 +114,7 @@ module.exports = async () => {
const order = [
step_type,
step_message,
step_description,
step_is_jira,
defaultProject.value ? step_is_default_project : null,
step_project_type,
Expand All @@ -124,18 +138,19 @@ module.exports = async () => {
return false
}

const { commit_type, commit_message, is_jira, is_default_project, project_type, jira_id } = response
const { commit_type, commit_message, commit_description, is_jira, is_default_project, project_type, jira_id } = response
const type = typesList.find(type => type.value === commit_type)
const msg = `${type.emoji} ${commit_type}: ${commit_message}`
const commitTitle = `${type.emoji} ${commit_type}: ${commit_message}`
const typeResponse = is_default_project ? defaultProject.value : project_type
const projectType = projects.find(project => project.value === typeResponse)
const result = is_jira
? `[${projectType.prefix}-${jira_id}] ${msg}`
: msg
? `[${projectType.prefix}-${jira_id}] ${commitTitle}`
: commitTitle

try {
const commitResult = await execa('git', ['commit', '-m', result])
const branchHashName = commitResult.stdout.match(/\[(.*)\]/).pop()
const commands = commit_description ? ['commit', '-m', result, '-m', commit_description] : ['commit', '-m', result]
const commitResult = await execa('git', commands)
const branchHashName = commitResult.stdout.match(/\[(.*?)\]/).pop()
const [branchName, branchHash] = branchHashName.split(' ')
console.log('-----------------------------------------------------------')
console.log(picocolors.dim(commitResult.stdout))
Expand All @@ -144,8 +159,11 @@ module.exports = async () => {
console.log(picocolors.dim(commitResult.stderr))
}
console.log('-----------------------------------------------------------')
console.log(picocolors.green(result))
console.log(picocolors.bold(branchName), picocolors.bgCyan(` ${branchHash} `))
console.log(`${picocolors.bgGreen(picocolors.bold(' Title '))} ${picocolors.green(result)}`)
if (commit_description) {
console.log(`${picocolors.bgGreen(picocolors.bold(' Description '))} ${picocolors.green(commit_description)}`)
}
console.log(`${picocolors.bgGreen(picocolors.bold(' Commit hash '))} ${picocolors.bold(picocolors.cyan(` ${branchHash} `))} (${picocolors.italic(picocolors.green(branchName))})`)
} catch (error) {
console.log(picocolors.red(error.stderr))
if (error.exitCode === 1) console.log(picocolors.bgRed(' No changes added to commit. '))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "owlting_cz",
"version": "2.1.0",
"version": "2.2.0",
"description": "create-commit for OwlTing",
"dependencies": {
"execa": "^5.1.1",
Expand Down

0 comments on commit b39853c

Please sign in to comment.