Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to skip ci run #213

Merged
merged 9 commits into from
Dec 17, 2021
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ You can access VSCode Conventional Commits in two ways:

### Extension Configuration

| name | description | default |
| :----------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-----: |
| `conventionalCommits.autoCommit` | Control whether the extension should commit files after: forming the message or closing the editor tab.<br>When `#git.enableSmartCommit#` enabled and `#git.smartCommitChanges#` was set to `all`, It allows to commit all changes when there are no staged changes.<br>And set `#git.postCommitCommand#` to `sync` to run `git.sync` after commit. | true |
| `conventionalCommits.emojiFormat` | Specify which format will be shown in the `gitmoji`. | code |
| `conventionalCommits.gitmoji` | Control whether the extension should prompt for a `gitmoji`. | true |
| `conventionalCommits.lineBreak` | Specify which word will be treated as line breaks in the `body`.<br>Blank means no line breaks. | "" |
| `conventionalCommits.promptBody` | Control whether the extension should prompt for the `body` section. | true |
| `conventionalCommits.promptFooter` | Control whether the extension should prompt for the `footer` section. | true |
| `conventionalCommits.promptScopes` | Control whether the extension should prompt for the `scope` section. | true |
| `conventionalCommits.scopes` | Specify available selections in the `scope` section. | [] |
| `conventionalCommits.showEditor` | Control whether the extension should show the commit message as a text document in a separate tab. | false |
| `conventionalCommits.showNewVersionNotes` | Control whether the extension should show the new version notes. | true |
| `conventionalCommits.editor.keepAfterSave` | Control whether the extension should keep the editor tab open after saving the commit message. | false |
| name | description | default |
| :----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------ |
| `conventionalCommits.autoCommit` | Control whether the extension should commit files after: forming the message or closing the editor tab.<br>When `#git.enableSmartCommit#` enabled and `#git.smartCommitChanges#` was set to `all`, It allows to commit all changes when there are no staged changes.<br>And set `#git.postCommitCommand#` to `sync` to run `git.sync` after commit. | true |
| `conventionalCommits.emojiFormat` | Specify which format will be shown in the `gitmoji`. | code |
| `conventionalCommits.gitmoji` | Control whether the extension should prompt for a `gitmoji`. | true |
| `conventionalCommits.lineBreak` | Specify which word will be treated as line breaks in the `body`.<br>Blank means no line breaks. | "" |
| `conventionalCommits.promptBody` | Control whether the extension should prompt for the `body` section. | true |
| `conventionalCommits.promptFooter` | Control whether the extension should prompt for the `footer` section. | true |
| `conventionalCommits.promptCI` | Control whether the extension should prompt for skipping CI run. | false |
| `conventionalCommits.promptScopes` | Control whether the extension should prompt for the `scope` section. | true |
| `conventionalCommits.scopes` | Specify available selections in the `scope` section. | [] |
| `conventionalCommits.showEditor` | Control whether the extension should show the commit message as a text document in a separate tab. | false |
| `conventionalCommits.showNewVersionNotes` | Control whether the extension should show the new version notes. | true |
| `conventionalCommits.editor.keepAfterSave` | Control whether the extension should keep the editor tab open after saving the commit message. | false |

## Commit Workflow

Expand Down Expand Up @@ -156,15 +157,18 @@ Or `\\n` in JSON format.

