Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@kfatehi

kfatehi Aug 5, 2013

Finally decided to automate this part of my workflow :)

Owner

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