Phabricator Auto Fill Summary/Test Plan

自动填充 Summary 和 Test Plan

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Phabricator Auto Fill Summary/Test Plan
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动填充 Summary 和 Test Plan
// @match        https://code.yangqianguan.com/differential/revision/attach/*
// @grant        GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(function() {
    'use strict';

    const commitMessageURL = "http://127.0.0.1:8899/commit_message";

    GM_xmlhttpRequest({
        method: "GET",
        url: commitMessageURL,
        onload: function(response) {
            const commitMsg = response.responseText;
const lines = commitMsg.split('\n');
        const titleLine = lines[0].trim();
        const titleField = document.querySelector('input[name="title"]');
        if (titleField) titleField.value = titleLine;

        const summaryMatch = commitMsg.match(/Summary:\s*([\s\S]*?)\nTest Plan:/);
            const testPlanMatch = commitMsg.match(/Test Plan:\s*([\s\S]*?)(?:\n[A-Z][a-z]+:|$)/);

            if(summaryMatch) {
                const summaryField = document.querySelector('textarea[name="summary"]');
                if(summaryField) summaryField.value = summaryMatch[1].trim();
            }

            if(testPlanMatch) {
                const testPlanField = document.querySelector('textarea[name="testPlan"]');
                if(testPlanField) testPlanField.value = testPlanMatch[1].trim();
            }
        }
    });
})();