Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds an input to the Jira operations toolbar which contains a git command to create a new branch
// ==UserScript==
// @name StupidJira
// @namespace http://mikebell.io
// @version 0.1
// @description Add branch details
// @match https://jira.ctidigital.com/browse/*
// @grant none
//allow pasting
// ==/UserScript==
(function() {
var inputWrapper = document.createElement("form");
inputWrapper.className = 'toolbar-group aui';
inputWrapper.style.width = '310px';
var input = document.createElement("input");
input.id = "stupidjira";
input.className = "text";
input.value = "git checkout -b ";
input.value += typereturn();
input.value += '/';
input.value += getTicketId();
input.onclick = function () {
this.select();
}
input.onmouseup = function () {
return false;
}
var container = document.querySelector(".ops-menus .toolbar-split");
inputWrapper.appendChild(input);
container.appendChild(inputWrapper);
function typereturn() {
var type = document.getElementById("type-val").textContent.trim();
if (type == 'Code Sub-task') {
return 'feature';
}
else if (type == 'Story') {
return 'feature';
}
else if (type == 'Task') {
return 'feature';
}
return 'bugfix';
}
function getTicketId() {
var metas = document.getElementsByTagName('meta');
for (i=0; i<metas.length; i++) {
if (metas[i].getAttribute("name") == "ajs-issue-key") {
return metas[i].getAttribute("content");
}
}
return "";
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment