Update scripts

This commit is contained in:
freearhey 2023-09-18 18:24:40 +03:00
parent e8d0b26ce0
commit 0f15fde4f2
4 changed files with 64 additions and 8 deletions

View file

@ -27,22 +27,25 @@ async function main() {
const streams = await parser.parse(files)
const groupedStreams = streams.groupBy((stream: Stream) => stream.url)
logger.info('loading issue from github...')
const issues = await loader.load({ labels: ['streams:add'] })
logger.info('creating report...')
let report = new Collection()
logger.info('checking streams:add requests...')
const addRequests = await loader.load({ labels: ['streams:add'] })
const buffer = new Dictionary()
const report = issues.map((issue: Issue) => {
addRequests.forEach((issue: Issue) => {
const channelId = issue.data.get('channel_id') || undefined
const streamUrl = issue.data.get('stream_url') || undefined
const result = new Dictionary({
issueNumber: issue.number,
type: 'streams:add',
channelId,
status: undefined
})
if (!channelId || !streamUrl) result.set('status', 'error')
if (!channelId) result.set('status', 'missing_id')
else if (!streamUrl) result.set('status', 'missing_link')
else if (groupedBlocklist.has(channelId)) result.set('status', 'blocked')
else if (groupedChannels.missing(channelId)) result.set('status', 'invalid_id')
else if (groupedStreams.has(streamUrl)) result.set('status', 'fullfilled')
@ -51,9 +54,51 @@ async function main() {
buffer.set(streamUrl, true)
return result.data()
report.add(result.data())
})
logger.info('checking streams:edit requests...')
const editRequests = await loader.load({ labels: ['streams:edit'] })
editRequests.forEach((issue: Issue) => {
const channelId = issue.data.get('channel_id') || undefined
const streamUrl = issue.data.get('stream_url') || undefined
const result = new Dictionary({
issueNumber: issue.number,
type: 'streams:edit',
channelId,
status: undefined
})
if (!streamUrl) result.set('status', 'missing_link')
else if (groupedStreams.missing(streamUrl)) result.set('status', 'invalid_link')
else if (channelId && groupedChannels.missing(channelId)) result.set('status', 'invalid_id')
else result.set('status', 'pending')
report.add(result.data())
})
logger.info('checking broken streams reports...')
const brokenStreamReports = await loader.load({ labels: ['broken stream'] })
brokenStreamReports.forEach((issue: Issue) => {
const streamUrl = issue.data.get('stream_url') || undefined
const result = new Dictionary({
issueNumber: issue.number,
type: 'broken stream',
channelId: undefined,
status: undefined
})
if (!streamUrl) result.set('status', 'missing_link')
else if (groupedStreams.missing(streamUrl)) result.set('status', 'invalid_link')
else result.set('status', 'pending')
report.add(result.data())
})
report = report.orderBy(item => item.issueNumber)
console.table(report.all())
}

View file

@ -16,6 +16,12 @@ export class IssueLoader {
case 'streams:add':
issues = (await import('../../tests/__data__/input/issues/streams_add')).default
break
case 'streams:edit':
issues = (await import('../../tests/__data__/input/issues/streams_edit')).default
break
case 'broken stream':
issues = (await import('../../tests/__data__/input/issues/broken_stream')).default
break
case 'streams:add,approved':
issues = (await import('../../tests/__data__/input/issues/streams_add_approved')).default
break

View file

@ -40,6 +40,8 @@ export class IssueParser {
data.set(id, value)
})
return new Issue({ number: issue.number, data })
const labels = issue.labels.map(label => label.name)
return new Issue({ number: issue.number, labels, data })
}
}

View file

@ -2,15 +2,18 @@ import { Dictionary } from '../core'
type IssueProps = {
number: number
labels: string[]
data: Dictionary
}
export class Issue {
number: number
labels: string[]
data: Dictionary
constructor({ number, data }: IssueProps) {
constructor({ number, labels, data }: IssueProps) {
this.number = number
this.labels = labels
this.data = data
}
}