feat(commands): warn on >250 line commits, improve text (#13)

This commit is contained in:
2023-12-17 17:18:41 +02:00
parent f371102a8a
commit 83d6559317
2 changed files with 33 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
"cSpell.words": [
"Acked",
"johndoe",
"numstat",
"onrelease",
"outro",
"postrelease",

View File

@@ -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)) {