Rename Merge Request Title Automatically

Compatible gitlab

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Rename Merge Request Title Automatically
// @name:es Rename Merge Request Title Automatically
// @description Compatible gitlab
// @description:es Compatible gitlab
// @date 2022-03-21
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @license CC BY-NC-ND 4.0 International. https://creativecommons.org/licenses/by-nc-nd/4.0/
// @match *://*.gitlab.com/*
// @match *://gitlab.*.com.*/*
// @version 0.1
// @namespace https://greasyfork.org/en/users/314553-stefango
// ==/UserScript==
(() => {
  if (window.location.href.includes('cherry-pick')) {
    const branchSelector = document.getElementsByClassName("branch-selector");
    const texto = branchSelector[0].innerText;
    const textoToInput = texto.split(' ');
    const source = textoToInput[1];
    const target = textoToInput[3];
    const url = window.location.href;
    const originalTitle = document.getElementById("merge_request_title").value;

    if (originalTitle.startsWith('Merge branch')) {
      let titleArr = document.getElementById("merge_request_title").value.split(' ');
      titleArr.splice(-1, 1, `'${target}'`);
      document.getElementById("merge_request_title").value = titleArr.join(' ');
    } else {
      // rename manually when code conflicted
    }
  }
})();