Last active
June 20, 2019 09:04
-
-
Save dougbacelar/2c26e39b1595004951f3251c5d8b5b30 to your computer and use it in GitHub Desktop.
Tampermonkey script to flag untested files on PR's
This file contains hidden or 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
// ==UserScript== | |
// @name Github PR Untested Files | |
// @namespace https://git.hubteam.com/ | |
// @version 0.1 | |
// @description Helps reviewing PR's | |
// @author Doug Bacelar | |
// @match https://git.hubteam.com/* | |
// ==/UserScript== | |
'use es6'; | |
(function() { | |
const isInPrFilesPage = () => | |
!!window.location.href.match(/git\.hubteam\.com\/.+\/.+\/pull\/.+\/files/); | |
console.log('🔥 Untested PR files activated!'); | |
setInterval(() => { | |
if (isInPrFilesPage()) { | |
console.log('🎯 PR files page!'); | |
const WHITE_LIST = [ | |
'actiontypes.js', | |
'reducers/index.js', | |
'constants.js', | |
'/constants/', | |
'langpaths.js', | |
'.yaml', | |
'.lyaml', | |
'.json', | |
'.md', | |
'selectors/common.js', | |
'/data/', | |
'webpack.', | |
]; | |
const allFiles = Array.from( | |
document.querySelectorAll('.file-header div.file-info') | |
) | |
.filter( | |
node => | |
!WHITE_LIST.some( | |
name => node.innerText.toLowerCase().indexOf(name) > -1 | |
) | |
) | |
.filter(node => node.getElementsByClassName('block-diff-added').length) | |
.map(node => node.getElementsByTagName('a')[0]); | |
const testFiles = allFiles.filter( | |
file => | |
file | |
.getAttribute('title') | |
.toLowerCase() | |
.indexOf('test') > -1 | |
); | |
const srcFiles = allFiles.filter( | |
file => | |
file | |
.getAttribute('title') | |
.toLowerCase() | |
.indexOf('test') === -1 | |
); | |
const curatedTestNames = testFiles.map(file => | |
file | |
.getAttribute('title') | |
.replace('test/spec', 'js') | |
.replace(/Tests|Test/, '') | |
); | |
const untestedFiles = srcFiles.filter( | |
file => curatedTestNames.indexOf(file.getAttribute('title')) === -1 | |
); | |
const createUntestedSpan = () => { | |
const untestedSpan = document.createElement('span'); | |
untestedSpan.setAttribute('class', 'untested-flag'); | |
untestedSpan.setAttribute('style', 'color: red; margin-left: 10px'); | |
untestedSpan.innerText = 'UNTESTED'; | |
return untestedSpan; | |
}; | |
const createUntestedList = () => { | |
const untestedFilesDiv = document.createElement('div'); | |
untestedFilesDiv.setAttribute('class', 'untested-list'); | |
untestedFilesDiv.innerHTML = untestedFiles | |
.map( | |
node => | |
`<a href='${node.getAttribute('href')}'>${node.innerText}</a>` | |
) | |
.join('<br>'); | |
return untestedFilesDiv; | |
}; | |
if (!document.getElementsByClassName('untested-list').length) { | |
document.getElementById('files').prepend(createUntestedList()); | |
} | |
untestedFiles.forEach(node => { | |
console.log(`Untested file: ${node.getAttribute('title')}`); | |
if (!node.getElementsByClassName('untested-flag').length) { | |
node.appendChild(createUntestedSpan()); | |
} | |
}); | |
} | |
}, 3000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 👌