mirror of
https://github.com/iptv-org/database.git
synced 2024-11-22 02:44:10 -05:00
Update update.js
This commit is contained in:
parent
518c78c1cb
commit
26f6bb3428
1 changed files with 14 additions and 46 deletions
|
@ -5,9 +5,7 @@ const { paginateRest } = require('@octokit/plugin-paginate-rest')
|
||||||
const CustomOctokit = Octokit.plugin(paginateRest)
|
const CustomOctokit = Octokit.plugin(paginateRest)
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const octokit = new CustomOctokit({
|
const octokit = new CustomOctokit()
|
||||||
auth: process.env.GITHUB_TOKEN
|
|
||||||
})
|
|
||||||
|
|
||||||
const DATA_DIR = process.env.DATA_DIR || './data'
|
const DATA_DIR = process.env.DATA_DIR || './data'
|
||||||
const OWNER = 'iptv-org'
|
const OWNER = 'iptv-org'
|
||||||
|
@ -40,16 +38,10 @@ main()
|
||||||
async function removeChannels() {
|
async function removeChannels() {
|
||||||
const issues = await fetchIssues('channels:remove,approved')
|
const issues = await fetchIssues('channels:remove,approved')
|
||||||
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
||||||
if (!channel) {
|
if (!channel) return
|
||||||
updateIssue(issue, { labels: ['channels:remove', 'rejected:invalid'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = _.findIndex(channels, { id: channel.id })
|
const index = _.findIndex(channels, { id: channel.id })
|
||||||
if (index < 0) {
|
if (index < 0) return
|
||||||
updateIssue(issue, { labels: ['channels:remove', 'rejected:wrong_id'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channels.splice(index, 1)
|
channels.splice(index, 1)
|
||||||
|
|
||||||
|
@ -60,16 +52,10 @@ async function removeChannels() {
|
||||||
async function editChannels() {
|
async function editChannels() {
|
||||||
const issues = await fetchIssues('channels:edit,approved')
|
const issues = await fetchIssues('channels:edit,approved')
|
||||||
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
||||||
if (!channel) {
|
if (!channel) return
|
||||||
updateIssue(issue, { labels: ['channels:edit', 'rejected:invalid'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = _.findIndex(channels, { id: channel.id })
|
const index = _.findIndex(channels, { id: channel.id })
|
||||||
if (index < 0) {
|
if (index < 0) return
|
||||||
updateIssue(issue, { labels: ['channels:edit', 'rejected:wrong_id'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const found = channels[index]
|
const found = channels[index]
|
||||||
|
|
||||||
|
@ -90,16 +76,10 @@ async function editChannels() {
|
||||||
async function addChannels() {
|
async function addChannels() {
|
||||||
const issues = await fetchIssues('channels:add,approved')
|
const issues = await fetchIssues('channels:add,approved')
|
||||||
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
issues.map(parseIssue).forEach(({ issue, channel }) => {
|
||||||
if (!channel) {
|
if (!channel) return
|
||||||
updateIssue(issue, { labels: ['channels:add', 'rejected:invalid'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const found = channels.find(c => c.id === channel.id)
|
const found = channels.find(c => c.id === channel.id)
|
||||||
if (found) {
|
if (found) return
|
||||||
updateIssue(issue, { labels: ['channels:add', 'rejected:duplicate'] })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channels.push(channel)
|
channels.push(channel)
|
||||||
processedIssues.push(issue)
|
processedIssues.push(issue)
|
||||||
|
@ -120,22 +100,10 @@ async function fetchIssues(labels) {
|
||||||
return issues
|
return issues
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateIssue(issue, { labels }) {
|
|
||||||
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', {
|
|
||||||
owner: OWNER,
|
|
||||||
repo: REPO,
|
|
||||||
issue_number: issue.number,
|
|
||||||
labels,
|
|
||||||
headers: {
|
|
||||||
'X-GitHub-Api-Version': '2022-11-28'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseIssue(issue) {
|
function parseIssue(issue) {
|
||||||
const buffer = {}
|
const buffer = {}
|
||||||
const channel = {}
|
const channel = {}
|
||||||
const fields = {
|
const fieldLabels = {
|
||||||
'Channel ID (required)': 'id',
|
'Channel ID (required)': 'id',
|
||||||
'Channel Name': 'name',
|
'Channel Name': 'name',
|
||||||
'Alternative Names': 'alt_names',
|
'Alternative Names': 'alt_names',
|
||||||
|
@ -165,17 +133,17 @@ function parseIssue(issue) {
|
||||||
Logo: 'logo'
|
Logo: 'logo'
|
||||||
}
|
}
|
||||||
|
|
||||||
const matches = issue.body.match(/### ([^\r\n]+)\s+([^\r\n]+)/g)
|
const fields = issue.body.split('###')
|
||||||
|
|
||||||
if (!matches) return { issue, channel: null }
|
if (!fields.length) return { issue, channel: null }
|
||||||
|
|
||||||
matches.forEach(item => {
|
fields.forEach(item => {
|
||||||
const [, fieldLabel, value] = item.match(/### ([^\r\n]+)\s+([^\r\n]+)/)
|
const [fieldLabel, , value] = item.split(/\r?\n/)
|
||||||
const field = fields[fieldLabel]
|
const field = fieldLabel ? fieldLabels[fieldLabel.trim()] : null
|
||||||
|
|
||||||
if (!field) return
|
if (!field) return
|
||||||
|
|
||||||
buffer[field] = value === '_No response_' ? undefined : value.trim()
|
buffer[field] = value.includes('_No response_') ? undefined : value.trim()
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let field of Object.keys(channelScheme)) {
|
for (let field of Object.keys(channelScheme)) {
|
||||||
|
|
Loading…
Reference in a new issue