Skip to content

Instantly share code, notes, and snippets.

@armincerf
Last active May 7, 2021 12:04
Show Gist options
  • Save armincerf/51cb4853d51ea273fe957adc40d7a20e to your computer and use it in GitHub Desktop.
Save armincerf/51cb4853d51ea273fe957adc40d7a20e to your computer and use it in GitHub Desktop.
Run `git config --global clubhouse.token {token}` to set your ch token, then run `git clubhouse {id}` (make sure git-clubhouse is in your $PATH and executable) to checkout a new branch and push it to trigger the clubhouse hook
#! /usr/bin/env bash
function main () {
local id="$1"
local token=$(git config --global --get clubhouse.token)
local story=$(curl -s "https://api.clubhouse.io/api/v3/stories/${id}?token=${token}")
local username=$(git config --global --get github.user)
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)
local branch="${username}/ch${id}/${name}"
git checkout ${branch} 2>/dev/null || git checkout -b ${branch}
git push -u origin "${username}/ch${id}/${name}"
}
main "$@"
(defun git-branch-from-clubhouse (num)
(interactive
(list (read-string "Clubhouse card number: ")))
(async-shell-command (format "%s %s" "git clubhouse" num)))
@Roxolan0
Copy link

Roxolan0 commented Jun 3, 2019

One feature I'd like is for the git clubhouse XXX command to checkout to that branch even if it already exists. Currently that causes a fatal: A branch named 'Roxolan0/chXXX/my-clubhouse-card' already exists error and keeps me onto the current branch. I'm forced to type git checkout Roxolan0/chXXX/my-clubhouse-card which can be a mouthful with long usernames / CH card names.

@armincerf
Copy link
Author

fixed

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