maxim-lighthouse_cli 1.0.1 → 1.1.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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ .rake_tasks~
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.authors = ["Maxim Chernyak"]
13
13
  gem.add_dependency "cldwalker-hirb"
14
14
  gem.add_development_dependency "thoughtbot-shoulda"
15
- gem.files.include %w(Lhcfile vendor/* vendor/lighthouse-api/* vendor/lighthouse-api/lib/* vendor/lighthouse-api/lib/lighthouse/*)
15
+ gem.files.include %w(Lhcfile lib/lighthouse_cli/* vendor/* vendor/lighthouse-api/* vendor/lighthouse-api/lib/* vendor/lighthouse-api/lib/lighthouse/*)
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
18
18
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
data/bin/lh CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- require 'yaml'
4
- require 'hirb'
5
3
  require 'lighthouse_cli'
6
- LighthouseCLI::Parser.go!
4
+ LighthouseCLI::Parser.parse_argv!
@@ -0,0 +1,25 @@
1
+ module LighthouseCLI
2
+ class Authenticator
3
+ class << self
4
+ def authenticate!
5
+ auth_data = Config.token ? Config.token : [Config.username, Config.password]
6
+ auth_data.flatten!
7
+
8
+ if auth_data.size == 1
9
+ authenticate_by_token(*auth_data)
10
+ else
11
+ authenticate_by_credentials(*auth_data)
12
+ end
13
+ end
14
+
15
+ private
16
+ def authenticate_by_token(token)
17
+ Lighthouse.token = token
18
+ end
19
+
20
+ def authenticate_by_credentials(user, pass)
21
+ Lighthouse.authenticate(user, pass)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,68 @@
1
+ module LighthouseCLI
2
+ module Commands
3
+ def add(title, tags = [])
4
+ create_ticket(title, tags)
5
+ puts "Ticket added."
6
+ end
7
+
8
+ def list(which = "next")
9
+ tickets = case which
10
+ when 'next'
11
+ fetch_tickets("responsible:me milestone:#{next_milestone.title} state:open sort:priority")
12
+ end
13
+
14
+ display_tickets tickets
15
+ end
16
+
17
+ def resolve(id)
18
+ t = fetch_ticket(id)
19
+ t.state = 'resolved'
20
+ if t.save
21
+ puts "Resolved: \"#{t.title}\""
22
+ else
23
+ puts "Failed trying to resolve ticket."
24
+ end
25
+ end
26
+
27
+ def open(id)
28
+ t = fetch_ticket(id)
29
+ t.state = 'new'
30
+ if t.save
31
+ puts "Opened: \"#{t.title}\""
32
+ else
33
+ puts "Failed trying to open ticket."
34
+ end
35
+ end
36
+
37
+ def show(id)
38
+ ticket = fetch_ticket(id)
39
+ puts " Ticket ##{id} (#{ticket.state})"
40
+ puts " #{ticket.title}"
41
+ puts " #{ticket.body}" unless ticket.body.blank?
42
+ puts " #{ticket.tags.join(', ')}" unless ticket.tags.blank?
43
+ end
44
+
45
+ def help
46
+ puts <<-TEXT
47
+ Available commands:
48
+ help
49
+ Show this text.
50
+
51
+ list
52
+ List all assigned tickets from upcoming milestone.
53
+
54
+ show 50
55
+ Show details for ticket with given id.
56
+
57
+ add "Ticket name" "tag1 tag2"
58
+ Add ticket for yourself into current milestone with (optional) tags and without any body.
59
+
60
+ resolve 50
61
+ Mark ticket 50 resolved.
62
+
63
+ open 50
64
+ Mark ticket 50 new.
65
+ TEXT
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ module LighthouseCLI
2
+ class Config
3
+ class << self
4
+ def method_missing(meth, *args, &blk)
5
+ load_config!
6
+ @config[meth]
7
+ end
8
+
9
+ private
10
+ def load_config!(config_path = DEFAULT_CONFIG_PATH)
11
+ @config ||= YAML.load_file(config_path).symbolize_keys
12
+ rescue
13
+ raise RuntimeError.new("Error: You must put either lighthouse token or space-separated username and password in your Lhcfile. Don't forget to ignore it in git.")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ module LighthouseCLI
2
+ module Helpers
3
+ private
4
+ include Hirb::Helpers
5
+
6
+ def create_ticket(title, tags)
7
+ ticket = Lighthouse::Ticket.new(:project_id => @project.id)
8
+ ticket.title = title
9
+ ticket.tags = tags.split
10
+ ticket.save
11
+ end
12
+
13
+ def fetch_ticket(id)
14
+ Lighthouse::Ticket.find(id, q)
15
+ end
16
+
17
+ def fetch_tickets(str = '')
18
+ query = q(str)
19
+ Lighthouse::Ticket.find(:all, query)
20
+ end
21
+
22
+ def q(str = '')
23
+ {:params => {:q => str, :project_id => @project.id}}
24
+ end
25
+
26
+ def next_milestone
27
+ @next_milestone ||= @project.milestones.find_all{|m| m.due_on > Time.now}.min{|a,b| a.due_on <=> b.due_on}
28
+ end
29
+
30
+ def display_tickets(tickets)
31
+ puts AutoTable.render tickets, :fields => [:number, :title], :max_width => width
32
+ end
33
+
34
+ def width
35
+ `stty size`.split.map { |x| x.to_i }.reverse.second
36
+ rescue
37
+ 30
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ module LighthouseCLI
2
+ class Parser
3
+ class << self
4
+ include Helpers
5
+ include Commands
6
+
7
+ def parse_argv!
8
+ (help; return) if ARGV.blank?
9
+
10
+ LighthouseCLI.bootstrap!
11
+ @project = LighthouseCLI.project
12
+
13
+ if self.respond_to?(meth = ARGV.shift.to_sym) && meth != :parse_argv!
14
+ self.send(meth, *ARGV)
15
+ else
16
+ puts "Unknown command \"#{meth}\"."
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,13 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'lighthouse-api', 'lib', 'lighthouse-api'))
2
2
 
3
+ require 'yaml'
4
+ require 'hirb'
5
+ require 'lighthouse_cli/config'
6
+ require 'lighthouse_cli/authenticator'
7
+ require 'lighthouse_cli/helpers'
8
+ require 'lighthouse_cli/commands'
9
+ require 'lighthouse_cli/parser'
10
+
3
11
  module LighthouseCLI
4
12
  DEFAULT_CONFIG_PATH = "Lhcfile"
5
13
 
@@ -21,151 +29,4 @@ module LighthouseCLI
21
29
  end
22
30
 
23
31
  module_function :bootstrap!, :project
24
-
25
-
26
- class Authenticator
27
- class << self
28
- def authenticate!
29
- auth_data = Config.token ? Config.token : [Config.username, Config.password]
30
- auth_data.flatten!
31
-
32
- if auth_data.size == 1
33
- authenticate_by_token(*auth_data)
34
- else
35
- authenticate_by_credentials(*auth_data)
36
- end
37
- end
38
-
39
- private
40
- def authenticate_by_token(token)
41
- Lighthouse.token = token
42
- end
43
-
44
- def authenticate_by_credentials(user, pass)
45
- Lighthouse.authenticate(user, pass)
46
- end
47
- end
48
- end
49
-
50
- class Config
51
- class << self
52
- def method_missing(meth, *args, &blk)
53
- load_config!
54
- @config[meth]
55
- end
56
-
57
- private
58
- def load_config!(config_path = DEFAULT_CONFIG_PATH)
59
- @config ||= YAML.load_file(config_path).symbolize_keys
60
- rescue
61
- raise RuntimeError.new("Error: You must put either lighthouse token or space-separated username and password in your Lhcfile. Don't forget to ignore it in git.")
62
- end
63
- end
64
- end
65
-
66
- class Parser
67
- class << self
68
- include Hirb::Helpers
69
-
70
- def go!
71
- (help; return) if ARGV.blank?
72
-
73
- LighthouseCLI.bootstrap!
74
- @project = LighthouseCLI.project
75
- self.send(ARGV.shift.to_sym, *ARGV)
76
- end
77
-
78
- def add(title, tags = [])
79
- new_ticket(title, tags)
80
- puts "Ticket added."
81
- end
82
-
83
- def list(which = "next")
84
- list = case which
85
- when 'next'
86
- tickets("responsible:me milestone:#{next_milestone.title} state:open sort:priority")
87
- end
88
-
89
- display_tickets list
90
- end
91
-
92
- def resolve(id)
93
- t = ticket(id)
94
- t.state = 'resolved'
95
- t.save
96
- puts "Resolved: \"#{t.title}\""
97
- end
98
-
99
- def open(id)
100
- t = ticket(id)
101
- t.state = 'new'
102
- t.save
103
- puts "Opened: \"#{t.title}\""
104
- end
105
-
106
- def show(id)
107
- ticket = ticket(id)
108
- puts " Ticket ##{id} (#{ticket.state})"
109
- puts " "+ticket.title
110
- puts " "+ticket.body unless ticket.body.blank?
111
- puts " "+ticket.tags.join(', ') unless ticket.tags.blank?
112
- end
113
-
114
- def help
115
- puts <<-TEXT
116
- Available commands:
117
- help
118
- Show this text.
119
-
120
- list
121
- List all assigned tickets from upcoming milestone.
122
-
123
- show 50
124
- Show details for ticket with given id.
125
-
126
- add "Ticket name" "tag1 tag2"
127
- Add ticket for yourself into current milestone with (optional) tags and without any body.
128
-
129
- resolve 50
130
- Mark ticket 50 resolved.
131
-
132
- open 50
133
- Mark ticket 50 new.
134
- TEXT
135
- end
136
-
137
- private
138
- def new_ticket(title, tags)
139
- ticket = Lighthouse::Ticket.new(:project_id => @project.id)
140
- ticket.title = title
141
- ticket.tags = tags.split
142
- ticket.save
143
- end
144
-
145
- def ticket(id)
146
- Lighthouse::Ticket.find(id, q)
147
- end
148
-
149
- def tickets(str = '')
150
- query = q(str)
151
- Lighthouse::Ticket.find(:all, query)
152
- end
153
-
154
- def q(str = '')
155
- {:params => {:q => str, :project_id => @project.id}}
156
- end
157
-
158
- def next_milestone
159
- @next_milestone ||= @project.milestones.find_all{|m| m.due_on > Time.now}.min{|a,b| a.due_on <=> b.due_on}
160
- end
161
-
162
- def display_tickets(tickets)
163
- puts AutoTable.render tickets, :fields => [:number, :title], :max_width => width
164
- end
165
-
166
- def width
167
- `stty size`.split.map { |x| x.to_i }.reverse.second
168
- end
169
- end
170
- end
171
32
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lighthouse_cli}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Maxim Chernyak"]
12
- s.date = %q{2009-09-01}
12
+ s.date = %q{2009-09-02}
13
13
  s.default_executable = %q{lh}
14
14
  s.description = %q{A quick command line interface to lighthouse. The goal is to reduce overhead of tracking tickets inline with normal workflow. The effect is achieved by setting conventions.}
15
15
  s.email = %q{max@bitsonnet.com}
@@ -29,6 +29,16 @@ Gem::Specification.new do |s|
29
29
  "VERSION",
30
30
  "bin/lh",
31
31
  "lib/lighthouse_cli.rb",
32
+ "lib/lighthouse_cli/authenticator.rb",
33
+ "lib/lighthouse_cli/authenticator.rb",
34
+ "lib/lighthouse_cli/commands.rb",
35
+ "lib/lighthouse_cli/commands.rb",
36
+ "lib/lighthouse_cli/config.rb",
37
+ "lib/lighthouse_cli/config.rb",
38
+ "lib/lighthouse_cli/helpers.rb",
39
+ "lib/lighthouse_cli/helpers.rb",
40
+ "lib/lighthouse_cli/parser.rb",
41
+ "lib/lighthouse_cli/parser.rb",
32
42
  "lighthouse_cli.gemspec",
33
43
  "test/lighthouse_cli_test.rb",
34
44
  "test/test_helper.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxim-lighthouse_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Chernyak
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-01 00:00:00 -07:00
12
+ date: 2009-09-02 00:00:00 -07:00
13
13
  default_executable: lh
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,11 @@ files:
51
51
  - VERSION
52
52
  - bin/lh
53
53
  - lib/lighthouse_cli.rb
54
+ - lib/lighthouse_cli/authenticator.rb
55
+ - lib/lighthouse_cli/commands.rb
56
+ - lib/lighthouse_cli/config.rb
57
+ - lib/lighthouse_cli/helpers.rb
58
+ - lib/lighthouse_cli/parser.rb
54
59
  - lighthouse_cli.gemspec
55
60
  - test/lighthouse_cli_test.rb
56
61
  - test/test_helper.rb