Last active
November 15, 2017 02:01
-
-
Save rajadain/438b8dfad5d9596cc9bff989516af82a to your computer and use it in GitHub Desktop.
GitHub Pull Request Unstable Warner Tampermonkey Script
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
// ==UserScript== | |
// @name Unstable Warner | |
// @namespace http://tampermonkey.net/ | |
// @version 0.5 | |
// @description Warn before merging unstable pull requests on GitHub | |
// @author Terence Tuhinanshu @rajadain | |
// @match https://github.com/**/pull/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const submitButton = '.btn-group-merge>button[type="submit"]'; | |
const cancelButton = '.commit-form-actions>.js-menu-container>button[type="button"]'; | |
let message = "No problems with this Pull Request."; | |
const hasFixups = () => { | |
message = "This Pull Request has FIXUP or WIP commits. Do you really want to merge this?"; | |
return [...document.querySelectorAll('.commit-message')] | |
.filter(commit => commit.innerText.toLowerCase().indexOf('fixup') >= 0 || | |
commit.innerText.toLowerCase().indexOf('wip') >= 0) | |
.length > 0; | |
}; | |
const isUnstable = () => { | |
message = "This Pull Request is UNSTABLE. Do you really want to merge this?"; | |
return document.querySelector('.branch-action.branch-action-state-unstable'); | |
}; | |
document | |
.querySelector(submitButton) | |
.addEventListener('click', event => { | |
if ((hasFixups() || isUnstable()) && !confirm(message)) { | |
event.preventDefault(); | |
document.querySelector(cancelButton).click(); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment