Skip to content

Instantly share code, notes, and snippets.

@anton-fomin
Created April 19, 2021 09:55
Show Gist options
  • Save anton-fomin/976feb64a5b6f96a8f777a7aae5f7954 to your computer and use it in GitHub Desktop.
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
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