Created
April 19, 2021 09:55
-
-
Save anton-fomin/976feb64a5b6f96a8f777a7aae5f7954 to your computer and use it in GitHub Desktop.
Bookmarklet to create feature branch name from JIRA ticket on a ticket page
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:(function(){ | |
const href = window.location.href; | |
const query = href.split('?')[1]; | |
let queryObj = null; | |
if (query) { | |
queryObj = query.split('&').map(it => { | |
return it.split('=') | |
}).find(it => it[0] === 'selectedIssue'); | |
}; | |
let id = ''; | |
let rapid = false; | |
if (queryObj && queryObj[1]) { | |
id = queryObj[1]; | |
rapid = true; | |
} else { | |
const found = href.match(/browse\/([^\/]+)/); | |
if (found && found[1]) { | |
id = found[1]; | |
}; | |
}; | |
let text = ''; | |
if (rapid) { | |
text = $('h1[data-test-id="issue.views.issue-base.foundation.summary.heading"]').text().trim(); | |
} else { | |
const summary = JSON.parse(window.SPA_STATE.ISSUE[id].data.fields).find(it => it[0] === 'summary'); | |
if (summary) { | |
text = summary[1].value; | |
}; | |
}; | |
let text_normalized = text.toLowerCase().replaceAll(/[^\w\d]+/g,'-').replace(/^-+/g, ''); | |
let branch_name = 'feature/anton/' + id + '/' + text_normalized; | |
alert(branch_name); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment