Skip to content

Commit

Permalink
feat: add scope template placeholder (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
axelprox authored and nitayneeman committed Oct 25, 2019
1 parent 8644829 commit 610a3fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"default": "--quiet",
"markdownDescription": "Specifies which [arguments](https://git-scm.com/docs/git-commit#_options) to be passed when the commit is executed."
},
"gitSemanticCommit.scopeTemplate": {
"type": "string",
"default": "($scope)",
"markdownDescription": "Specifies scope template (`$scope` placeholder will be replaced with passed scope)"
},
"gitSemanticCommit.preserveScope": {
"type": "boolean",
"default": false,
Expand Down
9 changes: 7 additions & 2 deletions src/commands/semantic-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { window, workspace, ExtensionContext, QuickPickItem } from 'vscode';

import { getConfiguration, ConfigurationProperties } from '../config';
import { Git } from '../git';
import { workspaceStorageKey } from '../constants';
import { workspaceStorageKey, scopeTemplatePlaceholder } from '../constants';
import { Command } from './common';

const enum ActionType {
Expand Down Expand Up @@ -75,6 +75,11 @@ export class SemanticCommitCommand extends Command {
return getConfiguration()[ConfigurationProperties.stageAll];
}

private get scopeTemplate() {
const template = getConfiguration()[ConfigurationProperties.scopeTemplate];
return template.length ? template : scopeTemplatePlaceholder;
}

private hasScope() {
return this.scope.length > 0;
}
Expand Down Expand Up @@ -129,7 +134,7 @@ export class SemanticCommitCommand extends Command {

private async performCommit(type: string, subject: string) {
if (subject.length > 0) {
const message = `${type}${this.hasScope() ? `(${this.scope})` : ''}: ${subject}`;
const message = `${type}${this.hasScope() ? this.scopeTemplate.replace(scopeTemplatePlaceholder, this.scope) : ''}: ${subject}`;

if (this.isStageAllEnabled()) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum ConfigurationProperties {
commitOptions = 'commitOptions',
preserveScope = 'preserveScope',
stageAll = 'stageAll',
scopeTemplate = 'scopeTemplate',
types = 'types'
}

Expand Down
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ const extensionIdentifier = 'gitSemanticCommit';

const workspaceStorageKey = 'gitSemanticCommit';

export { extensionIdentifier, workspaceStorageKey };
const scopeTemplatePlaceholder = '$scope';

export { extensionIdentifier, workspaceStorageKey, scopeTemplatePlaceholder };

0 comments on commit 610a3fc

Please sign in to comment.