Skip to content

Commit

Permalink
Merge pull request #3 from jmaicaaan/feat/support-extending-commit-types
Browse files Browse the repository at this point in the history
✨- feat: Support extending commit types
  • Loading branch information
jmaicaaan authored Apr 27, 2020
2 parents 20461e3 + ec718cc commit 17d022b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { App } from '../constants';
import { CommitType } from './commitType';

export type JiraWorkflowTransition = Record<'key' | 'label' | 'workflowTransitionName', string>;

export type Settings = {
workflow: App.BasicWorkflow | App.JiraWorkflow;
format?: string;
commitTypes?: CommitType[],
jira: {
allowWorkflowTransitionPrompt: false;
workflowTransitions: JiraWorkflowTransition[];
Expand Down
51 changes: 51 additions & 0 deletions packages/vscode-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,57 @@
"description": "Set the commit format you wanted to use",
"scope": "application"
},
"commitji.commitTypes": {
"type": "array",
"default": [],
"description": "Extend the current commit types based on your needs",
"items": {
"type": "object",
"title": "Extended Commit Types",
"description": "Commit Type Properties",
"properties": {
"name": {
"type": "string",
"description": "Commit Type name",
"examples": [
"fix",
"feat"
]
},
"description": {
"type": "string",
"description": "The Commit Type description",
"examples": [
"A bug fix",
"A new feature"
]
},
"emoji": {
"type": "object",
"title": "The emoji to be used on the Commit Type",
"description": "The name of the workflow with the hashtag",
"properties": {
"unicode": {
"type": "string",
"description": "The emoji unicode represnetation",
"examples": [
"🐛",
""
]
},
"shortcode": {
"type": "string",
"description": "The emoji shortcode represnetation",
"examples": [
":bug:",
":sparkles:"
]
}
}
}
}
}
},
"commitji.jira.allowWorkflowTransitionPrompt": {
"type": "boolean",
"default": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { QuickPickItem, window } from 'vscode';

import { commitTypes, CommitType, Message } from '@commitji/core';
import { commitTypes, CommitType, Message, Settings } from '@commitji/core';

type ShowCommitTypePickerResult = CommitType;

const findCommitTypeByName = (name: string) => (commitType: CommitType) => commitType.name === name;

export const showCommitTypePicker = async (): Promise<ShowCommitTypePickerResult> => {
export const showCommitTypePicker = async (settings: Settings): Promise<ShowCommitTypePickerResult> => {
const commitTypeToQuickPickDisplay = (commitType: CommitType): QuickPickItem => ({
label: [commitType.emoji.unicode, commitType.name, '-', commitType.description].join(' '),
});
const mergedCommitTypes = [...commitTypes, ...settings.commitTypes];

const quickPickItems = commitTypes.map(commitTypeToQuickPickDisplay);
const quickPickItems = mergedCommitTypes.map(commitTypeToQuickPickDisplay);

const result = await window.showQuickPick(quickPickItems, {
placeHolder: 'What type of task did you do?',
Expand All @@ -26,7 +27,7 @@ export const showCommitTypePicker = async (): Promise<ShowCommitTypePickerResult
const [commitTypeWithEmojiUnicode] = result.label.split('-');
const [, commitTypeName] = commitTypeWithEmojiUnicode.split(' ');
const commitTypeFromTheResult = findCommitTypeByName(commitTypeName);
const commitTypeFromResult = commitTypes.find(commitTypeFromTheResult);
const commitTypeFromResult = mergedCommitTypes.find(commitTypeFromTheResult);

if (!commitTypeFromResult) {
throw new Error(Message.Error.MissingCommitType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatter, basicCommitParser, Settings } from '@commitji/core';
import { showCommitTypePicker, showCommitBodyInputBox, writeCommitToTerminal } from '../utils';

export const basicWorkflow = async (settings: Settings) => {
const commitType = await showCommitTypePicker();
const commitType = await showCommitTypePicker(settings);
const commitMessage = await showCommitBodyInputBox();
const parser = basicCommitParser({
format: settings.format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../utils';

export const jiraWorkflow = async (settings: Settings) => {
const commitType = await showCommitTypePicker();
const commitType = await showCommitTypePicker(settings);
const issueKey = await showJiraIssueKeyInputBox();
const commitMessage = await showCommitBodyInputBox();
const workflowTransition = await showJiraWorkflowTransitionPicker(
Expand Down

0 comments on commit 17d022b

Please sign in to comment.