mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-11-22 14:41:05 +01:00
feat: implement draft
Closes https://github.com/xHyroM/bun-discord-bot/issues/22
This commit is contained in:
parent
56922524e2
commit
a6affd1b8e
2 changed files with 13 additions and 10 deletions
|
@ -126,6 +126,7 @@ app.post('/github_webhook', bodyParse(), (c) => {
|
||||||
user_login: issueOrPr.pull_request.user.login,
|
user_login: issueOrPr.pull_request.user.login,
|
||||||
user_html_url: issueOrPr.pull_request.user.html_url,
|
user_html_url: issueOrPr.pull_request.user.html_url,
|
||||||
type: '(PR)',
|
type: '(PR)',
|
||||||
|
draft: issueOrPr.pull_request.draft,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -26,14 +26,15 @@ interface Issue {
|
||||||
|
|
||||||
interface PullRequest extends Issue {
|
interface PullRequest extends Issue {
|
||||||
merged_at: string | null;
|
merged_at: string | null;
|
||||||
|
draft: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const db = new Database('./files/database.sqlite');
|
export const db = new Database('./files/database.sqlite');
|
||||||
await db.exec('DROP TABLE IF EXISTS issuesandprs');
|
await db.exec('DROP TABLE IF EXISTS issuesandprs');
|
||||||
await db.exec('CREATE TABLE issuesandprs (id INTEGER PRIMARY KEY, repository TEXT, title TEXT, number INTEGER, state TEXT, created_at TEXT, closed_at TEXT, merged_at TEXT, html_url TEXT, user_login TEXT, user_html_url TEXT, type TEXT)');
|
await db.exec('CREATE TABLE issuesandprs (id INTEGER PRIMARY KEY, repository TEXT, title TEXT, number INTEGER, state TEXT, created_at TEXT, closed_at TEXT, merged_at TEXT, html_url TEXT, user_login TEXT, user_html_url TEXT, type TEXT, draft TINYINT)');
|
||||||
|
|
||||||
const addToDb = db.prepare(
|
const addToDb = db.prepare(
|
||||||
'INSERT INTO issuesandprs (repository, title, number, state, created_at, closed_at, merged_at, html_url, user_login, user_html_url, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
'INSERT INTO issuesandprs (repository, title, number, state, created_at, closed_at, merged_at, html_url, user_login, user_html_url, type, draft) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||||
);
|
);
|
||||||
|
|
||||||
export let issues: number = 0;
|
export let issues: number = 0;
|
||||||
|
@ -67,7 +68,8 @@ export const fetchIssues = async() => {
|
||||||
issue.html_url,
|
issue.html_url,
|
||||||
issue.user.login,
|
issue.user.login,
|
||||||
issue.user.html_url,
|
issue.user.html_url,
|
||||||
'(IS)'
|
'(IS)',
|
||||||
|
null,
|
||||||
]);
|
]);
|
||||||
issues++;
|
issues++;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +115,8 @@ export const fetchPullRequests = async() => {
|
||||||
pull.html_url,
|
pull.html_url,
|
||||||
pull.user.login,
|
pull.user.login,
|
||||||
pull.user.html_url,
|
pull.user.html_url,
|
||||||
'(PR)'
|
'(PR)',
|
||||||
|
pull.draft,
|
||||||
]);
|
]);
|
||||||
pulls++;
|
pulls++;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +175,8 @@ export const setPullRequest = async(pull: PullRequest) => {
|
||||||
pull.html_url,
|
pull.html_url,
|
||||||
pull.user_login,
|
pull.user_login,
|
||||||
pull.user_html_url,
|
pull.user_html_url,
|
||||||
'(IS)'
|
'(IS)',
|
||||||
|
pull.draft,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +204,7 @@ export const search = async(query: string, repository: string, state: IssueState
|
||||||
|
|
||||||
const searcher = new MiniSearch({
|
const searcher = new MiniSearch({
|
||||||
fields: query.startsWith('#') ? ['number'] : ['title'],
|
fields: query.startsWith('#') ? ['number'] : ['title'],
|
||||||
storeFields: ['title', 'number', 'type', 'state', 'merged_at'],
|
storeFields: ['title', 'number', 'type', 'state', 'merged_at', 'draft'],
|
||||||
searchOptions: {
|
searchOptions: {
|
||||||
fuzzy: 3,
|
fuzzy: 3,
|
||||||
processTerm: term => term.toLowerCase(),
|
processTerm: term => term.toLowerCase(),
|
||||||
|
@ -254,14 +258,12 @@ export const formatEmojiStatus = (data: Issue | PullRequest) => {
|
||||||
let emoji = '';
|
let emoji = '';
|
||||||
switch(data.state as 'open' | 'closed' | 'all') {
|
switch(data.state as 'open' | 'closed' | 'all') {
|
||||||
case 'open':
|
case 'open':
|
||||||
emoji = '🟢';
|
emoji = (data as PullRequest).draft ? '⚫' : '🟢';
|
||||||
break;
|
break;
|
||||||
case 'closed':
|
case 'closed':
|
||||||
emoji = '🔴';
|
emoji = (data as PullRequest).merged_at ? '🟣' : '🔴';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type === '(PR)' && (data as PullRequest).merged_at) emoji = '🟣';
|
|
||||||
|
|
||||||
return emoji;
|
return emoji;
|
||||||
}
|
}
|
Loading…
Reference in a new issue