Skip to content

Instantly share code, notes, and snippets.

@rajadain
Last active November 15, 2017 02:01
Show Gist options
  • Save rajadain/438b8dfad5d9596cc9bff989516af82a to your computer and use it in GitHub Desktop.
Save rajadain/438b8dfad5d9596cc9bff989516af82a to your computer and use it in GitHub Desktop.
GitHub Pull Request Unstable Warner Tampermonkey Script
// ==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