Skip to content

Instantly share code, notes, and snippets.

@philwolstenholme
Forked from mikebell/StupidJira.js
Last active October 28, 2015 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philwolstenholme/fe31065b932474cbbc2e to your computer and use it in GitHub Desktop.
Save philwolstenholme/fe31065b932474cbbc2e to your computer and use it in GitHub Desktop.
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