a bookmarklet to generate the branch name from an open jira story

Posted . Visible to the public.
javascript: (function ($) {
  var branchName = "nothing found" ;
  var story = jQuery(".ghx-fieldname-issuekey a");
  if(story){
    var title = $("[data-field-id='summary']").text();
    var id = story.text();
    
    var translate = {
      "ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"
    };

    var cleanedTitle = title.toLowerCase().replace(/[öäüß]/g, function(match) { 
      return translate[match]; 
    }).replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_/, "").replace(/_$/, "");

    var cleanedId = id.toUpperCase().replace(/[öäüß]/g, function(match) { 
      return translate[match]; 
    }).replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-/, "").replace(/-$/, "");

    
    var storyType = "feature";
    var gitptTitle = id + '-' + title;

    var branchName = storyType + "/" +  cleanedId +"_" + cleanedTitle;

    prompt('Your branch Name:', branchName);
  } else {
    alert("Please select the stories first.");
  }
})(jQuery);
Christoph Beck
Last edit
Posted by Christoph Beck to BitCrowd (2014-06-23 16:01)