diff --git a/lib/stableBrandNewReminder.js b/lib/stableBrandNewReminder.js index ce81d328d..6e902ea23 100644 --- a/lib/stableBrandNewReminder.js +++ b/lib/stableBrandNewReminder.js @@ -2,12 +2,26 @@ const { addLabel, createLabel, + deleteLabel, getLabels, getAllComments, getGithub, } = require('./common'); async function doIt() { + let labels = await getLabels(''); + labels = labels.forEach( (l)=> { + const result = /^(\d\d)\.(\d\d)\.(\d\d\d\d)$/g.exec(l.name); + if (result) { + let targetTs=new Date(result[3], result[2]-1, result[1], 0, 0, 0).getTime(); + const nowTs = new Date().getTime(); + if ( nowTs > targetTs + 2* 24*60*60*1000) { + console.log(`Label ${l.name} is outdated and will be removed`); + deleteLabel('', l.name); + } + }; + }); + const issues = await getGithub(`https://api.github.com/repos/iobroker/ioBroker.repositories/issues`); for (const issue of issues ) { if (issue.labels.find(label => label.name === 'STABLE - brand new')) { @@ -27,14 +41,14 @@ async function doIt() { const nowTs = new Date().getTime(); if ( nowTs < targetTs ) { console.log(` will merged after ${dateStr}`); - const label = `* ${dateStr} *`; - const labels = await getLabels(''); - //if ( ! labels.filter( (f) => { console.log( f.name ); return f.name===`${label}`})) { - if ( ! labels.includes(`${label}`)) { + const label = `${dateStr}`; + let labels = await getLabels(''); + labels = labels.filter( (f) => { return f.name===`${label}`} ); + if (!labels.length) { console.log(` will create label $label}`); - await createLabel(`${label}`, `remind after ${dateStr}`, `#ffffff`); + await createLabel(`${label}`, `remind after ${dateStr}`, `ffffff`); } - await addLabel(`${issue.number}`, `${label}`); + await addLabel(issue.number, [`${label}`]); } else { console.log(` should be merged now (deadline ${dateStr})`); await addLabel(issue.number, ['⚠️check']); @@ -52,14 +66,14 @@ async function doIt() { const nowTs = Date.now(); if ( nowTs < targetTs ) { console.log(` will remind at ${dateStr}`); - const label = `* ${dateStr} *`; - const labels = await getLabels(''); - //if ( ! labels.filter( (f) => { console.log( f.name ); return f.name===`${label}`})) { - if ( ! labels.includes(`${label}`)) { + const label = `${dateStr}`; + let labels = await getLabels(''); + labels = labels.filter( (f) => { return f.name===`${label}`} ); + if (!labels.length) { console.log(` will create label ${label}`); - await createLabel(`${label}`, `remind after ${dateStr}`, `#ffffff`); + await createLabel(`${label}`, `remind after ${dateStr}`, `ffffff`); } - await addLabel(`${issue.number}`, `${label}`); + await addLabel(issue.number, [`${label}`]); } else { console.log(` should be checked now (deadline ${dateStr})`); await addLabel(issue.number, ['⚠️check']);