Browse files

Initial commit to git-ticket.

  • Loading branch information...
0 parents commit 62f325687fee3870a2ecd5bbc70935ec41888342 @reinh committed Apr 22, 2010
Showing with 174 additions and 0 deletions.
  1. +5 −0 .document
  2. +23 −0 .gitignore
  3. +20 −0 LICENSE
  4. +21 −0 README
  5. +19 −0 Rakefile
  6. +86 −0 bin/git-ticket
5 .document
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
23 .gitignore
@@ -0,0 +1,23 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+
+## PROJECT::SPECIFIC
+# Because I'm right and Yehuda is wrong.
+*.gemspec
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Rein Henrichs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 README
@@ -0,0 +1,21 @@
+Usage: git-ticket [OPTION] TICKET
+
+Checkout, create, delete or list ticket branches.
+
+Based on the git workflow described in
+ http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html
+
+NOTE: Currently designed to work with Redmine only.
+
+Synopsis:
+ git ticket <ticket>
+ git ticket [-i, --interactive] (-b, --branch) <ticket>
+ git ticket (-d, --delete) <ticket>
+ git ticket (-l, --list)
+
+Options:
+ -i, --interactive Interactive mode.
+ -b, --branch Create a new ticket branch.
+ -d, --delete Delete a ticket branch.
+ -l, --list List all ticket branches.
+ -h, --help You're reading it.
19 Rakefile
@@ -0,0 +1,19 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "git-ticket"
+ gem.summary = %Q{Checkout, create, delete or list ticket branches}
+ gem.description = gem.summary
+ gem.email = "reinh@reinh.com"
+ gem.homepage = "http://github.com/reinh/git-ticket"
+ gem.authors = ["Rein Henrichs"]
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+task :default => :build
86 bin/git-ticket
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'nokogiri'
+require 'readline'
+
+trap('INT') { abort "Exiting..."}
+
+URL = "http://projects.reductivelabs.com/issues/%d.xml"
+
+# Flags
+help = ARGV.delete('--help') || ARGV.delete('-h') || ARGV.empty?
+branch = ARGV.delete('--branch') || ARGV.delete('-b')
+interactive = ARGV.delete('--interactive') || ARGV.delete('-i')
+delete = ARGV.delete('--delete') || ARGV.delete('-d')
+list = ARGV.delete('--list') || ARGV.delete('-l')
+
+if help
+ puts <<USAGE
+Usage: git-ticket [OPTION] TICKET
+
+Checkout, create, delete or list ticket branches.
+
+Based on the git workflow described in
+ http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html
+
+NOTE: Currently designed to work with Redmine only.
+
+Synopsis:
+ git ticket <ticket>
+ git ticket [-i, --interactive] (-b, --branch) <ticket>
+ git ticket (-d, --delete) <ticket>
+ git ticket (-l, --list)
+
+Options:
+ -i, --interactive Interactive mode.
+ -b, --branch Create a new ticket branch.
+ -d, --delete Delete a ticket branch.
+ -l, --list List all ticket branches.
+ -h, --help You're reading it.
+USAGE
+
+ exit 0
+end
+
+if list
+ branches = `git branch`.gsub(/^\*?\s+/,'').split(/\n/).grep(/^(?:bug\-)?\d+\-/)
+ puts branches.empty? ? "No ticket branches" : branches
+ exit 0
+end
+
+id = ARGV.grep(/^\d+$/).first.to_i
+
+if branch
+ doc = Nokogiri::XML(`curl -s #{URL % id}`)
+
+ type = doc.search('issue tracker').first['name'].downcase
+ title = doc.search('issue subject').first.text.gsub(/\s+/, '-')
+
+ branch_name_root = "#{'bug-' if type=="bug"}#{id}-"
+ branch_name = "#{branch_name_root}#{title}".downcase
+ def branch_name.too_long?; length > 50 end
+
+
+ if interactive || branch_name.too_long?
+ puts "Branch name: #{branch_name}"
+ new_branch_name = Readline.readline "New branch name: #{branch_name_root}"
+ branch_name = branch_name_root + new_branch_name unless new_branch_name.empty?
+ end
+
+ `git checkout -b #{branch_name}`
+ exit 0
+end
+
+existing_branch = `git branch`.gsub(/^\*?\s+/,'').split(/\n/).grep(/^(?:bug\-)?#{id}\-/)
+
+if existing_branch.empty?
+ puts "No such ticket branch"
+ exit 0
+end
+
+if delete
+ puts `git branch -d #{existing_branch}`
+ exit 0
+end
+
+`git checkout #{existing_branch}`

0 comments on commit 62f3256

Please sign in to comment.