Last active
July 24, 2023 09:26
-
-
Save Benjaminhu/3208d2945b5e1c36d6c222a564ec3707 to your computer and use it in GitHub Desktop.
JavaScript Bookmarklet: make a branch name from a Jira ticket
This file contains 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
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