Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickvergessen/f4b03ae8ea4b4a1ffacc39679f4329a6 to your computer and use it in GitHub Desktop.
Save nickvergessen/f4b03ae8ea4b4a1ffacc39679f4329a6 to your computer and use it in GitHub Desktop.
Github status check sort
// ==UserScript==
// @name Github status check sort
// @namespace https://github.com/
// @version 1.1.2
// @description Sort the status checks on a PR by status and then by name
// @author Skjnldsv
// @match https://github.com/*/*/pull/*
// @icon https://github.githubassets.com/favicons/favicon.svg
// @grant none
// @updateURL https://gist.github.com/skjnldsv/eb7b894ae996affde4a7d0e00e0d80a1/raw/github-status-check-sort.user.js
// @downloadURL https://gist.github.com/skjnldsv/eb7b894ae996affde4a7d0e00e0d80a1/raw/github-status-check-sort.user.js
// ==/UserScript==
(function() {
'use strict';
const targetNode = document.querySelector('.discussion-timeline-actions')
const config = { attributes: false, childList: true, subtree: false }
const callback = (mutationList) => {
if ([...mutationList[0].removedNodes].length > 0) {
const container = document.querySelector('.merge-status-list > div.merge-status-item').parentElement
const children = Array.prototype.slice.call(container.querySelectorAll('div.merge-status-item'), 0)
while (container.firstChild) {
container.removeChild(container.firstChild);
}
container.append(...children.sort((a, b) => {
const iconSelector = '.merge-status-icon svg'
const statusCheckError = a.querySelector(iconSelector).classList.contains('octicon-x') - b.querySelector(iconSelector).classList.contains('octicon-x')
const statusCheckSkip = a.querySelector(iconSelector).classList.contains('octicon-skip') - b.querySelector(iconSelector).classList.contains('octicon-skip')
const statusCheckSuccess = a.querySelector(iconSelector).classList.contains('octicon-check') - b.querySelector(iconSelector).classList.contains('octicon-check')
const statusCheckNeutral = a.querySelector(iconSelector).classList.contains('octicon-square-fill') - b.querySelector(iconSelector).classList.contains('octicon-square-fill')
// Sort order: error -> neutral -> skip -> success -> name
return statusCheckSuccess || statusCheckSkip || statusCheckNeutral || statusCheckError
|| a.innerText.localeCompare(b.innerText)
}))
}
}
const observer = new MutationObserver(callback)
observer.observe(targetNode, config)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment