Github - Open PR CheckList

check the base branch, reviews, and field updates

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Github - Open PR CheckList
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  check the base branch, reviews, and field updates
// @author       You
// @match        https://github.com/*/pull/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        none
// @license      MIT
// @require http://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements */


(function () {
    'use strict';
    $(document).ready(function () {
        function validatePR() {
            var pr_target = $("div#partial-discussion-header div.gh-header-meta span.commit-ref:not(.head-ref)");
            var pr_status = $("div#partial-discussion-header div.gh-header-meta span.State").attr("title");
            var pr_reviews = $('form.js-issue-sidebar-form[aria-label="Select reviewers"] span.css-truncate').text();
            var currentUrl = window.location.href;

            if (currentUrl.indexOf("/pull/") != -1 && pr_status.indexOf("Open") != -1) { // only handle open PRs
                var pr_merge_message = $("div#discussion_bucket div.merge-pr.Details.is-merging div.mergeability-details div.merge-message div.select-menu");

                // always remind to check field updates for backward-compatibility
                pr_merge_message.prepend("<div style=\"color:pink;\"><h4>🤨 Did you DELETE/UPDATE api fields?? If so, are the clients ready?</h4></div>");

                let badBaseBranch = false;
                let badReviewers = false;

                if (pr_target.text() === "master" || pr_target.text() === "main") {
                    pr_merge_message.prepend("<div style=\"color:orange; \"><h4>⚠️ You are merging into Master/Main branch 😱 🪵 </h4></div>");
                    badBaseBranch = true;
                }

                if (pr_reviews.indexOf("No reviews") != -1) {
                    pr_merge_message.prepend("<div style=\"color:orange;\"><h4>⚠️ This PR has no reviewers! 👀 🤔 🔍 </h4></div>");
                    badReviewers = true;
                }
                let alertMessage = '';
                if (badBaseBranch) {
                    alertMessage = 'merging to MAIN?! 😱 🪵';
                }
                if (badReviewers) {
                    alertMessage += ' no reviewers!? 👀 🤔 🔍'
                }

                if (alertMessage.length > 0) {
                    alert(alertMessage);
                }


            }

        }
        setTimeout(validatePR, 2000)

    });
})();