Created
August 5, 2013 10:53
-
-
Save kfatehi/6155048 to your computer and use it in GitHub Desktop.
issue branching macro using ghi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Use a ruby script tucked in .rubies | |
useruby() { | |
ruby ~/.rubies/$1.rb $@ | |
} | |
## | |
# Create a new branch for an issue | |
branch_for() { | |
useruby ghi_brancher $@ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally decided to automate this part of my workflow :)