GitHub-Maintainer-Buttons

Adds four Buttons To each Commit in a GitHub pull request for selecting comment templates.

Από την 26/08/2015. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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();