Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add titlecase description option #81

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
24 changes: 23 additions & 1 deletion src/prepareCommitMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}`;
}

Expand Down