Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created February 8, 2019 22:05
Show Gist options
  • Save mattdeboard/ae609734d6bdabbbd109abdece3d7833 to your computer and use it in GitHub Desktop.
Save mattdeboard/ae609734d6bdabbbd109abdece3d7833 to your computer and use it in GitHub Desktop.
Push PR merge buttons for you
function justClickIt() {
// The web-based minification tools I tried require 'var' instead of 'const'
var mergeButton = document.querySelector(".merge-message .select-menu .btn-group-squash button");
var confirmButton = document.querySelector("button.js-merge-commit-button");
// Selector for the "Update Branch" button
var updateButton = document.querySelector("form.branch-action-btn button");
console.log("Looking for the right buttons...");
if (!!updateButton && !updateButton.disabled) {
console.log("Clicking update branch button...");
updateButton.click();
} else if (mergeButton && !mergeButton.disabled) {
console.log("Merge button looks active; clicking it!");
mergeButton.click();
if (confirmButton) {
confirmButton.click();
} else {
console.log("Looks like the merge button was ready but the confirm button wasn't...");
}
}
}
setInterval(justClickIt, 3000);
@mattdeboard
Copy link
Author

mattdeboard commented Feb 8, 2019

Warning - Do not test this on open PRs you don't want merged.

This little program will just indiscriminately click merge buttons without checking with you first!

Make sure you read the source & understand what's happening before running this.

What is this?

This is a javascript snippet that eliminates having to race other devs to get your branch merged when it's ready. It accomplishes this via the following algorithm:

  • If "Update Branch" is clickable, click it.
  • If not:
    • If the "Squash and Merge" button is clickable, click it.
    • Then, click the confirm button.

It:

  • will work even if you aren't looking at the browser, or are in a different tab. You can basically hit the bookmarklet on a PR you're trying to get merged, then "AFK".
  • will stop running if you refresh or close the tab. You will then need to re-run.
  • waits 3 seconds before running. If you want to change this, change the second argument to setInterval.

Instructions

A couple ways to run this:

  1. Copy and paste the code into your Chrome console
  2. Use a bookmarklet

To create a bookmarklet (easiest way):

  1. Create a new bookmark in Chrome
  2. In the Name field, put "Pull Request Waiter" (or whatever)
  3. In the URL field, put this minified version of the code:
javascript:function justClickIt(){var a=document.querySelector(".merge-message .select-menu .btn-group-squash button"),b=document.querySelector("button.js-merge-commit-button"),c=document.querySelector("form.branch-action-btn button");console.log("Looking for the right buttons..."),c.disabled?a&&!a.disabled&&(console.log("Merge button looks active; clicking it!"),a.click(),b?b.click():console.log("Looks like the merge button was ready but the confirm button wasn't...")):(console.log("Clicking update branch button..."),c.click())}setInterval(justClickIt,3e3);

The javascript: prefix will tell Chrome to run that code when you click the bookmark. It's minified because there's a length limit to bookmark URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment