Skip to content

Instantly share code, notes, and snippets.

@birkholz
Last active July 17, 2017 23:33
Show Gist options
  • Save birkholz/61f04cf3397a9464a108e9246380dfbe to your computer and use it in GitHub Desktop.
Save birkholz/61f04cf3397a9464a108e9246380dfbe to your computer and use it in GitHub Desktop.
A userscript for adding a 1-click approve button to PRs
// ==UserScript==
// @name GitHub 1-click PR Approve
// @namespace https://gist.github.com/birkholz
// @description Adds a 1-click approve button to Pull Requests
// @version 3
// @author https://github.com/birkholz
// @match https://github.com/*/*/pull/*/files
// @grant none
// ==/UserScript==
(function() {
'use strict';
function AddButton() {
var reviewMenu = document.querySelector('.pull-request-review-menu');
if (reviewMenu.querySelector('input[value=approve]').disabled) return;
var approveButton = document.createElement('button');
approveButton.innerText = 'Approve';
approveButton.classList.add('btn', 'btn-sm', 'btn-primary');
approveButton.type = 'button';
approveButton.style = 'margin-left:20px;';
approveButton.onclick = function(e) {
e.preventDefault();
reviewMenu.querySelector('input[value=approve]').checked = true;
reviewMenu.querySelector('button[type=submit]').click();
return false;
};
document.querySelector('.pr-review-tools').append(approveButton);
var reviewButton = document.querySelector('.js-reviews-container > button');
reviewButton.classList.remove('btn-primary');
}
window.setTimeout(AddButton, 300);
})();
@birkholz
Copy link
Author

birkholz commented Jul 17, 2017

screen shot 2017-07-17 at 12 52 35 pm

Adds a "1-Click Approve" button to the sidebar of the PR homepage.

I got tired to going to a PR, clicking "Files changed", "Review changes", "Approve", "Submit". This reduces a 4-click process down to 1.

See this revision for the sidebar button. The latest version has the button in the Files Changed tab.

@birkholz
Copy link
Author

Technical notes:

  • The "files changed" tab doesn't exist in the DOM until you click it, so we have to switch tabs before we can submit the review.
  • I hate using timeouts to add content to the DOM. I saw someone listening for pjax events, but that didn't work for me. Maybe GitHub changed their event names.

@birkholz
Copy link
Author

The button has been moved to the Files Changed tab:

screen shot 2017-07-17 at 4 21 38 pm

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