GitHub-Maintainer-Buttons

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

目前為 2015-08-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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