## Financial Contributors

Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/vscode-conventional-commits/contribute)]
Become a financial contributor and help us sustain our community.
[[Contribute](https://opencollective.com/vscode-conventional-commits/contribute)]

### Individuals

<a href="https://opencollective.com/vscode-conventional-commits"><img src="https://opencollective.com/vscode-conventional-commits/individuals.svg?width=890"></a>

### Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/vscode-conventional-commits/contribute)]
Support this project with your organization. Your logo will show up here with a
link to your website.
[[Contribute](https://opencollective.com/vscode-conventional-commits/contribute)]

<a href="https://opencollective.com/vscode-conventional-commits"><img src="https://opencollective.com/vscode-conventional-commits/organization.svg?width=890"></a>

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
"default": true,
"markdownDescription": "%extension.configuration.promptBody.markdownDescription%"
},
"conventionalCommits.promptCI": {
"type": "boolean",
"default": false,
"markdownDescription": "%extension.configuration.promptCI.markdownDescription%"
},
"conventionalCommits.promptFooter": {
"type": "boolean",
"default": true,
Expand Down
6 changes: 6 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"extension.configuration.promptBody.markdownDescription": "Control whether the extension should prompt for the `body` section.",
"extension.configuration.promptFooter.markdownDescription": "Control whether the extension should prompt for the `footer` section.",
"extension.configuration.promptScopes.markdownDescription": "Control whether the extension should prompt for the `scope` section.",
"extension.configuration.promptCI.markdownDescription": "Control whether the extension should prompt for skipping CI run.",
"extension.configuration.scopes.markdownDescription": "Specify available selections in the `scope` section.",
"extension.configuration.showEditor.markdownDescription": "Control whether the extension should show the commit message as a text document in a separate tab.",
"extension.configuration.showNewVersionNotes.markdownDescription": "Control whether the extension should show the new version notes.",
Expand All @@ -34,6 +35,11 @@
"extension.sources.prompt.gitmoji.noneItem.label": "None",
"extension.sources.prompt.gitmoji.noneItem.detail": "No gitmoji.",
"extension.sources.prompt.subject.placeholder": "Write a short, imperative tense description of the change.",
"extension.sources.prompt.ci.accept.label": "Yes",
"extension.sources.prompt.ci.decline.label": "No",
"extension.sources.prompt.ci.accept.detail": "Avoid running CI worflow.",
"extension.sources.prompt.ci.decline.detail": "Run CI workflow if available.",
"extension.sources.prompt.ci.placeholder": "Choose do you want to skip CI run.",
"extension.sources.prompt.subject.error.including": "including ",
"extension.sources.prompt.subject.error.type": "type: ",
"extension.sources.prompt.subject.error.scope": "scope: ",
Expand Down
6 changes: 6 additions & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"extension.configuration.promptBody.markdownDescription": "是否需要填写 `body`。",
"extension.configuration.promptFooter.markdownDescription": "是否需要填写 `footer`。",
"extension.configuration.promptScopes.markdownDescription": "是否需要填写 `scope`。",
"extension.configuration.promptCI.markdownDescription": "是否需要提示“跳过 CI 工作流”。",
"extension.configuration.scopes.markdownDescription": "指定 `scope` 中的可选项。",
"extension.configuration.showEditor.markdownDescription": "是否需要在新标签页用文本编辑器展示提交信息",
"extension.configuration.showNewVersionNotes.markdownDescription": "是否需要显示新版本说明。",
Expand All @@ -34,6 +35,11 @@
"extension.sources.prompt.gitmoji.noneItem.label": "无",
"extension.sources.prompt.gitmoji.noneItem.detail": "无 gitmoji。",
"extension.sources.prompt.subject.placeholder": "请填写描述。",
"extension.sources.prompt.ci.accept.label": "是",
"extension.sources.prompt.ci.decline.label": "否",
"extension.sources.prompt.ci.accept.detail": "跳过 CI 工作流。",
"extension.sources.prompt.ci.decline.detail": "如果可用,则执行 CI 工作流。",
"extension.sources.prompt.ci.placeholder": "选择是否要跳过 CI 工作流。",
"extension.sources.prompt.subject.error.including": "包括",
"extension.sources.prompt.subject.error.type": "类型:",
"extension.sources.prompt.subject.error.scope": "作用域:",
Expand Down
15 changes: 14 additions & 1 deletion src/lib/commit-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class CommitMessage {
private _subject: string = '';
private _body: string = '';
private _footer: string = '';
private _ci: string = '';

get type() {
return this._type;
Expand Down Expand Up @@ -57,6 +58,14 @@ export class CommitMessage {
set footer(input: string) {
this._footer = input.trim();
}

get ci() {
return this._ci;
}

set ci(input: string) {
this._ci = input.trim();
}
}

export function serializeSubject(partialCommitMessage: {
Expand All @@ -78,14 +87,15 @@ export function serializeSubject(partialCommitMessage: {
}

export function serializeHeader(partialCommitMessage: {
ci: string;
type: string;
scope: string;
gitmoji: string;
subject: string;
}) {
let result = '';
result += partialCommitMessage.type;
const { scope } = partialCommitMessage;
const { scope, ci } = partialCommitMessage;
if (scope) {
result += `(${scope})`;
}
Expand All @@ -94,6 +104,9 @@ export function serializeHeader(partialCommitMessage: {
if (subject) {
result += subject;
}
if (ci === 'Yes') {
result += ' [skip ci]';
}
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Configuration = {
promptScopes: boolean;
promptBody: boolean;
promptFooter: boolean;
promptCI: boolean;
showNewVersionNotes: boolean;
'editor.keepAfterSave': boolean;
};
Expand Down
1 change: 1 addition & 0 deletions src/lib/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default function createConventionalCommits() {
promptScopes: configuration.get<boolean>('promptScopes'),
promptBody: configuration.get<boolean>('promptBody'),
promptFooter: configuration.get<boolean>('promptFooter'),
promptCI: configuration.get<boolean>('promptCI'),
});
output.info(`messageJSON:\n${JSON.stringify(commitMessage, null, 2)}`);
const message = serialize(commitMessage);
Expand Down
26 changes: 25 additions & 1 deletion src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default async function prompts({
promptScopes,
promptBody,
promptFooter,
promptCI,
}: {
gitmoji: boolean;
showEditor: boolean;
Expand All @@ -46,6 +47,7 @@ export default async function prompts({
promptScopes: boolean;
promptBody: boolean;
promptFooter: boolean;
promptCI: boolean;
}): Promise<CommitMessage> {
const commitMessage = new CommitMessage();
const conventionalCommitsTypes = getTypesByLocale(locale).types;
Expand Down Expand Up @@ -170,12 +172,30 @@ export default async function prompts({
alwaysShow: true,
},
},
{
type: PROMPT_TYPES.QUICK_PICK,
name: 'ci',
placeholder: getPromptLocalize('ci.placeholder'),
items: [
{
label: getPromptLocalize('ci.accept.label'),
description: '',
detail: getPromptLocalize('ci.accept.detail'),
},
],
noneItem: {
label: getPromptLocalize('ci.decline.label'),
description: '',
detail: getPromptLocalize('ci.decline.detail'),
alwaysShow: true,
},
},
{
type: PROMPT_TYPES.INPUT_BOX,
name: 'subject',
placeholder: getPromptLocalize('subject.placeholder'),
validate(input: string) {
const { type, scope, gitmoji } = commitMessage;
const { type, scope, gitmoji, ci } = commitMessage;
const serializedSubject = serializeSubject({
gitmoji,
subject: input,
Expand All @@ -198,6 +218,7 @@ export default async function prompts({
scope,
gitmoji,
subject: input,
ci,
}),
);
if (headerError) {
Expand Down Expand Up @@ -247,13 +268,16 @@ export default async function prompts({

if (question.name === 'gitmoji' && !gitmoji) return false;

if (question.name === 'ci' && !promptCI) return false;

if (question.name === 'body') {
if (showEditor || !promptBody) return false;
}

if (question.name === 'footer') {
if (showEditor || !promptFooter) return false;
}

return true;
})
.map(function (question, index, array) {
Expand Down