git-ticket 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/.gitignore +0 -2
  2. data/Rakefile +1 -0
  3. data/VERSION +1 -1
  4. data/bin/git-ticket +78 -25
  5. metadata +16 -5
data/.gitignore CHANGED
@@ -19,5 +19,3 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
- # Because I'm right and Yehuda is wrong.
23
- *.gemspec
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "reinh@reinh.com"
11
11
  gem.homepage = "http://github.com/reinh/git-ticket"
12
12
  gem.authors = ["Rein Henrichs"]
13
+ gem.add_dependency 'commandant'
13
14
  end
14
15
  Jeweler::GemcutterTasks.new
15
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,22 +1,41 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
1
+ #!/usr/bin/env ruby -rubygems
3
2
  require 'nokogiri'
4
3
  require 'readline'
4
+ require 'commandant'
5
5
 
6
- trap('INT') { abort "Exiting..."}
6
+ include Commandant
7
7
 
8
8
  URL = "http://projects.reductivelabs.com/issues/%d.xml"
9
9
 
10
- # Flags
11
- help = ARGV.delete('--help') || ARGV.delete('-h') || ARGV.empty?
12
- branch = ARGV.delete('--branch') || ARGV.delete('-b')
13
- interactive = ARGV.delete('--interactive') || ARGV.delete('-i')
14
- delete = ARGV.delete('--delete') || ARGV.delete('-d')
15
- list = ARGV.delete('--list') || ARGV.delete('-l')
10
+ trap('INT') { abort "Exiting..."}
11
+
12
+ def parse_args(args)
13
+ # Flags
14
+ $help = args.delete('--help') || args.delete('-h') || args.empty?
15
+ $branch = args.delete('--branch') || args.delete('-b')
16
+ $interactive = args.delete('--interactive') || args.delete('-i')
17
+ $delete = args.delete('--delete') || args.delete('-d')
18
+ $list = args.delete('--list') || args.delete('-l')
19
+
20
+ $id = args.grep(/^\d+$/).first && args.grep(/^\d+$/).first.to_i
21
+ end
22
+
23
+ def existing_branch
24
+ `git branch`.gsub(/^\*?\s+/,'').split(/\n/).grep(/^(?:bug\-)?#{$id}\-/)
25
+ end
26
+
27
+ def assert_id_provided
28
+ abort "Error: ticket number required" unless $id
29
+ end
16
30
 
17
- if help
31
+ def assert_branch_exists
32
+ assert_id_provided
33
+ abort "Error: no ticket branch for #$id" if existing_branch.empty?
34
+ end
35
+
36
+ command :help do
18
37
  puts <<USAGE
19
- Usage: git-ticket [OPTION] TICKET
38
+ Usage: git-ticket [COMMAND] [OPTIONS] [TICKET]
20
39
 
21
40
  Checkout, create, delete or list ticket branches.
22
41
 
@@ -30,6 +49,16 @@ Synopsis:
30
49
  git ticket [-i, --interactive] (-b, --branch) <ticket>
31
50
  git ticket (-d, --delete) <ticket>
32
51
  git ticket (-l, --list)
52
+ git ticket list
53
+ git ticket branch [-i, --interactive] <ticket>
54
+ git ticket delete <ticket>
55
+ git ticket checkout <ticket>
56
+
57
+ Aliases:
58
+ br => branch
59
+ co => checkout
60
+ ls => list
61
+ rm => delete
33
62
 
34
63
  Options:
35
64
  -i, --interactive Interactive mode.
@@ -42,26 +71,31 @@ USAGE
42
71
  exit 0
43
72
  end
44
73
 
45
- if list
74
+ command :list do
46
75
  branches = `git branch`.gsub(/^\*?\s+/,'').split(/\n/).grep(/^(?:bug\-)?\d+\-/)
47
76
  puts branches.empty? ? "No ticket branches" : branches
48
77
  exit 0
49
78
  end
50
79
 
51
- id = ARGV.grep(/^\d+$/).first.to_i
80
+ command :branch do |args|
81
+ parse_args(args)
82
+ assert_id_provided
52
83
 
53
- if branch
54
- doc = Nokogiri::XML(`curl -s #{URL % id}`)
84
+ doc = Nokogiri::XML(`curl -s #{URL % $id}`)
55
85
 
56
- type = doc.search('issue tracker').first['name'].downcase
86
+ ticket = doc.search('issue tracker').first
87
+
88
+ abort "Error: no such ticket #$id" unless ticket
89
+
90
+ type = ticket['name'].downcase
57
91
  title = doc.search('issue subject').first.text.gsub(/\s+/, '-')
58
92
 
59
- branch_name_root = "#{'bug-' if type=="bug"}#{id}-"
93
+ branch_name_root = "#{'bug-' if type=="bug"}#{$id}-"
60
94
  branch_name = "#{branch_name_root}#{title}".downcase
61
95
  def branch_name.too_long?; length > 50 end
62
96
 
63
97
 
64
- if interactive || branch_name.too_long?
98
+ if $interactive || branch_name.too_long?
65
99
  puts "Branch name: #{branch_name}"
66
100
  new_branch_name = Readline.readline "New branch name: #{branch_name_root}"
67
101
  branch_name = branch_name_root + new_branch_name unless new_branch_name.empty?
@@ -71,16 +105,35 @@ if branch
71
105
  exit 0
72
106
  end
73
107
 
74
- existing_branch = `git branch`.gsub(/^\*?\s+/,'').split(/\n/).grep(/^(?:bug\-)?#{id}\-/)
108
+ command :delete do |args|
109
+ parse_args(args)
110
+ assert_branch_exists
75
111
 
76
- if existing_branch.empty?
77
- puts "No such ticket branch"
112
+ puts `git branch -d #{existing_branch}`
78
113
  exit 0
79
114
  end
80
115
 
81
- if delete
82
- puts `git branch -d #{existing_branch}`
83
- exit 0
116
+ command :checkout do |args|
117
+ parse_args(args)
118
+ assert_branch_exists
119
+
120
+ `git checkout #{existing_branch}`
84
121
  end
85
122
 
86
- `git checkout #{existing_branch}`
123
+ command :main do |args|
124
+ parse_args(args)
125
+
126
+ Commandant.run(:help) if $help
127
+ Commandant.run(:branch) if $branch
128
+ Commandant.run(:list) if $list
129
+ Commandant.run(:delete) if $delete
130
+
131
+ puts "Error: Unknown command #{args.first}"
132
+ puts "Available commands: #{Commandant::COMMANDS.keys.sort_by{|k| k.to_s} * ', '}"
133
+ puts
134
+ Commandant.run(:help)
135
+ end
136
+
137
+ add_alias :br => :branch, :co => :checkout, :ls => :list, :rm => :delete
138
+
139
+ run
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rein Henrichs
@@ -14,10 +14,21 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-22 00:00:00 -07:00
17
+ date: 2010-05-21 00:00:00 -07:00
18
18
  default_executable: git-ticket
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: commandant
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
21
32
  description: Checkout, create, delete or list ticket branches
22
33
  email: reinh@reinh.com
23
34
  executables: