Links back to Jira
当前为
// ==UserScript==
// @name ECOD-GitLab2Jira
// @namespace http://tampermonkey.net/
// @version 1.0.6
// @description Links back to Jira
// @author CRK
// @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()
})();