Gitlab Merge request title check + Links back to Jira based on ECOD-XXXX formats
当前为
// ==UserScript==
// @name ECOD-GitLab2Jira
// @namespace ecod.gitlab.utils
// @version 2.0.0
// @description Gitlab Merge request title check + Links back to Jira based on ECOD-XXXX formats
// @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 = /ecod[ -_]?\d+/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');
}
function checkTitle(node){
let ecodRegex = /(fix|feat)\(ecod[ -_]?\d+\): \w+/i;
let result = ecodRegex.test(node.innerHTML);
return result;
}
var linkGitLab = document.createElement('span');
linkGitLab.setAttribute("style" ,"cursor:pointer;");
linkGitLab.innerHTML = `<a href='#' class='gl-button btn btn-md btn-default js-issuable-edit'
target='_blank'
style='background-color: #5707a6; color:white;'
id='linkgit'
title='Go to JIRA issue'
name='linkgit'>Goto JIRA</a>`;
var titleWarning = document.createElement('span');
titleWarning.setAttribute("style" ,"cursor:help;");
titleWarning.innerHTML = `<span
style='color:red; display: inline; padding-left: 15px; padding-right: 15px; font-size: 22px;'
id='titleWarning'
name='titleWarning'
title='Merge Request title is non-standard. Make sure you use the Jira "Merge" button to copy the standard MR name convention. Ex: fix(ecod-1234): exact Jira title'
>⚠</span>`;
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;
if(!checkTitle(node)) divContainer.appendChild(titleWarning);
divContainer.appendChild(linkGitLab);
divContainer.setAttribute("style", "margin-top:10px; display: inline");
node.appendChild(divContainer);
}
}
}
hookTheMonkeyForGitLab()
})();