Skip to content

Commit

Permalink
feat(cz-git): use fuzzy search for type, scope and issues list
Browse files Browse the repository at this point in the history
link #22
  • Loading branch information
Zhengqbbb committed Apr 30, 2022
1 parent f1f5784 commit b82fbf9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/cz-git/src/generator/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getCurrentScopes
} from "../shared";
import { generateMessage } from "./message";
// import { fuzzyFilter } from "@cz-git/inquirer";
import { fuzzyFilter } from "@cz-git/inquirer";

export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
if (!Array.isArray(options.types) || options.types.length === 0) {
Expand All @@ -29,21 +29,21 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
name: "type",
message: options.messages?.type,
source: (_: unknown, input: string) => {
const typesSource = options.types?.concat(options.typesAppend || []) || [];
return typesSource.filter((item) => (input ? item.value.includes(input) : true)) || true;
const typeSource = options.types?.concat(options.typesAppend || []) || [];
return fuzzyFilter(input, typeSource, "value");
}
},
{
type: "autocomplete",
name: "scope",
message: options.messages?.scope,
source: (answer: Answers, input: string) => {
let scopes: Option[] = [];
scopes = handleStandardScopes(
let scopeSource: Option[] = [];
scopeSource = handleStandardScopes(
getCurrentScopes(options.scopes, options.scopeOverrides, answer.type)
);
scopes = handleCustomTemplate(
scopes,
scopeSource = handleCustomTemplate(
scopeSource,
cz,
options.customScopesAlign,
options.emptyScopesAlias,
Expand All @@ -52,7 +52,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.allowEmptyScopes,
options.defaultScope as string
);
return scopes?.filter((item) => (input ? item.name?.includes(input) : true)) || true;
return fuzzyFilter(input, scopeSource);
},
when: (answer: Answers) => {
return !isSingleItem(
Expand Down Expand Up @@ -159,7 +159,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
name: "footerPrefix",
message: options.messages?.footerPrefixsSelect,
source: (_: Answers, input: string) => {
const issues = handleCustomTemplate(
const issuePrefixSource = handleCustomTemplate(
options.issuePrefixs as Option[],
cz,
options.customIssuePrefixsAlign,
Expand All @@ -168,7 +168,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.allowCustomIssuePrefixs,
options.allowEmptyIssuePrefixs
);
return issues?.filter((item) => (input ? item.name?.includes(input) : true)) || true;
return fuzzyFilter(input, issuePrefixSource);
},
when: () =>
!isSingleItem(
Expand Down

0 comments on commit b82fbf9

Please sign in to comment.