feat(commands): warn on >250 line commits, improve text (#13)
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -2,6 +2,7 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"Acked",
|
"Acked",
|
||||||
"johndoe",
|
"johndoe",
|
||||||
|
"numstat",
|
||||||
"onrelease",
|
"onrelease",
|
||||||
"outro",
|
"outro",
|
||||||
"postrelease",
|
"postrelease",
|
||||||
|
|||||||
35
src/index.ts
35
src/index.ts
@@ -80,6 +80,25 @@ program
|
|||||||
process.exit(0);
|
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({
|
const type: string | symbol = await select({
|
||||||
message: "Choose a commit type",
|
message: "Choose a commit type",
|
||||||
options: config?.types || [
|
options: config?.types || [
|
||||||
@@ -91,7 +110,7 @@ program
|
|||||||
{
|
{
|
||||||
label: "fix",
|
label: "fix",
|
||||||
value: "fix",
|
value: "fix",
|
||||||
hint: "bug fix",
|
hint: "functionality bug fix",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "build",
|
label: "build",
|
||||||
@@ -132,12 +151,18 @@ program
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scope: string | symbol = await text({
|
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) => {
|
validate: (value) => {
|
||||||
if (config?.scopes && value) {
|
if (config?.scopes && value) {
|
||||||
if (!config?.scopes.includes(value))
|
if (!config?.scopes.includes(value))
|
||||||
return "This scope is not allowed by local configuration";
|
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({
|
const message = await text({
|
||||||
message: `Briefly describe made changes in imperative tense, maximum length 50`,
|
message: `Briefly describe made changes in imperative tense, maximum length 50`,
|
||||||
|
placeholder: "warn upon suspicious router requests",
|
||||||
validate: (value) => {
|
validate: (value) => {
|
||||||
if (value.length > 50) {
|
if (value.length > 50) {
|
||||||
return "Your message is too long";
|
return "Your message is too long";
|
||||||
@@ -161,7 +187,9 @@ program
|
|||||||
}
|
}
|
||||||
|
|
||||||
const body = await text({
|
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)) {
|
if (isCancel(body)) {
|
||||||
@@ -171,6 +199,7 @@ program
|
|||||||
|
|
||||||
const footer = await text({
|
const footer = await text({
|
||||||
message: `Insert commit footer, can be left empty, e.g. Acked-by: @johndoe`,
|
message: `Insert commit footer, can be left empty, e.g. Acked-by: @johndoe`,
|
||||||
|
placeholder: "Acked-by: @security",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isCancel(footer)) {
|
if (isCancel(footer)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user