Skip to content

Instantly share code, notes, and snippets.

@ryanml
Last active August 12, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanml/dbb95a3382150072852b8ade401fc40b to your computer and use it in GitHub Desktop.
Save ryanml/dbb95a3382150072852b8ade401fc40b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Release Merge Sanity Checker
// @version 1.0
// @description :^)
// @author ryanml
// @match https://github.com/MetaMask/metamask-extension/pull/*
// @grant none
// ==/UserScript==
(function() {
// The final merge button isn't present in the initial DOM content, rather
// loaded in shortly after, so we have to wait for it
const findMergeButton = async () => {
return new Promise((resolve, _reject) => {
let retries = 0
const findButtonInterval = setInterval(() => {
const mergeButton = document.querySelector('.hx_create-pr-button:enabled')
if (mergeButton || retries === 500) {
clearInterval(findButtonInterval)
resolve(mergeButton)
}
retries++
}, 10)
})
}
const init = async () => {
const branchName = document.querySelector('.head-ref')?.textContent
if (branchName !== 'master-sync' &&
!branchName?.match(/Version-v[0-9\.]{1,}/)) {
return
}
const mergeButton = await findMergeButton()
if (mergeButton?.classList.contains('btn-group-squash')) {
mergeButton.onclick = (event) => {
window.alert(
'This looks like a release related PR, should you be merging this instead?'
)
}
}
}
window.onload = () => {
init()
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment