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(scope): ✨ add option to always use new unsaved scope #318

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ 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.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.silentAutoCommit` | Control that auto commit should be silent, without focusing source control panel. | false |
| `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.alwaysUseNewScope` | Always use a new unsaved `scope` for each commit. | false |
| `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.silentAutoCommit` | Control that auto commit should be silent, without focusing source control panel. | false |
| `conventionalCommits.editor.keepAfterSave` | Control whether the extension should keep the editor tab open after saving the commit message. | false |

## Commit Workflow

Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"extension.sources.prompt.scope.newItem.placeholder": "Create a new scope.",
"extension.sources.prompt.scope.newItemWithoutSetting.label": "New scope (only use once)",
"extension.sources.prompt.scope.newItemWithoutSetting.detail": "Use a new scope. (The scope will not be added in workspace `settings.json`.)",
"extension.sources.prompt.scope.alwaysUseNewUnsavedScope.placeholder": "Write the scope of the change",
"extension.sources.prompt.gitmoji.placeholder": "Choose a gitmoji.",
"extension.sources.prompt.gitmoji.noneItem.label": "None",
"extension.sources.prompt.gitmoji.noneItem.detail": "No gitmoji.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"extension.sources.prompt.scope.newItem.placeholder": "请输入作用域。",
"extension.sources.prompt.scope.newItemWithoutSetting.label": "新作用域(仅用一次)",
"extension.sources.prompt.scope.newItemWithoutSetting.detail": "使用新作用域。(不会加入工作区的 `settings.json`)",
"extension.sources.prompt.scope.alwaysUseNewUnsavedScope.placeholder": "写出变更范围",
"extension.sources.prompt.gitmoji.placeholder": "请选择 gitmoji。",
"extension.sources.prompt.gitmoji.noneItem.label": "无",
"extension.sources.prompt.gitmoji.noneItem.detail": "无 gitmoji。",
Expand Down
1 change: 1 addition & 0 deletions src/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type Configuration = {
promptFooter: boolean;
promptCI: boolean;
showNewVersionNotes: boolean;
alwaysUseNewUnsavedScope: boolean;
'editor.keepAfterSave': boolean;
};

Expand Down
11 changes: 8 additions & 3 deletions src/lib/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ async function getRepository({
}

export default function createConventionalCommits() {
return async function conventionalCommits(repoUri?: VSCodeGit.Repository | vscode.Uri) {
return async function conventionalCommits(
repoUri?: VSCodeGit.Repository | vscode.Uri,
) {
try {
output.info('Conventional commits started.');

Expand All @@ -121,11 +123,11 @@ export default function createConventionalCommits() {

// 3. get repository
let _repoUri = repoUri;
if (!(repoUri instanceof vscode.Uri) && (repoUri !== undefined)) {
if (!(repoUri instanceof vscode.Uri) && repoUri !== undefined) {
_repoUri = repoUri.rootUri;
}
const repository = await getRepository({
arg: (<vscode.Uri | undefined>_repoUri),
arg: <vscode.Uri | undefined>_repoUri,
git: git,
workspaceFolders: vscode.workspace.workspaceFolders,
});
Expand Down Expand Up @@ -154,6 +156,9 @@ export default function createConventionalCommits() {
promptBody: configuration.get<boolean>('promptBody'),
promptFooter: configuration.get<boolean>('promptFooter'),
promptCI: configuration.get<boolean>('promptCI'),
alwaysUseNewUnsavedScope: configuration.get<boolean>(
'alwaysUseNewUnsavedScope',
),
});
output.info(`messageJSON:\n${JSON.stringify(commitMessage, null, 2)}`);
const message = serialize(commitMessage);
Expand Down
16 changes: 16 additions & 0 deletions src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default async function prompts({
promptBody,
promptFooter,
promptCI,
alwaysUseNewUnsavedScope,
}: {
gitmoji: boolean;
showEditor: boolean;
Expand All @@ -48,6 +49,7 @@ export default async function prompts({
promptBody: boolean;
promptFooter: boolean;
promptCI: boolean;
alwaysUseNewUnsavedScope: boolean;
}): Promise<CommitMessage> {
const commitMessage = new CommitMessage();
const conventionalCommitsTypes = getTypesByLocale(locale).types;
Expand Down Expand Up @@ -101,6 +103,20 @@ export default async function prompts({
detail: getPromptLocalize('scope.noneItem.detail'),
alwaysShow: true,
};

if (alwaysUseNewUnsavedScope) {
return {
type: PROMPT_TYPES.INPUT_BOX,
name,
placeholder: getPromptLocalize(
'scope.alwaysUseNewUnsavedScope.placeholder',
),
validate(input: string) {
return commitlint.lintScope(input);
},
};
}

if (scopeEnum.length) {
return {
type: PROMPT_TYPES.QUICK_PICK,
Expand Down