Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go for general reminder #3123

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@
.then(response => response.data);
}

function updateLabel(name, description, color) {
return axios.patch(`https://api.github.com/repos/ioBroker/ioBroker.repositories/labels/${name}`,
{
'description': `${description}`,
'color': `${color}`
},
{
headers: {
Authorization: process.env.OWN_GITHUB_TOKEN ? `token ${process.env.OWN_GITHUB_TOKEN}` : 'none',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "none" is used as
authorization header
.
'user-agent': 'Action script'
}
})
.then(response => response.data);
}
function addComment(prID, body) {
return axios.post(`https://api.github.com/repos/ioBroker/ioBroker.repositories/issues/${prID}/comments`, {body},
{
Expand Down Expand Up @@ -148,6 +162,7 @@
addLabel,
createLabel,
deleteLabel,
updateLabel,
getGithub,
getUrl,
createIssue,
Expand Down
114 changes: 95 additions & 19 deletions lib/stableBrandNewReminder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@ const {
addLabel,
createLabel,
deleteLabel,
updateLabel,
getLabels,
getAllComments,
getGithub,
} = require('./common');

async function doIt() {
async function cleanupLabels(){
let labels = await getLabels('');
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`);
console.log(` ${l.name} is outdated and will be removed`);
deleteLabel('', l.name);
}
};
});

}

async function cleanupIssueLabels(){
const issues = await getGithub(`https://api.github.com/repos/iobroker/ioBroker.repositories/issues`);
for (const issue of issues ) {
console.log(`cleanup PR ${issue.number}`);
issue.labels.forEach((l) => {
const result = /^(\d\d)\.(\d\d)\.(\d\d\d\d)$/g.exec(l.name);
if (result) {
console.log(` ${l.name} will be removed`);
deleteLabel(issue.number, l.name);
}
})
}
}

async function handleBrandNew(){
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')) {
Expand All @@ -31,51 +48,57 @@ async function doIt() {
let found=false;
let comment;

comment = comments.find( c => /created (\d+\.\d+\.\d+)/g.exec(c.body));
comment = comments.findLast( c => /created (\d+\.\d+\.\d+)/g.exec(c.body));
if (comment) {
const result = /created (\d+)\.(\d+)\.(\d+)/g.exec(comment.body);
if (result) {
let targetTs=new Date(result[3], result[2]-1, result[1], 0, 0, 0).getTime();
targetTs += (7 * 86400 * 1000);
const dateStr = new Date(targetTs).toLocaleDateString();
const nowTs = new Date().getTime();
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`);
}
if ( nowTs < targetTs ) {
console.log(` will merged after ${dateStr}`);
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 updateLabel(`${label}`, `remind after ${dateStr}`, `ffffff`);
await addLabel(issue.number, [`${label}`]);
} else {
console.log(` should be merged now (deadline ${dateStr})`);
await updateLabel(`${label}`, `remind after ${dateStr}`, `ff0000`);
await addLabel(issue.number, [`${label}`]);
await addLabel(issue.number, ['⚠️check']);
}
}
found=true;
}

comment = comments.find( c => /reminder (\d+\.\d+\.\d+)/g.exec(c.body));
comment = comments.findLast( c => /reminder (\d+\.\d+\.\d+)/g.exec(c.body));
if (comment) {
const result = /reminder (\d+)\.(\d+)\.(\d+)/g.exec(comment.body);
if (result) {
let targetTs=new Date(result[3], result[2]-1, result[1], 0, 0, 0).getTime();
const dateStr = new Date(targetTs).toLocaleDateString();
const nowTs = Date.now();
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`);
}
if ( nowTs < targetTs ) {
console.log(` will remind at ${dateStr}`);
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 updateLabel(`${label}`, `remind after ${dateStr}`, `ffffff`);
await addLabel(issue.number, [`${label}`]);
} else {
console.log(` should be checked now (deadline ${dateStr})`);
await updateLabel(`${label}`, `remind after ${dateStr}`, `ff0000`);
await addLabel(issue.number, [`${label}`]);
await addLabel(issue.number, ['⚠️check']);
}
}
Expand All @@ -88,6 +111,59 @@ async function doIt() {
}
}
}
}

async function handleOthers(){
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')) {
console.log(`checking PR ${issue.number}`);
const comments= await getAllComments( issue.number );

let comment = comments.findLast( c => /reminder (\d+\.\d+\.\d+)/g.exec(c.body));
if (comment) {
const result = /reminder (\d+)\.(\d+)\.(\d+)/g.exec(comment.body);
if (result) {
let targetTs=new Date(result[3], result[2]-1, result[1], 0, 0, 0).getTime();
const dateStr = new Date(targetTs).toLocaleDateString();
const nowTs = Date.now();
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`);
}
if ( nowTs < targetTs ) {
console.log(` will remind at ${dateStr}`);
await updateLabel(`${label}`, `remind after ${dateStr}`, `ffffff`);
await addLabel(issue.number, [`${label}`]);
} else {
console.log(` should be checked now (deadline ${dateStr})`);
await updateLabel(`${label}`, `remind after ${dateStr}`, `ff0000`);
await addLabel(issue.number, [`${label}`]);
}
}
}
}
}
}

async function doIt() {
// cleanup labels
console.log ('check for outdated labels');
await cleanupLabels();

console.log ('cleanup labels already set');
await cleanupIssueLabels();

// process STABLE-brand new tagged issues
console.log ('process STABLE-brand-new issues');
await handleBrandNew();

// process other reminders
console.log ('process normal issues');
await handleOthers();
return 'done';
}

Expand Down