Skip to content

Commit

Permalink
feat: 🔥 support fusejs on scopes list (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tal-rofe authored Apr 15, 2023
2 parents 8c42f2f + 975cb90 commit 1058902
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/utils/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export const getQuestions = async (configuration: IConfiguration) => {
keys: ['value', 'emoji', 'description'],
});

const scopesFuse = new fuse(configuration.scopes, {
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
minMatchCharLength: 1,
});

const shouldValidateTicket = await shouldValidateTicketId(configuration.allowEmptyTicketIdForBranches);

return [
Expand All @@ -37,14 +45,16 @@ export const getQuestions = async (configuration: IConfiguration) => {
),
},
{
type: isScopesListsMode ? 'list' : 'input',
when: !configuration.skipScope,
type: isScopesListsMode ? 'autocomplete' : 'input',
name: 'scope',
message: configuration.scopeQuestion,
choices: isScopesListsMode ? configuration.scopes : null,
when: !configuration.skipScope,
validate: isScopesListsMode
? null
: (input: string) => input.length > 0 || 'Scope must be provided',
source: (_: unknown, query: string) =>
Promise.resolve(
query
? scopesFuse.search(query).map((match) => ({ name: match.item, value: match.item }))
: configuration.scopes,
),
},
{
type: 'input',
Expand Down

0 comments on commit 1058902

Please sign in to comment.