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

Commit

Permalink
feat(footer): add ability for custom footer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjakos authored and KnisterPeter committed Oct 15, 2018
1 parent 9b172b9 commit 5d06c7a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
await ccm.getSubject();
await ccm.getBody();
await ccm.getBreaking();
await ccm.getCloses();
await ccm.getFooter();
if (ccm.complete && vscode.workspace.workspaceFolders) {
await commit(vscode.workspace.workspaceFolders[0].uri.fsPath, ccm.message.trim());
}
Expand All @@ -57,6 +57,7 @@ interface CzConfig {
};
allowCustomScopes: boolean;
allowBreakingChanges: string[];
footerPrefix: string;
}

async function readCzConfig(): Promise<CzConfig|undefined> {
Expand Down Expand Up @@ -93,7 +94,7 @@ 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): Promise<boolean> {
const pickOptions: vscode.QuickPickOptions = {
placeHolder: question,
ignoreFocusOut: true,
Expand All @@ -109,7 +110,7 @@ async function askOneOf(question: string, picks: vscode.QuickPickItem[],
}

async function ask(question: string, save: (input: string) => void,
validate?: (input: string) => string): Promise<boolean> {
validate?: (input: string) => string): Promise<boolean> {
const options: vscode.InputBoxOptions = {
placeHolder: question,
ignoreFocusOut: true
Expand Down Expand Up @@ -243,7 +244,7 @@ class ConventionalCommitMessage {
private subject: string;
private body: string|undefined;
private breaking: string|undefined;
private closes: string|undefined;
private footer: string|undefined;

constructor(czConfig: CzConfig|undefined) {
this.czConfig = czConfig;
Expand Down Expand Up @@ -305,10 +306,10 @@ class ConventionalCommitMessage {
}
}

public async getCloses(): Promise<void> {
public async getFooter(): Promise<void> {
if (this.next) {
this.next = await ask(this.inputMessage('footer'),
input => this.closes = input);
input => this.footer = input);
}
}

Expand All @@ -322,7 +323,15 @@ class ConventionalCommitMessage {
(typeof this.scope === 'string' && this.scope ? `(${this.scope})` : '') +
`: ${this.subject}\n\n${this.body}\n\n` +
(this.breaking ? `BREAKING CHANGE: ${this.breaking}\n` : '') +
(this.closes ? `Closes ${this.closes}` : '');
this.messageFooter();
}

private messageFooter(): string {
return this.footer
? `${this.czConfig && this.czConfig.footerPrefix ? this.czConfig.footerPrefix : 'Closes '}${
this.footer
}`
: '';
}

private inputMessage(messageType: string): string {
Expand Down

0 comments on commit 5d06c7a

Please sign in to comment.