chore: updates

fix(githubUtils): query, slice 0,93

feat(regexes): move regex
This commit is contained in:
xHyroM 2022-07-14 08:13:18 +02:00
parent 21b74eb472
commit fe8563a008
2 changed files with 5 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import MiniSearch from 'minisearch';
import { Logger } from './Logger'; import { Logger } from './Logger';
import { APIApplicationCommandOptionChoice } from 'discord-api-types/v10'; import { APIApplicationCommandOptionChoice } from 'discord-api-types/v10';
import { Database } from 'bun:sqlite'; import { Database } from 'bun:sqlite';
import { discordChoicesRegex } from './regexes';
interface Issue { interface Issue {
id: number; id: number;
@ -185,7 +186,7 @@ export const search = async(query: string, repository: string): Promise<APIAppli
if (!query) { if (!query) {
const array = arrayFiltered.slice(0, 25); const array = arrayFiltered.slice(0, 25);
return array.map((issueOrPr: Issue | PullRequest) => new Object({ return array.map((issueOrPr: Issue | PullRequest) => new Object({
name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 93).replace(discordChoicesRegex, '')}`,
value: issueOrPr.number.toString() value: issueOrPr.number.toString()
})) as APIApplicationCommandOptionChoice[] })) as APIApplicationCommandOptionChoice[]
} }
@ -204,7 +205,7 @@ export const search = async(query: string, repository: string): Promise<APIAppli
const result = searcher.search(query); const result = searcher.search(query);
return (result as unknown as Issue[] | PullRequest[]).slice(0, 25).map((issueOrPr: Issue | PullRequest) => new Object({ return (result as unknown as Issue[] | PullRequest[]).slice(0, 25).map((issueOrPr: Issue | PullRequest) => new Object({
name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 93).replace(discordChoicesRegex, '')}`,
value: issueOrPr.number.toString() value: issueOrPr.number.toString()
})) as APIApplicationCommandOptionChoice[] })) as APIApplicationCommandOptionChoice[]
} catch(e) { } catch(e) {
@ -247,7 +248,7 @@ export const formatEmojiStatus = (data: Issue | PullRequest) => {
break; break;
} }
if (data.type === '(PR)' && !isNaN(new Date((data as PullRequest).merged_at).getTime())) emoji = '🟣'; if (data.type === '(PR)' && (data as PullRequest).merged_at) emoji = '🟣';
return emoji; return emoji;
} }

1
src/utils/regexes.ts Normal file
View file

@ -0,0 +1 @@
export const discordChoicesRegex = /[^a-z0-9 (|)|-|*|/|+|,|<|>|&|!|?]/gi;