Skip to content

Instantly share code, notes, and snippets.

@kfatehi
Created August 5, 2013 10:53
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 kfatehi/6155048 to your computer and use it in GitHub Desktop.
Save kfatehi/6155048 to your computer and use it in GitHub Desktop.
issue branching macro using ghi
##
# Use a ruby script tucked in .rubies
useruby() {
ruby ~/.rubies/$1.rb $@
}
##
# Create a new branch for an issue
branch_for() {
useruby ghi_brancher $@
}
module Keyvan
module Rubies
module GhiBrancher
class << self
def run
if (input = ARGV[1].to_i) == 0
puts "Expected an issue #"
exit(1)
end
issues.each do |number, description|
if input == number.to_i
create_branch number, description
exit(0)
end
end
# Still here? I guess I didn't find that issue
puts "Issue #{input} not found!"
issues.each do |n,d|
puts " #{n} #{d}"
end
exit(2)
end
def sanitize text
text.gsub(" ", "_").downcase
end
def create_branch issue_no, description
name = "#{issue_no}_#{sanitize(description)}"
cmd = "git checkout -b #{name}"
puts "Press any key to #{cmd}"
STDIN.gets
puts `#{cmd}`
rescue Interrupt
puts "ancelled"
end
def issues
@issues ||= begin
puts "Fetching issue list from GitHub"
ghi = `ghi list -p -s 'open'`.strip
Hash[ghi.scan(/ (\d+) ([\w|\ ]+) /)]
end
end
end
end
end
end
Keyvan::Rubies::GhiBrancher.run
➜ bait git:(master) daf branch_for 30
sourcing /Users/keyvan/.keyvanrc
Fetching issue list from GitHub
Press any key to git checkout -b 30_coverage_report
Switched to a new branch '30_coverage_report'
➜ bait git:(30_coverage_report) branch_for 200
Fetching issue list from GitHub
Issue 200 not found!
34 Improve User Interface
30 Coverage Report
23 Security
22 Establish a convention for static analysis
➜ bait git:(30_coverage_report) branch_for 23
Fetching issue list from GitHub
Press any key to git checkout -b 23_security
^Cancelled
@kfatehi
Copy link
Author

kfatehi commented Aug 5, 2013

Finally decided to automate this part of my workflow :)

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