diff --git a/files/database.sqlite b/files/database.sqlite index e22ac7d..4ed05b6 100644 Binary files a/files/database.sqlite and b/files/database.sqlite differ diff --git a/src/commands/github.ts b/src/commands/github.ts index cef951b..e81d392 100644 --- a/src/commands/github.ts +++ b/src/commands/github.ts @@ -3,9 +3,8 @@ import { Command } from '../structures/Command'; // @ts-expect-error Types :( import utilities from '../../files/utilities.toml'; import Collection from '@discordjs/collection'; -import formatStatus from '../utils/formatStatus'; import { CommandContext } from '../structures/contexts/CommandContext'; -import { getIssueOrPR, search } from '../utils/githubUtils'; +import { getIssueOrPR, search, formatStatus } from '../utils/githubUtils'; const cooldowns: Collection = new Collection(); const invalidIssue = (ctx: CommandContext, query: string) => { @@ -83,7 +82,7 @@ new Command({ html_url: item.html_url, user_login: item.user.login, user_html_url: item.user.html_url, - type: item.pull_request ? '(PR)' : '(ISSUE)', + type: item.pull_request ? '(PR)' : '(IS)', }; } diff --git a/src/index.ts b/src/index.ts index 512fc08..fa92d59 100644 --- a/src/index.ts +++ b/src/index.ts @@ -106,7 +106,7 @@ app.post('/github_webhook', bodyParse(), (c) => { html_url: issueOrPr.issue.html_url, user_login: issueOrPr.issue.user.login, user_html_url: issueOrPr.issue.user.html_url, - type: '(ISSUE)', + type: '(IS)', }) } else { diff --git a/src/utils/formatStatus.ts b/src/utils/formatStatus.ts deleted file mode 100644 index 3378616..0000000 --- a/src/utils/formatStatus.ts +++ /dev/null @@ -1,18 +0,0 @@ -export default (data: any) => { - let operation = ''; - let timestamp = ''; - switch(data.state as 'open' | 'closed' | 'all') { - case 'open': - operation = 'opened'; - timestamp = ``; - break; - case 'closed': - operation = data?.pull_request?.merged_at ? 'merged' : 'closed'; - timestamp = data?.pull_request?.merged_at - ? `` - : ``; - break; - } - - return `${operation} ${timestamp}`; -} \ No newline at end of file diff --git a/src/utils/githubUtils.ts b/src/utils/githubUtils.ts index 26c226b..93fbdc5 100644 --- a/src/utils/githubUtils.ts +++ b/src/utils/githubUtils.ts @@ -18,7 +18,7 @@ interface Issue { html_url: string; user_login: string; user_html_url: string; - type: '(ISSUE)' | '(PR)'; + type: '(IS)' | '(PR)'; } interface PullRequest extends Issue { @@ -64,7 +64,7 @@ export const fetchIssues = async() => { issue.html_url, issue.user.login, issue.user.html_url, - '(ISSUE)' + '(IS)' ]); issues++; } @@ -145,7 +145,7 @@ export const setIssue = async(issue: Issue) => { issue.html_url, issue.user_login, issue.user_html_url, - '(ISSUE)' + '(IS)' ]); } } @@ -167,7 +167,7 @@ export const setPullRequest = async(pull: PullRequest) => { pull.html_url, pull.user_login, pull.user_html_url, - '(ISSUE)' + '(IS)' ]); } } @@ -183,14 +183,14 @@ export const search = async(query: string, repository: string): Promise new Object({ - name: `${issueOrPr.type} ${issueOrPr.title.slice(0, 93).replace(/[^a-z0-9 ]/gi, '')}`, + name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, value: issueOrPr.number.toString() })) as APIApplicationCommandOptionChoice[] } const searcher = new MiniSearch({ - fields: ['title', 'number', 'type'], - storeFields: ['title', 'number', 'type'], + fields: query.startsWith('#') ? ['number'] : ['title'], + storeFields: ['title', 'number', 'type', 'state', 'merged_at'], searchOptions: { fuzzy: 3, processTerm: term => term.toLowerCase(), @@ -202,7 +202,7 @@ export const search = async(query: string, repository: string): Promise new Object({ - name: `${issueOrPr.type} ${issueOrPr.title.slice(0, 93).replace(/[^a-z0-9 ]/gi, '')}`, + name: `${issueOrPr.type} ${formatEmojiStatus(issueOrPr)} ${issueOrPr.title.slice(0, 95).replace(/[^a-z0-9 ]/gi, '')}`, value: issueOrPr.number.toString() })) as APIApplicationCommandOptionChoice[] } catch(e) { @@ -213,4 +213,39 @@ export const search = async(query: string, repository: string): Promise => { const issueOrPR = await db.prepare(`SELECT * FROM issuesandprs WHERE repository = '${repository}' AND number = ${number}`).get(); return issueOrPR; +} + +export const formatStatus = (data: Issue | PullRequest) => { + let operation = ''; + let timestamp = ''; + switch(data.state as 'open' | 'closed' | 'all') { + case 'open': + operation = 'opened'; + timestamp = ``; + break; + case 'closed': + operation = (data as PullRequest).merged_at ? 'merged' : 'closed'; + timestamp = (data as PullRequest).merged_at + ? `` + : ``; + break; + } + + return `${operation} ${timestamp}`; +} + +export const formatEmojiStatus = (data: Issue | PullRequest) => { + let emoji = ''; + switch(data.state as 'open' | 'closed' | 'all') { + case 'open': + emoji = '🟢'; + break; + case 'closed': + emoji = '🔴'; + break; + } + + if (data.type === '(PR)' && !isNaN(new Date((data as PullRequest).merged_at).getTime())) emoji = '🟣'; + + return emoji; } \ No newline at end of file