From 74e220997561af302c64fec135a18028cf21bed6 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 23 Apr 2023 23:30:06 +0300 Subject: [PATCH] Update update.js --- scripts/db/update.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/db/update.js b/scripts/db/update.js index b00ca500..bcbd2e73 100644 --- a/scripts/db/update.js +++ b/scripts/db/update.js @@ -21,6 +21,7 @@ async function main() { const filepath = `${DATA_DIR}/channels.csv` channels = await csv.fromFile(filepath) + await removeChannels() await editChannels() await addChannels() @@ -36,6 +37,26 @@ async function main() { main() +async function removeChannels() { + const issues = await fetchIssues('channels:remove,approved') + issues.map(parseIssue).forEach(({ issue, channel }) => { + if (!channel) { + updateIssue(issue, { labels: ['channels:remove', 'rejected:invalid'] }) + return + } + + const index = _.findIndex(channels, { id: channel.id }) + if (index < 0) { + updateIssue(issue, { labels: ['channels:remove', 'rejected:wrong_id'] }) + return + } + + channels.splice(index, 1) + + processedIssues.push(issue) + }) +} + async function editChannels() { const issues = await fetchIssues('channels:edit,approved') issues.map(parseIssue).forEach(({ issue, channel }) => { @@ -46,7 +67,7 @@ async function editChannels() { const index = _.findIndex(channels, { id: channel.id }) if (!index) { - updateIssue(issue, { labels: ['channels:edit', 'rejected:invalid'] }) + updateIssue(issue, { labels: ['channels:edit', 'rejected:wrong_id'] }) return }