Skip to content

Instantly share code, notes, and snippets.

@seletz
Last active August 29, 2015 13:56
Show Gist options
  • Save seletz/8803767 to your computer and use it in GitHub Desktop.
Save seletz/8803767 to your computer and use it in GitHub Desktop.
Bash script which creates a feature branch and adds a comment on the github issue.
#!/bin/bash
function usage() {
echo "usage: fbranch <issue no> <tagline>..."
}
issue=$1
shift
tagline=($*) # convert to array
tagline=$(printf "_%s" "${tagline[@]}") # interpose with _ (- does not work)
tagline=${tagline:1} # remove leading _
tagline=$(echo "$tagline" | tr "[:upper:]" "[:lower:]") # convert to lowercase
tagline=$(echo "$tagline" | tr "_" "-") # transform _ to -
test -z "$issue" && {
usage
exit 10
}
test -z "$tagline" && {
usage;
exit 10;
}
branch="issue${issue}-${tagline}"
echo "creating branch $branch"
git co -b $branch
echo "crating comment for issue ..."
ghi comment -m "Working on feature branch \`$branch\`" $issue
# vim: set ts=4 sw=4 expandtab nolist:

Problem

I often work on feature branches for a given Github Issue. I then like to add a comment to the issue to indicate on which branch I work, and to signal others in my team that I indeed work on that issue.

This is manual work, and so I created a little bash script which automates that. The heavy lifting is done using ghi.

Dependencies

This script uses ghi to actually create comments on a issue.

Usage

Usage is simple:

$ fbranch <issue> <tagline>....

e.g.:

$ fbranch 9 Whizbang Frobnicate foo

This will create a feature branch named issue9-whizbang-frobnicate-foo and adds a comment to issue 9 wording "Working on feature branch issue9-whizbang-frobnicate-foo"

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