diff --git a/.vscode/settings.json b/.vscode/settings.json index 08c5157..b1a21ff 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "Acked", "johndoe", + "numstat", "onrelease", "outro", "postrelease", diff --git a/src/index.ts b/src/index.ts index 817142a..1f69fd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,6 +80,25 @@ program process.exit(0); } + const changedLines = ( + ( + await simpleGit().diff(["--numstat", stageAll ? "HEAD" : "--cached"]) + ).match(/\d+/gm) || [] + ).reduce((partialSum, num) => partialSum + Number(num), 0); + + if (changedLines > 250) { + const proceedCommitting = await confirm({ + message: + "You are about to commit changes to more than 250 lines, are you sure you want to proceed?", + initialValue: false, + }); + + if (isCancel(proceedCommitting)) { + cancel("Commit creation cancelled"); + process.exit(0); + } + } + const type: string | symbol = await select({ message: "Choose a commit type", options: config?.types || [ @@ -91,7 +110,7 @@ program { label: "fix", value: "fix", - hint: "bug fix", + hint: "functionality bug fix", }, { label: "build", @@ -132,12 +151,18 @@ program } const scope: string | symbol = await text({ - message: "Input a scope (e.g. router, forms, core) or leave empty", + message: + "Input a scope (subsystem which change is relevant to e.g. router, forms, core) or leave empty", + placeholder: "router", validate: (value) => { if (config?.scopes && value) { if (!config?.scopes.includes(value)) return "This scope is not allowed by local configuration"; } + + if (value.includes(" ")) { + return "Must not include a space"; + } }, }); @@ -148,6 +173,7 @@ program const message = await text({ message: `Briefly describe made changes in imperative tense, maximum length 50`, + placeholder: "warn upon suspicious router requests", validate: (value) => { if (value.length > 50) { return "Your message is too long"; @@ -161,7 +187,9 @@ program } const body = await text({ - message: `Insert a commit body, recommended length 100, can be left empty`, + message: `Insert a commit body (motivation or elaboration for the change), can be left empty`, + placeholder: + "improves regex for suspicious character check in router requests", }); if (isCancel(body)) { @@ -171,6 +199,7 @@ program const footer = await text({ message: `Insert commit footer, can be left empty, e.g. Acked-by: @johndoe`, + placeholder: "Acked-by: @security", }); if (isCancel(footer)) {