Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto Close Github issue by issue name (e.g. "Extension causes high cpu load" )
const comment = `Hello. few questions!!,
When you're getting this issue? after load of vscode or after clicking to Go Live ?
Is this happen every-time ? or random ?
Please reply here https://github.com/ritwickdey/vscode-live-server/issues/278
Duplicate of https://github.com/ritwickdey/vscode-live-server/issues/278
> [Note: This issue is closed by a javascript code (written by me).
https://gist.github.com/ritwickdey/36682dabe4a992c57e4562c935bfbbdd ]
Thank You.
`
const timeout = (time) => new Promise(r => setTimeout(r,time));
function commentAndCloseIssue (thisWindow, comment) {
return new Promise(async (resolve, reject) => {
let timeoutIds = [];
const mutationObserver = new MutationObserver((mutations) => {
const timeout = setTimeout(() => {
const isClosed = thisWindow.document.querySelector('[name=comment_and_open]') !== null;
if(isClosed) {
console.log('Issue Closed');
next();
}
}, 3000);
timeoutIds.push(timeout);
});
function next() {
mutationObserver.disconnect();
resolve();
timeoutIds.forEach(timeout => clearTimeout(timeout))
}
const onLoad = () => {
mutationObserver.observe(thisWindow.document.documentElement, {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});
const hasComment = thisWindow.document.querySelectorAll('.timeline-comment-wrapper.js-comment-container').length > 2;
if(hasComment) {
// I respect user & his/her comment. I should read.
console.log('This issue has comment: skipping to close!!');
return next();
}
const commentAndcloseBtn = thisWindow.document.querySelector('[name=comment_and_close]');
thisWindow.document.querySelector('#new_comment_field').value = comment;
console.log('Commenting..');
commentAndcloseBtn.click();
}
thisWindow.addEventListener('DOMContentLoaded', onLoad);
});
}
async function startClosing() {
const issuesUrls = [...document.querySelectorAll('div[aria-label=Issues] > div > div')]
.filter(node => node.innerText.split('\n')[0] === 'Extension causes high cpu load')
.filter(node => node.querySelector('svg.open'))
.map(e => e.querySelector('a[href]').href);
if(!issuesUrls || !issuesUrls.length) {
console.log('No issue found!');
return;
}
for (const issueUrl of issuesUrls) {
if(issueUrl === 'https://github.com/ritwickdey/vscode-live-server/issues/278') {
// BCZ IT'S BASE ISSUE
return;
}
console.log('Issue => ', issueUrl);
const issueWindow = window.open(issueUrl);
await commentAndCloseIssue(issueWindow, comment);
issueWindow.close();
console.log('----------', '\n');
}
}
startClosing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment