From 9311be80b2b47f3623902f04e17a540772b6b781 Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Mon, 21 Aug 2023 18:03:36 +0300 Subject: [PATCH 1/4] feat(commands): add commit message validation command (#4) --- src/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/index.ts b/src/index.ts index 71c4a13..868168f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -407,4 +407,37 @@ program ); }); +program + .command("validate") + .description("Validate whether a string fits given commit conventions") + .argument("[message]", "string for validation") + .action(async (string: string) => { + try { + const message = string || fs.readFileSync(0, "utf-8"); + + const config = await GetConfig(); + + // Regex for testing: + // /(build|feat|docs)(\((commands|changelog)\))?!?: .* ?(\(..*\))?((\n\n..*)?(\n\n..*)?)?/gm + + const testRegex = new RegExp( + `(${ + config?.types?.map((type) => type.value).join("|") || + "feat|fix|build|ci|docs|perf|refactor" + })(\\((${ + config?.scopes?.join("|") || "..*" + })\\))?!?: .* ?(\\(..*\\))?((\n\n..*)?(\n\n..*)?)?`, + "gm" + ); + + console.log( + testRegex.test(message) + ? "[rcz]: valid message" + : "[rcz]: invalid message" + ); + } catch (err) { + console.log("[rcz]: no stdin found"); + } + }); + program.parse(); -- 2.49.1 From 755da3bb57d6e236fe7e5b18785b08b3c1560d67 Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Mon, 21 Aug 2023 18:10:39 +0300 Subject: [PATCH 2/4] feat(commands): add ability to write a footer --- cspell.json | 2 ++ src/index.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index c8b5db3..7ad2c62 100644 --- a/cspell.json +++ b/cspell.json @@ -4,6 +4,8 @@ "dictionaryDefinitions": [], "dictionaries": [], "words": [ + "Acked", + "johndoe", "outro", "rczrc" ], diff --git a/src/index.ts b/src/index.ts index 868168f..c85c2d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -145,6 +145,15 @@ program process.exit(0); } + const footer = await text({ + message: `Insert commit footer, can be left empty, e.g. Acked-by: @johndoe`, + }); + + if (isCancel(footer)) { + cancel("Commit creation cancelled"); + process.exit(0); + } + const isBreaking = await confirm({ message: "Does this commit have breaking changes?", initialValue: false, @@ -178,7 +187,7 @@ program scope ? `(${scope.toString()})` : `` }${isBreaking ? "!" : ""}: ${message.toString()}${ resolvesIssue ? ` (${issue?.toString()})` : `` - }${body ? `\n\n${body}` : ``}`; + }${body ? `\n\n${body}` : ``}${footer ? `\n\n${footer}` : ``}`; if (stageAll) { await simpleGit() -- 2.49.1 From f3c55fac309b8fda08ad3153676f538f4ba90fe8 Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Mon, 21 Aug 2023 18:11:10 +0300 Subject: [PATCH 3/4] chore(release): v1.3.0 --- package.json | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aef811b..9785910 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@resultium/rcz", - "version": "1.2.0", + "version": "1.3.0", "description": "Resultium commit standardization library, based on conventional commits", "main": "./dist/index.js", "bin": { diff --git a/src/index.ts b/src/index.ts index c85c2d9..ba17731 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,7 @@ const program = new Command(); program .name("rcz") .description("Resultium commit standardization command-line interface") - .version("1.0.0"); + .version("1.3.0"); program .command("commit") -- 2.49.1 From 45458d14e26f55130060e7b52b540b9fd4433c99 Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Mon, 21 Aug 2023 18:12:59 +0300 Subject: [PATCH 4/4] docs(changelog): generate for v1.3.0 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb63bc..b1a05a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ Generation of this changelog is based on commits +## v1.3.0 + +### Features + +- [755da3bb5] - **commands**: add ability to write a footer +- [9311be80b] - **commands**: add commit message validation command (#4) + ## v1.2.0 ### Features -- 2.49.1