Update scripts

This commit is contained in:
freearhey 2025-03-18 08:32:46 +03:00
parent 77680e2dc9
commit 075c53143e
14 changed files with 520 additions and 132 deletions

View file

@ -21,7 +21,10 @@ const opts = {
replaced_by: nullable,
website: nullable,
logo: nullable,
countries: listParser
countries: listParser,
timezones: listParser,
is_main: boolParser,
video_format: nullable
}
}

View file

@ -1,17 +0,0 @@
export class IDCreator {
create(name: string, country: string): string {
const slug = normalize(name)
const code = country.toLowerCase()
return `${slug}.${code}`
}
}
function normalize(name: string) {
return name
.replace(/^@/gi, 'At')
.replace(/^&/i, 'And')
.replace(/\+/gi, 'Plus')
.replace(/\s-(\d)/gi, ' Minus$1')
.replace(/[^a-z\d]+/gi, '')
}

View file

@ -2,6 +2,5 @@ export * from './csv'
export * from './issueParser'
export * from './issueLoader'
export * from './csvParser'
export * from './idCreator'
export * from './issueData'
export * from './issue'

View file

@ -9,32 +9,15 @@ const CustomOctokit = Octokit.plugin(paginateRest, restEndpointMethods)
const octokit = new CustomOctokit()
export class IssueLoader {
async load({ labels }: { labels: string[] | string }) {
labels = Array.isArray(labels) ? labels.join(',') : labels
async load(props?: { labels: string[] | string }) {
let labels = ''
if (props && props.labels) {
labels = Array.isArray(props.labels) ? props.labels.join(',') : props.labels
}
let issues: object[] = []
if (TESTING) {
switch (labels) {
case 'channels:add,approved':
issues = (await import('../../tests/__data__/input/issues/channels_add_approved.js'))
.default
break
case 'channels:edit,approved':
issues = (await import('../../tests/__data__/input/issues/channels_edit_approved.js'))
.default
break
case 'channels:remove,approved':
issues = (await import('../../tests/__data__/input/issues/channels_remove_approved.js'))
.default
break
case 'blocklist:add,approved':
issues = (await import('../../tests/__data__/input/issues/blocklist_add_approved.js'))
.default
break
case 'blocklist:remove,approved':
issues = (await import('../../tests/__data__/input/issues/blocklist_remove_approved.js'))
.default
break
}
issues = (await import('../../tests/__data__/input/update/issues.js')).default
} else {
issues = await octokit.paginate(octokit.rest.issues.listForRepo, {
owner: OWNER,

View file

@ -3,40 +3,30 @@ import { IssueData, Issue } from '../core'
const FIELDS = new Dictionary({
'Channel ID': 'channel_id',
'Channel ID (required)': 'channel_id',
'Channel ID (optional)': 'channel_id',
'Channel Name': 'name',
'Channel Name': 'channel_name',
'Feed Name': 'feed_name',
'Feed ID': 'feed_id',
'Main Feed': 'is_main',
'Alternative Names': 'alt_names',
'Alternative Names (optional)': 'alt_names',
Network: 'network',
'Network (optional)': 'network',
Owners: 'owners',
'Owners (optional)': 'owners',
Country: 'country',
Subdivision: 'subdivision',
'Subdivision (optional)': 'subdivision',
City: 'city',
'City (optional)': 'city',
'Broadcast Area': 'broadcast_area',
Timezones: 'timezones',
Format: 'video_format',
Languages: 'languages',
Categories: 'categories',
'Categories (optional)': 'categories',
NSFW: 'is_nsfw',
Launched: 'launched',
'Launched (optional)': 'launched',
Closed: 'closed',
'Closed (optional)': 'closed',
'Replaced By': 'replaced_by',
'Replaced By (optional)': 'replaced_by',
Website: 'website',
'Website (optional)': 'website',
Logo: 'logo',
Reason: 'reason',
Notes: 'notes',
'Notes (optional)': 'notes',
Reference: 'ref',
'Reference (optional)': 'ref',
'Reference (required)': 'ref'
Reference: 'ref'
})
export class IssueParser {
@ -46,7 +36,7 @@ export class IssueParser {
const data = new Dictionary()
fields.forEach((field: string) => {
let [_label, , _value] = field.split(/\r?\n/)
_label = _label ? _label.trim() : ''
_label = _label ? _label.replace(/ \(optional\)| \(required\)/, '').trim() : ''
_value = _value ? _value.trim() : ''
if (!_label || !_value) return data