Adds four Buttons To each Commit in a GitHub pull request for selecting comment templates.
Version vom
// ==UserScript==
// @name GitHub-Maintainer-Buttons
// @namespace https://pruetz.net/userscript/github/maintainer-buttons
// @include https://github.com/*/pull/*
// @version 1
// @grant none
// @description Adds four Buttons To each Commit in a GitHub pull request for selecting comment templates.
// ==/UserScript==
var commit_id = function (element) {
return $(element).contents()[0].data;
};
var new_comment_field = $('#new_comment_field');
var fill_and_focus_comment = function(text) {
new_comment_field.val(text);
new_comment_field.focus();
};
var provide_feedback = function(commit_id) {
fill_and_focus_comment("FEEDBACK (" + commit_id + ")\n\n* [ ] ");
};
var request_review = function(commit_id) {
fill_and_focus_comment("REVIEW (" + commit_id + ")\n\n[Cruise]() (" + commit_id + ")");
};
var say_its_ok = function(commit_id) {
fill_and_focus_comment("OK (" + commit_id + ")");
};
var say_it_looks_good = function(commit_id) {
fill_and_focus_comment("LGTM (" + commit_id + ")");
};
var add_button = function(dom_sibling, title, icon, click_handler) {
// octicon class in conjunction with dark user stlye utterly destroys button style
$("<button class='btn btn-sm octicon-" + icon + "' style='font: 16px/1 octicons; margin-left: 1px; margin-right: 1px;' title='" + title + "'></button>").
appendTo($(dom_sibling.parentNode)).click(click_handler);
};
var add_maintainer_buttons = function () {
var commit_id_elements = $('.commit-id');
$.each(commit_id_elements, function(index, dom_element) {
add_button(dom_element, "Feedback", "comment", function() { provide_feedback(commit_id(dom_element)); });
add_button(dom_element, "Review", "eye", function() { request_review(commit_id(dom_element)); });
add_button(dom_element, "Ok", "check", function() { say_its_ok(commit_id(dom_element)); });
add_button(dom_element, "Seems fine", "thumbsup", function() { say_it_looks_good(commit_id(dom_element)); });
});
};
add_maintainer_buttons();