Skip to content

Commit 17d022b

Browse files
authored
Merge pull request #3 from jmaicaaan/feat/support-extending-commit-types
✨- feat: Support extending commit types
2 parents 20461e3 + ec718cc commit 17d022b

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

packages/core/src/types/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { App } from '../constants';
2+
import { CommitType } from './commitType';
23

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

56
export type Settings = {
67
workflow: App.BasicWorkflow | App.JiraWorkflow;
78
format?: string;
9+
commitTypes?: CommitType[],
810
jira: {
911
allowWorkflowTransitionPrompt: false;
1012
workflowTransitions: JiraWorkflowTransition[];

packages/vscode-ext/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,57 @@
5353
"description": "Set the commit format you wanted to use",
5454
"scope": "application"
5555
},
56+
"commitji.commitTypes": {
57+
"type": "array",
58+
"default": [],
59+
"description": "Extend the current commit types based on your needs",
60+
"items": {
61+
"type": "object",
62+
"title": "Extended Commit Types",
63+
"description": "Commit Type Properties",
64+
"properties": {
65+
"name": {
66+
"type": "string",
67+
"description": "Commit Type name",
68+
"examples": [
69+
"fix",
70+
"feat"
71+
]
72+
},
73+
"description": {
74+
"type": "string",
75+
"description": "The Commit Type description",
76+
"examples": [
77+
"A bug fix",
78+
"A new feature"
79+
]
80+
},
81+
"emoji": {
82+
"type": "object",
83+
"title": "The emoji to be used on the Commit Type",
84+
"description": "The name of the workflow with the hashtag",
85+
"properties": {
86+
"unicode": {
87+
"type": "string",
88+
"description": "The emoji unicode represnetation",
89+
"examples": [
90+
"🐛",
91+
""
92+
]
93+
},
94+
"shortcode": {
95+
"type": "string",
96+
"description": "The emoji shortcode represnetation",
97+
"examples": [
98+
":bug:",
99+
":sparkles:"
100+
]
101+
}
102+
}
103+
}
104+
}
105+
}
106+
},
56107
"commitji.jira.allowWorkflowTransitionPrompt": {
57108
"type": "boolean",
58109
"default": false,

packages/vscode-ext/src/commitjiCommit/utils/showCommitTypePicker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { QuickPickItem, window } from 'vscode';
22

3-
import { commitTypes, CommitType, Message } from '@commitji/core';
3+
import { commitTypes, CommitType, Message, Settings } from '@commitji/core';
44

55
type ShowCommitTypePickerResult = CommitType;
66

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

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

14-
const quickPickItems = commitTypes.map(commitTypeToQuickPickDisplay);
15+
const quickPickItems = mergedCommitTypes.map(commitTypeToQuickPickDisplay);
1516

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

3132
if (!commitTypeFromResult) {
3233
throw new Error(Message.Error.MissingCommitType);

packages/vscode-ext/src/commitjiCommit/workflows/basicWorkflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { formatter, basicCommitParser, Settings } from '@commitji/core';
33
import { showCommitTypePicker, showCommitBodyInputBox, writeCommitToTerminal } from '../utils';
44

55
export const basicWorkflow = async (settings: Settings) => {
6-
const commitType = await showCommitTypePicker();
6+
const commitType = await showCommitTypePicker(settings);
77
const commitMessage = await showCommitBodyInputBox();
88
const parser = basicCommitParser({
99
format: settings.format,

packages/vscode-ext/src/commitjiCommit/workflows/jiraWorkflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '../utils';
1010

1111
export const jiraWorkflow = async (settings: Settings) => {
12-
const commitType = await showCommitTypePicker();
12+
const commitType = await showCommitTypePicker(settings);
1313
const issueKey = await showJiraIssueKeyInputBox();
1414
const commitMessage = await showCommitBodyInputBox();
1515
const workflowTransition = await showJiraWorkflowTransitionPicker(

0 commit comments

Comments
 (0)