Skip to content

Instantly share code, notes, and snippets.

@joshmanders
Last active March 23, 2017 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmanders/ee37c9681adc4176ad0f24751af05a1b to your computer and use it in GitHub Desktop.
Save joshmanders/ee37c9681adc4176ad0f24751af05a1b to your computer and use it in GitHub Desktop.
Git Clubhouse.io Command

Git Clubhouse.io Command

This command takes a story ID and connects to the API using your token and gets the story with that ID, determines the type and title of the story.

After it has gathered that, it slugifies the title and creates a branch in the format of {type}/{id}-{title} so for example:

❯ git clubhouse 82
Switched to a new branch 'feature/82-login-my-account-menu-item'

All you have to do is create a token for the org you're in, save git-clubhouse into your $PATH and make it executable with chmod +x git-clubhouse then setup a token in .gitconfig by running:

git config --global clubhouse.token {token}

Now just run git clubhouse {id} and watch your branch be created.

This depends on jq being installed.

#! /usr/bin/env bash
function main () {
local id="$1"
local token=$(git config --globa --get clubhouse.token)
local story=$(curl -s "https://api.clubhouse.io/api/v1/stories/${id}?token=${token}")
local type=$(echo "${story}" | jq -r '.story_type')
local name=$(echo "${story}" | jq -r '.name' | iconv -t ascii//TRANSLIT | sed -E s/[^a-zA-Z0-9]+/-/g | sed -E s/^-+\|-+$//g | tr A-Z a-z)
git checkout -b "${type}/${id}-${name}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment