Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Benjaminhu/3208d2945b5e1c36d6c222a564ec3707 to your computer and use it in GitHub Desktop.
Save Benjaminhu/3208d2945b5e1c36d6c222a564ec3707 to your computer and use it in GitHub Desktop.
JavaScript Bookmarklet: make a branch name from a Jira ticket
javascript:
// steps:
// 1. copy code
// 2. go to: http://subsimple.com/bookmarklets/jsbuilder.htm
// 3. paste code after: "javascript:"
// 4. [optional] customize "removeRegexp"
// 5. add name
// 6. push "(function...)"
// 7. push "comress"
// 8. drag & drop your bookmarklet name to your bookmark tab
var removeRegexp = new RegExp(/^[A-Z,\s]{2,} *\-/);
function myQuery(selector) {
return jQuery(selector);
}
function ucwords(str) {
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
}
function removeAccents(str) {
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
function removeWhitespaces(str) {
return str.replace(/ /g, '');
}
function removeNotNeedCharacters(str) {
return str.replace(/[^a-z0-9]/ig, '');
}
function removeUppercasePrefix(str) {
return str.replace(removeRegexp, '');
}
function getGitBranchName(issueId, issueTitle) {
var branchName = removeWhitespaces(removeNotNeedCharacters(ucwords(removeUppercasePrefix(removeAccents(issueTitle)))));
return issueId + '_' + branchName;
}
function initGitBranchName() {
// breadcumb last item: Projects / DEV / EPIC-954 / TICKET-1084
var issueId = myQuery('nav[aria-label="Breadcrumbs"] li:last a span').text();
var issueTitle = myQuery('h1').text();
var gitBranchName = getGitBranchName(issueId, issueTitle);
console.log('branch name: ' + gitBranchName);
alert(gitBranchName);
}
initGitBranchName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment