Skip to content

Instantly share code, notes, and snippets.

@EmilienD
Last active July 25, 2019 13:10
Show Gist options
  • Select an option

  • Save EmilienD/97342b6b352f08a6ac6e1d164ca329fc to your computer and use it in GitHub Desktop.

Select an option

Save EmilienD/97342b6b352f08a6ac6e1d164ca329fc to your computer and use it in GitHub Desktop.
Unsophisticated user script to create branch name out of Jira ticket page (triggered by clicking on the tomato dot in the top right corner, or ctrl+shift+B)
// ==UserScript==
// @name BRANCH_NAME_MAKER
// @include https://qover001.atlassian.net/browse/*
// @grant GM.setClipboard
// ==/UserScript==
const clickZone = document.createElement('div')
clickZone.style = `
position: absolute;
top: 15px;
right: 15px;
width: 30px;
height: 30px;
border-radius: 15px;
background-color: tomato;
z-index: 9001;
transition: background-color 0.2s linear;
`
clickZone.addEventListener('transitionend', () => {
if(clickZone.style.backgroundColor !== 'tomato'){ clickZone.style.backgroundColor = 'tomato' }
})
function branchNameToClipboard() {
const branchPrefix = document.getElementById('type-val').innerText.match(/[Bb]ug/)? 'fix':'feature'
const ticketId = location.pathname.split('/').pop()
const ticketInfo = document.getElementById('summary-val').innerText.replace(/['\[\]-]/g, ' ').trim().replace(/ +/gi, '-')
const branchName = `${branchPrefix}/${ticketId}-${ticketInfo}`
const commandLine = 'git checkout -b '
GM.setClipboard(commandLine + branchName)
clickZone.style.backgroundColor = '#FFF'
}
clickZone.addEventListener('click', branchNameToClipboard)
document.querySelector('body').append(clickZone)
document.addEventListener('keypress', e => {
e.ctrlKey && e.shiftKey && e.key === 'B' &&
branchNameToClipboard()
})
@EmilienD
Copy link
Author

EmilienD commented Jul 25, 2019

Doesn't work with the new views ¯\_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment