Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix(commit): custom scope with scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Maqix authored and KnisterPeter committed Oct 26, 2018
1 parent b04e921 commit 0316fc5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ function hasCzConfig(pkg: any): pkg is { config: { 'cz-customizable': { config:
}

async function askOneOf(question: string, picks: vscode.QuickPickItem[],
save: (pick: vscode.QuickPickItem) => void): Promise<boolean> {
save: (pick: vscode.QuickPickItem) => void, customLabel?: string, customQuestion?: string): Promise<boolean> {
const pickOptions: vscode.QuickPickOptions = {
placeHolder: question,
ignoreFocusOut: true,
matchOnDescription: true,
matchOnDetail: true
};
const pick = await vscode.window.showQuickPick(picks, pickOptions);
if (pick && pick.label === customLabel && !!customQuestion) {
const next = await ask(customQuestion || "", input => {
save({label: input, description: ''})
return true
});
return next;
}
if (pick === undefined) {
return false;
}
Expand Down Expand Up @@ -172,6 +179,7 @@ const DEFAULT_TYPES = [
const DEFAULT_MESSAGES = {
type: 'Select the type of change that you\'re committing',
customScope: 'Denote the SCOPE of this change',
customScopeEntry: 'Custom scope...',
scope: 'Denote the SCOPE of this change (optional)',
subject: 'Write a SHORT, IMPERATIVE tense description of the change',
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line',
Expand Down Expand Up @@ -228,8 +236,7 @@ async function hasStagedFiles(cwd: string): Promise<boolean> {
class ConventionalCommitMessage {

private static hasScopes(czConfig: CzConfig|undefined): czConfig is CzConfig {
return Boolean(czConfig && (!czConfig.allowCustomScopes ||
czConfig.scopes && czConfig.scopes.length === 0));
return Boolean(czConfig && czConfig.scopes && czConfig.scopes.length !== 0);
}

private static hasCustomMessage(czConfig: CzConfig|undefined, messageType: string ): czConfig is CzConfig {
Expand Down Expand Up @@ -270,8 +277,17 @@ class ConventionalCommitMessage {
label: scope.name || scope as string,
description: ''
}));
if (this.czConfig.allowCustomScopes) {
scopePicks.push({
label: this.inputMessage('customScopeEntry'),
description: ''
})
}
this.next = await askOneOf(this.inputMessage('customScope'), scopePicks,
pick => this.scope = pick.label || undefined);
pick => {
this.scope = pick.label || undefined
},
this.inputMessage('customScopeEntry'), this.inputMessage('customScope'));
}
} else {
this.next = await ask(this.inputMessage('scope'), input => this.scope = input);
Expand Down

0 comments on commit 0316fc5

Please sign in to comment.