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" + } + } } } } diff --git a/src/prepareCommitMsg.ts b/src/prepareCommitMsg.ts index 145076a..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,10 +39,31 @@ 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 +} + +/** + * Capitalize first letter. + */ +export function _titlecase(value: string): string { + return `${value[0].toUpperCase()}${value.slice(1)}` +} + /** - * 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 { + const useTitlecase = _mustUseTitlecase() + if (useTitlecase) { + second = _titlecase(second) + } + return `${first}: ${second}`; }