ECOD-GitLab2Jira

Links back to Jira

当前为 2024-02-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ECOD-GitLab2Jira
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  Links back to Jira
// @author       [email protected]
// @match        https://gitlab.ecodesigncloud.com/ecodesign*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    function hookTheMonkeyForGitLab() {
	function goToGitLabUrl(node){
		let baseUrl = 'https://jira.fsc.atos-services.net/browse/';
		let ecodRegex = /\becod[ -_]?\d+\b/i;
		let result = ecodRegex.test(node.innerHTML);
		if(result){
			let matches = ecodRegex.exec(node.innerHTML);
			return baseUrl + matches[0];
		}
		return false;
		//window.open(baseUrl + result, '_blank');
	}

	var linkGitLab = document.createElement('span');
	linkGitLab.setAttribute("style" ,"cursor:pointer;");
	linkGitLab.innerHTML = `<a href='#' class='gl-button btn btn-md btn-default gl-display-none gl-md-display-block js-issuable-edit'
								   target='_blank'
								   style='background-color: #5707a6; color:white;'
								   id='linkgit'
                                   title='Go to JIRA issue'
								   name='linkgit'>Goto JIRA</a>`;

	let node= document.querySelector('h1[data-testid="title-content"]')
	if(!node) node = document.querySelector('h3[class="commit-title"]')
	if(node) {
		let url = goToGitLabUrl(node);
		if(url){
			let divContainer = document.createElement('div');
			linkGitLab.firstChild.href = url;
			divContainer.appendChild(linkGitLab);
			divContainer.setAttribute("style", "margin-top:10px; display: inline-block");

			node.appendChild(divContainer);
		}
	}
}
    hookTheMonkeyForGitLab()
})();