Skip to content

Instantly share code, notes, and snippets.

@frankmarineau
Last active March 5, 2017 05:35
Show Gist options
  • Save frankmarineau/0198c2b4768a306df33bedc929e3713d to your computer and use it in GitHub Desktop.
Save frankmarineau/0198c2b4768a306df33bedc929e3713d to your computer and use it in GitHub Desktop.
Filter PR files based on their name and the presence of additions.
const originalFiles = Array.from(document.querySelectorAll('.js-file'))
const container = document.querySelector('#files')
const isFileValid = el => {
// Exclude a certain file name pattern
const EXCLUSION_REGEX = /\.s?css$|^\ios\/|^\java\/|yarn\.lock|styles\.js|\.svg$/
const fileName = el.querySelector('.file-header').dataset.path
if (fileName.match(EXCLUSION_REGEX)) return false
// Exclude files with no addition
if (!el.querySelector('.block-diff-added')) return false
return true
}
const filteredFiles = originalFiles.filter(fileEl => isFileValid(fileEl))
container.innerHTML = ''
filteredFiles.forEach(f => container.append(f))
console.log(`Filtered from ${originalFiles.length} to ${document.querySelectorAll('.js-file').length} files`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment