Last active
April 12, 2019 02:57
-
-
Save ritwickdey/ddf2ff0e3ca49354b773a4c4ce8cb53c to your computer and use it in GitHub Desktop.
Auto Close Github issue by issue name (e.g. "Extension causes high cpu load" )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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