Created
September 24, 2024 14:25
-
-
Save lharby/3de870a0ef09555bae8fef5d381a5fce to your computer and use it in GitHub Desktop.
Bookmarklet to create git feature branches from JIRA
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
/** | |
* A bookmarklet for creating feature branches from JIRA/Trello/Shortcut | |
* You can use https://caiorss.github.io/bookmarklet-maker/ to turn this into a minified bookmarklet | |
*/ | |
/** | |
* This bookmarket will empty the page and then create an input and button | |
* Cut and paste the JIRA ticket name into the input | |
* For example "PJ-5625 Form validation errors" | |
* After clicking the button the output will read | |
* git checkout -b feature/pj-5625-form-validation-errors | |
* Cut and paste this into git/terminal/VSCode and so on. | |
*/ | |
document.body.replaceChildren(); | |
const template = ` | |
<input class="input" type="text" value="" /> | |
<button class="btn-run">Run</button> | |
<p class="output">Output</p> | |
`; | |
document.body.insertAdjacentHTML('beforeend', template); | |
const input = document.querySelector(".input"); | |
const output = document.querySelector(".output"); | |
const formatStr = () => { | |
let str = input.value; | |
const regex = /[- :\/]+/g; | |
str = str.replace(regex, "-"); | |
output.textContent = `git checkout -b feature/${str.toLowerCase()}`; | |
}; | |
const trigger = document.querySelector(".btn-run"); | |
trigger.addEventListener("click", () => { | |
formatStr(); | |
}); | |
document.addEventListener("DOMContentLoaded", () => { | |
input.focus(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment