Github Repository Dispatch Trigger

Add repository_dispatch trigger for Github Actions

2019-12-21 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Github Repository Dispatch Trigger
// @version      0.1
// @description  Add repository_dispatch trigger for Github Actions
// @author       Texot
// @namespace    https://github.com/tete1030/github-repo-dispatcher
// @homepage     https://github.com/tete1030/github-repo-dispatcher
// @require      https://code.jquery.com/jquery-latest.min.js
// @match        https://github.com/*/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

    $(document).ready(() => {
        let btn = $("<a class='btn btn-sm'>Repo Dispatch</a>");
        btn.on("click", () => {
            let token = GM_getValue("token", "");
            if (!token) {
                token = window.prompt("Token");
            }
            if (!token) return;
            GM_setValue("token", token);
            let pathArray = window.location.pathname.split('/');
            if (pathArray.length < 3) return;
            let type = window.prompt("Type", GM_getValue("type", ""));
            if (!type) return;
            GM_setValue("type", type);
            let payload = window.prompt("Client Payload", GM_getValue("payload", ""));
            if (payload === null) return;
            GM_setValue("payload", payload);
            let data = {event_type: type};
            try {
                if (payload) data.client_payload = JSON.parse(payload);
            } catch (e) {
                window.alert("JSON parse failed: " + e.message);
                return;
            }
            GM_xmlhttpRequest({
                method: "POST",
                url: "https://api.github.com/repos/" + pathArray[1] + "/" + pathArray[2] + "/dispatches",
                headers: {"Authorization": "token " + token, "Accept": "application/vnd.github.everest-preview+json"},
                data: JSON.stringify(data),
                onload: (resp) => {
                    if (resp.status == 204 || resp.status == 200) {
                        console.log("Repo dispatch succeed: " + resp.responseText);
                        window.alert("Repo dispatch succeed" + (resp.responseText?(": " + resp.responseText):""));
                    } else {
                        var message = resp.responseText;
                        try {
                            message = JSON.parse(message).message;
                        } catch (e) {}
                        console.log("Repo dispatch failed: " + resp.responseText);
                        window.alert("Repo dispatch failed: " + message);
                    }
                },
                onerror: (e) => {
                    console.log("Repo dispatch failed: " + e);
                    window.alert("Repo dispatch failed: " + e.message);
                }
            });
        });
        $(".pagehead-actions").eq(0).prepend($("<li></li>").append(btn));
    });

})();