Last active
April 26, 2022 16:09
-
-
Save lcorneliussen/7250016 to your computer and use it in GitHub Desktop.
A bookmarklet for copying jira issues keys and summaries from a agile planning page or an open jira issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Create the bookmarklet here: http://mrcoles.com/bookmarklet/ */ | |
function buildDialog($) { | |
var host = window.location.protocol + "//" + window.location.hostname; | |
var issues = $('.ghx-selected') | |
.filter('.js-issue') | |
.add($('.jpoc-checkbox-selected').parents('.rm-table-line')) | |
.add($('#issuetable .issuerow')) | |
.map(function(i, issue) { | |
var $i = $(issue); | |
var k = $i.attr("data-issue-key") || $(issue).find(".jpo-key").text() || $i.find('.issue-link').attr("data-issue-key"); | |
var s = $i.find('.ghx-summary').attr("data-tooltip") || $i.find('.jpo-text').text() || $i.find('.summary').text(); | |
var type = $i.find('.ghx-type').attr("title") || $i.find('.ghx-field-icon').attr('data-tooltip') || $i.find('.issuetype img').attr('alt'); | |
return { key: k, summary: s, type: type }; | |
}).toArray(); | |
/* copy issue from open issue */ | |
var t = document.title.replace(" - JIRA", "").replace(" - Jira", ""); | |
var match = t.match(/\[(.*)\]/); | |
if (match) { | |
var k = match[1]; | |
issues.push({ | |
key: k, | |
type: $('#type-val').text().trim(), | |
summary: t.replace("[" + k + "] ", "")}) | |
} | |
for( var pos in issues ){ | |
var i = issues[pos]; | |
if (i.key) i.link = host + '/browse/' + i.key; | |
if (i.summary) i.summary = i.summary.trim() | |
} | |
console.log(issues); | |
var simplelist = jQuery.map(issues, function(i){ | |
return "[" + i.key + "] " + (i.type ? i.type + ": " : "") + i.summary ; | |
}).join("\r"); | |
var wiki = jQuery.map(issues, function(i){ | |
return "[" + i.key + "|" + i.link + "] " + (i.type ? i.type + ": " : "") + i.summary ; | |
}).join("\r"); | |
var plainLinks = jQuery.map(issues, function(i){ | |
return i.link; | |
}).join("\r"); | |
return { | |
text: { | |
'Simple list': simplelist, | |
'Wiki markup': wiki, | |
'Just links': plainLinks | |
}, | |
html: { | |
'Links': jQuery.map(issues, function(i){ | |
return "<a href='" + i.link + "'>[" + i.key + "]</a> " + (i.type ? i.type + ": " : "") + i.summary + "" ; | |
}).join("<br>") | |
} | |
}; | |
} | |
function getScript(url, success) { | |
var script = document.createElement('script'); | |
script.src = url; | |
var head = document.getElementsByTagName('head')[0]; | |
var completed = false; | |
script.onload = script.onreadystatechange = function () { | |
if (!completed && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { | |
completed = true; | |
success(); | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
} | |
getScript("https://code.jquery.com/jquery-3.6.0.min.js", function () { | |
getScript("https://code.jquery.com/ui/1.13.1/jquery-ui.min.js", function () { | |
var $ = jQuery.noConflict(); | |
var myStylesLocation = "https://code.jquery.com/ui/1.13.1/themes/cupertino/jquery-ui.css"; | |
$('<link rel="stylesheet" type="text/css" href="'+myStylesLocation+'" >').appendTo("head"); | |
$('<style> .ui-dialog { z-index: 1000 !important ;}</style>').appendTo("head"); | |
var result = buildDialog($); | |
var text = ""; | |
for(var prop in result.text) { | |
text += "<h2>" + prop + "</h2>"; | |
text += "<pre>" + result.text[prop] + "</pre><br/>"; | |
} | |
for(var prop in result.html) { | |
text += "<h2>" + prop + "</h2>"; | |
text += "<div>" + result.html[prop] + "</div><br/>"; | |
} | |
try { | |
var oldDiag = $('#jira-issues-dialog'); | |
oldDiag.filter('.ui-dialog-content').dialog('destroy').remove(); | |
} catch(e){} | |
var d = $("<div id='jira-issues-dialog'>" + "<pre>" + text + "</pre>" + "</p></div>").appendTo("body"); | |
d.dialog( { | |
"width":"90%", | |
close: function(event, ui) { | |
$(this).dialog('destroy').remove(); | |
} | |
}); | |
}); | |
}); |
@tdalon here a version with type and link: https://gist.github.com/mheiniger/6181dc4115c0a218c2b2/5817f42be3a0cf8bce58a4f5b481f006771dfa5d
Really nice to see others use it, too :)
Your version with type and link doesn't work from issue details... Havn't tried from board and issue navigator...
Shows "undefined" then...
Here's a variation that generates Markdown table syntax: https://gist.github.com/CodeCommander/6b80a3bea770d8c1be0ed7920338cb99#file-jira-extract-issue-links-js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. Looks great!
How would you add the issue type?