🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2025/12/24 17:04:29
🔄 下次更新时间:2025/12/24 18:04:29
手动刷新缓存

Merge All Button for GitLab

Add a button to GitLab dashboard page to merge all merge requests

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name                Merge All Button for GitLab
// @name:zh-CN          GitLab一键合并按钮
// @namespace           https://greasyfork.org/users/692574
// @version             0.0.92
// @description         Add a button to GitLab dashboard page to merge all merge requests 
// @description:zh-CN   在GitLab仪表盘界面添加一个合并所有请求的按钮
// @author              Chase Choi
// @license             MIT
// @match               https://gitlab.com/dashboard/merge_requests*
// @require             https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant               GM.xmlHttpRequest
// ==/UserScript==

const SUCCESS = 200;
const BASE_URL = window.location.origin;
const ACCESS_TOKEN = '<YOUR_ACCESS_TOKEN>';

(function() {
    'use strict';
    
    // Update DOM
    const mergeAllElement = `
        <div class="gl-ml-3">
            <a class="btn gl-button btn-confirm merge-all-btn">Merge All</a>
        </div>
    `;
    $(`${mergeAllElement}`).insertAfter($('.filter-dropdown-container'));
    $('.merge-all-btn').css('background-color', '#3C824E');

    // add event listener
    $('.merge-all-btn').click(function() {
        if (ACCESS_TOKEN == '<YOUR_ACCESS_TOKEN>') {
            alert("Empty access token!");
            return;
        }
        const text = "Are you sure to merge all?"
        if (confirm(text) == true) {
            console.log("Start merging all...");
            mergeAll();
        }
    });
})();

/**
 * Iterate all merge requests on current page and perform merge action for each one.
 */
function mergeAll() {
    // iterate merge request list
    let elements = $('li.merge-request .issuable-info .issuable-reference');
    if (elements.length) {
        elements.each(function () {
            const mergeRequestReference = $(this).text();
            if (mergeRequestReference.length) {
                const projectNamespace = mergeRequestReference.split('!')[0].trim().replaceAll('/', '%2F');
                const mergeRequestID = mergeRequestReference.split('!')[1];
                console.log(projectNamespace, mergeRequestID);
                mergeProject(projectNamespace, mergeRequestID);
            }
        });
    }
}

/**
 * Get project ID and perform merge action.
 *
 * @param {string} projectNamespace The project name with namespace.
 * @param {number} mergeRequestID The merge request ID.
 */
function mergeProject(projectNamespace, mergeRequestID) {
    GM.xmlHttpRequest({
        method: "GET",
        url: `${BASE_URL}/api/v4/projects/${projectNamespace}`,
        headers: {
            "Authorization": `Bearer ${ACCESS_TOKEN}`
        },
        onload: function (response) {
            if (response.status == SUCCESS) {
                const projectInfo = JSON.parse(response.responseText);
                console.log(`project ID: ${projectInfo.id}; merge request ID: ${mergeRequestID}`);
                performMergeAction(projectInfo.id, mergeRequestID);
            }
        }
    });
}

/**
 * Perform actual merge action for specific project.
 *
 * @param {number} projectID The project ID.
 * @param {number} mergeRequestID The merge request ID.
 */
function performMergeAction(projectID, mergeRequestID) {
    GM.xmlHttpRequest({
        method: "PUT",
        url: `${BASE_URL}/api/v4/projects/${projectID}/merge_requests/${mergeRequestID}/merge`,
        headers: {
            "Authorization": `Bearer ${ACCESS_TOKEN}`
        },
        onload: function (response) {
            if (response.status == SUCCESS) {
                console.log("Merged successfully!");
            }
        }
    });
}