NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Copy Git branch name from Jira
// @version 1.0.1
// @copyright 2020, Milan Farkas / WRD Labs Zrt. (https://www.wrd.hu)
// @namespace www.wrd.hu
// @description DEPRECATED! Adds a button to Jira that copies the suggested Git branch name to the clipboard
// @author milanfarkas
// @license MIT
// @include /https?:\/\/jira.*\/browse\/.*
// @include /https?:\/\/jira.*\/secure\/RapidBoard.jspa.*
// @include /https?:\/\/jira.*\/.*issues.*
// @require https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js
// @updateURL https://openuserjs.org/meta/milanfarkas/Copy_Git_branch_name_from_Jira.meta.js
// @downloadURL https://openuserjs.org/install/milanfarkas/Copy_Git_branch_name_from_Jira.user.js
// ==/UserScript==
// ==OpenUserJS==
// @author milanfarkas
// ==/OpenUserJS==
(function () {
'use strict';
$(document).ajaxComplete(() => initPlugin());
let initPlugin = () => {
if (!$('#gitClipboardBtn').length) {
$('#ghx-detail-head .ghx-controls').prepend("<button id='gitClipboardBtn' style='margin-left:0;' class='copy-gitbranch-button aui-button ghx-actions aui-button-compact aui-button-subtle'><span class='icon icon-default aui-icon aui-icon-small aui-iconfont-devtools-branch-small'></span> Branch</button>");
$('.aui-toolbar2-secondary').prepend("<div id='opsbar-jira.issue.tools' class='aui-buttons pluggable-ops'><a id='gitClipboardBtn' href='#' class='copy-gitbranch-button aui-button'><span class='icon icon-default aui-icon aui-icon-small aui-iconfont-devtools-branch-small'></span> <span>Branch</span></a></div>");
$(".copy-gitbranch-button").off("click");
$(".copy-gitbranch-button").click(copyTaskKeyAndTitle);
}
};
let copyTaskKeyAndTitle = () => {
let issueKey = $('#key-val').text();
if (issueKey === '') {
issueKey = $('#issuekey-val').text();
}
const issueTitle = $('#summary-val').text();
const plainText = (issueKey + '_' + issueTitle)
.toLowerCase()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/\W+/g, '-')
.toLowerCase();
copyToClipboard(plainText);
$.notify(plainText, 'success');
};
let copyToClipboard = (plainText) => {
function listener(e) {
e.clipboardData.setData("text/plain", plainText);
e.preventDefault();
}
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
};
})();