GitHub-Maintainer-Buttons

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

2015-08-26 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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();