From 3a6460a37cd6e95cd6e912341ea963f266ed24a3 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:16:39 +0200 Subject: [PATCH 1/3] feat: add _joinWithColonTitlecase function --- src/prepareCommitMsg.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/prepareCommitMsg.ts b/src/prepareCommitMsg.ts index 145076a..47d6e85 100644 --- a/src/prepareCommitMsg.ts +++ b/src/prepareCommitMsg.ts @@ -39,12 +39,28 @@ export function _joinWithSpace(first: string, second: string) { } /** - * Join two strings using a colon and space. + * Join two strings using a colon and a space. + * + * @returns Value like 'abc: def'. */ export function _joinWithColon(first: string, second: string): string { return `${first}: ${second}`; } +/** + * Join two strings using a colon and a space and the second as titlecase. + * + * Using titlecase is not standard in the Conventional Commit convention, but + * some users will prefer this style. + * + * @returns Value like 'abc: Def'. + */ +export function _joinWithColonTitlecase(first: string, second: string): string { + second = `${second[0].toUpperCase()}${second.slice(1)}` + + return _joinWithColon(first, second) +} + /** * Determine the Conventional Commit type prefix for a file change. * From 051b59be6776ff4254dd75f6e2d12c465c514e24 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:39:21 +0200 Subject: [PATCH 2/3] build: update package.json --- package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package.json b/package.json index 7514715..db93016 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,16 @@ "group": "navigation" } ] + }, + "configuration": { + "title": "Auto Commit Msg", + "properties": { + "autoCommitMsg.useTitlecaseDescription": { + "type": "boolean", + "default": false, + "description": "Convert description to start with a capital letter" + } + } } } } From 15eb2c01e36c3e07bd2a8041192663e804639298 Mon Sep 17 00:00:00 2001 From: Michael Currin <18750745+MichaelCurrin@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:40:10 +0200 Subject: [PATCH 3/3] feat: add use of configuration for titlecase --- src/prepareCommitMsg.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/prepareCommitMsg.ts b/src/prepareCommitMsg.ts index 47d6e85..c57e0ce 100644 --- a/src/prepareCommitMsg.ts +++ b/src/prepareCommitMsg.ts @@ -10,6 +10,7 @@ * This module doesn't interact with the git CLI or the extension. It just deals * with text. */ +import * as vscode from "vscode"; import { lookupDiffIndexAction } from "./generate/action"; import { getConventionType } from "./generate/convCommit"; import { countFilesDesc } from "./generate/count"; @@ -38,27 +39,32 @@ export function _joinWithSpace(first: string, second: string) { return `${first} ${second}`.trim(); } +/** Return configuration value for whether titlecase must be used. */ +export function _mustUseTitlecase(): boolean { + const ws = vscode.workspace.getConfiguration('autoCommitMsg') + + return ws.get('useTitlecaseDescription') ?? false +} + /** - * Join two strings using a colon and a space. - * - * @returns Value like 'abc: def'. + * Capitalize first letter. */ -export function _joinWithColon(first: string, second: string): string { - return `${first}: ${second}`; +export function _titlecase(value: string): string { + return `${value[0].toUpperCase()}${value.slice(1)}` } /** - * Join two strings using a colon and a space and the second as titlecase. - * - * Using titlecase is not standard in the Conventional Commit convention, but - * some users will prefer this style. + * Join two strings using a colon and a space. * - * @returns Value like 'abc: Def'. + * @returns Value like 'abc: def'. */ -export function _joinWithColonTitlecase(first: string, second: string): string { - second = `${second[0].toUpperCase()}${second.slice(1)}` +export function _joinWithColon(first: string, second: string): string { + const useTitlecase = _mustUseTitlecase() + if (useTitlecase) { + second = _titlecase(second) + } - return _joinWithColon(first, second) + return `${first}: ${second}`; } /**