Last active
April 20, 2018 09:45
-
-
Save Craga89/9a61dbda8729b33f976cc91349dbe726 to your computer and use it in GitHub Desktop.
Launches the Bitbucket Server "Create Branch" dialog with correct params based on your selected JIRA issue (or prompts if none selected)
This file contains hidden or 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:(async function openDialog() { let issueTypesMap = { 'Sub-bug': 'Bug', 'Sub-task': 'Story', 'Task': 'Story' }; let issueKey; if (/^\/browse\//.test(location.pathname)) { issueKey = (location.pathname.match(/^\/browse\/([^&\/]+)/) || [])[1]; } else { issueKey = (window.location.search.match(/selectedIssue=([^&]+)/) || [])[1]; } if (!issueKey) { issueKey = prompt('No Issue Key detected on the page. Enter the Issue Key here'); } const request = await fetch('https://communicatorcorp.atlassian.net/rest/api/2/issue/' + issueKey, { credentials: 'include' }); const json = await request.json(); const issueTypeName = json.fields.issuetype.name; const issueType = issueTypesMap[issueTypeName] || issueTypeName; const branchNameSlug = json.fields.summary.toString().toLowerCase() .replace(/\s+/g, '-') /* Replace spaces with - */ .replace(/[^\w\-]+/g, '') /* Remove all non-word chars */ .replace(/\-\-+/g, '-') /* Replace multiple - with single - */ .replace(/^-+/, '') /* Trim - from start of text */ .replace(/-+$/, ''); /* Trim - from end of text */ const queryStr = [ 'issueKey=' + issueKey, 'issueType=' + issueType, 'branchName=' + (issueKey + '-' + branchNameSlug) ].join('&'); window.open('http://git.cc-corp.int/plugins/servlet/create-branch?' + queryStr); }) () |
This file contains hidden or 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:(async function openDialog() { | |
let issueTypesMap = { | |
'Sub-bug': 'Bug', | |
'Sub-task': 'Story', | |
'Task': 'Story' | |
}; | |
let issueKey; | |
if (/^\/browse\//.test(location.pathname)) { | |
issueKey = (location.pathname.match(/^\/browse\/([^&\/]+)/) || [])[1]; | |
} | |
else { | |
issueKey = (window.location.search.match(/selectedIssue=([^&]+)/) || [])[1]; | |
} | |
if (!issueKey) { | |
issueKey = prompt('No Issue Key detected on the page. Enter the Issue Key here'); | |
} | |
const request = await fetch('https://communicatorcorp.atlassian.net/rest/api/2/issue/' + issueKey, { credentials: 'include' }); | |
const json = await request.json(); | |
const issueTypeName = json.fields.issuetype.name; | |
const issueType = issueTypesMap[issueTypeName] || issueTypeName; | |
const branchNameSlug = json.fields.summary.toString().toLowerCase() | |
.replace(/\s+/g, '-') /* Replace spaces with - */ | |
.replace(/[^\w\-]+/g, '') /* Remove all non-word chars */ | |
.replace(/\-\-+/g, '-') /* Replace multiple - with single - */ | |
.replace(/^-+/, '') /* Trim - from start of text */ | |
.replace(/-+$/, ''); /* Trim - from end of text */ | |
const queryStr = [ | |
'issueKey=' + issueKey, | |
'issueType=' + issueType, | |
'branchName=' + (issueKey + '-' + branchNameSlug) | |
].join('&'); | |
window.open('http://git.cc-corp.int/plugins/servlet/create-branch?' + queryStr); | |
}) | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment