djanowski-helm 0.0.2 → 0.0.3

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/bin/helm CHANGED
@@ -6,6 +6,16 @@ require File.dirname(__FILE__) + '/../lib/helm'
6
6
 
7
7
  require 'yaml'
8
8
 
9
+ def argv(key)
10
+ start = "--#{key}="
11
+
12
+ value = ARGV.detect do |v|
13
+ v =~ /^#{Regexp.escape(start)}/
14
+ end
15
+
16
+ value[start.size..-1] if value
17
+ end
18
+
9
19
  def load_config(file)
10
20
  file = File.expand_path(file)
11
21
 
@@ -16,22 +26,12 @@ def load_config(file)
16
26
  yaml = yield(yaml) if block_given?
17
27
 
18
28
  yaml.each do |k,v|
19
- ARGV << "--#{k}=#{v}"
29
+ ARGV << "--#{k}=#{v}" unless argv(k)
20
30
  end if yaml
21
31
 
22
32
  yaml
23
33
  end
24
34
 
25
- def argv(key)
26
- start = "--#{key}="
27
-
28
- value = ARGV.detect do |v|
29
- v =~ /^#{Regexp.escape(start)}/
30
- end
31
-
32
- value[start.size..-1] if value
33
- end
34
-
35
35
  local_config = load_config('.helm_config')
36
36
 
37
37
  load_config('~/.helm_config') do |opts|
@@ -2,6 +2,8 @@ module Helm
2
2
  module Commands
3
3
  class Assign < Command
4
4
  def run
5
+ parameters :ticket, :milestone
6
+
5
7
  ticket = session.ticket
6
8
 
7
9
  if session.milestone
@@ -3,6 +3,10 @@ module Helm
3
3
  class Command
4
4
  attr_reader :session
5
5
 
6
+ def parameters(*names)
7
+ session.configure_params(*names)
8
+ end
9
+
6
10
  def initialize(session)
7
11
  @session = session
8
12
  end
@@ -48,11 +48,7 @@ module Helm
48
48
  ticket.body = ticket.body.strip
49
49
  ticket.save
50
50
  puts "##{ticket.id} Created"
51
- # puts "Title: #{ticket.title}"
52
- # puts "Description: #{ticket.body}"
53
- # puts "URL: http://citrusbyte.lighthouseapp.com/projects/18337/tickets/#{ticket.id}"
54
51
  end
55
-
56
52
  end
57
53
  end
58
54
  end
@@ -2,6 +2,8 @@ module Helm
2
2
  module Commands
3
3
  class Info < Command
4
4
  def run
5
+ parameters :ticket
6
+
5
7
  ticket = session.ticket
6
8
 
7
9
  puts "##{ticket.id} #{ticket.title}"
@@ -0,0 +1,16 @@
1
+ module Helm
2
+ module Commands
3
+ class List < Command
4
+ def run
5
+ parameters :filter
6
+
7
+ filter = session[:filter] || "responsible:me state:open milestone:next"
8
+
9
+ puts "Tickets with filter \"#{filter}\""
10
+ session.tickets(filter).each do |ticket|
11
+ puts " ##{ticket.id} #{ticket.title}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,6 +2,8 @@ module Helm
2
2
  module Commands
3
3
  class Resolve < Command
4
4
  def run
5
+ parameters :ticket
6
+
5
7
  ticket = session.ticket
6
8
 
7
9
  ticket.state = 'resolved'
@@ -0,0 +1,25 @@
1
+ module Helm
2
+ module Commands
3
+ class Show < Command
4
+ def run
5
+ parameters :milestone, :filter
6
+
7
+ unless milestone = session.milestone
8
+ return puts("The milestone \"#{session[:milestone]}\" couldn't be found")
9
+ end
10
+
11
+ filter = session[:filter] || "state:open milestone:\"#{milestone.title}\""
12
+
13
+ puts "Details about #{milestone.title}"
14
+ puts " Goals: #{milestone.goals}"
15
+ puts " Due on: #{milestone.due_on}"
16
+ puts ""
17
+ puts " Tickets (#{milestone.open_tickets_count} open out of #{milestone.tickets_count})"
18
+
19
+ session.tickets(filter).each do |ticket|
20
+ puts " ##{ticket.id} #{ticket.title}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,57 @@
1
+ module Helm
2
+ module Commands
3
+ class Upload < Command
4
+ def run
5
+ parameters :ticket, :filename
6
+
7
+ ensure_filename!
8
+
9
+ login!
10
+
11
+ agent.get url(session.ticket_path(ticket)) do |page|
12
+ form = page.form_with(:enctype => 'multipart/form-data')
13
+
14
+ form.file_uploads.first.file_name = filename
15
+
16
+ agent.submit(form)
17
+ end if false
18
+
19
+ puts "EMBED" if argv('--embed')
20
+ end
21
+
22
+ protected
23
+
24
+ def filename
25
+ session[:filename]
26
+ end
27
+
28
+ def ticket
29
+ session[:ticket]
30
+ end
31
+
32
+ def url(path)
33
+ "#{session.url}#{path}"
34
+ end
35
+
36
+ def login!
37
+ agent.get url('/login') do |page|
38
+ page.forms.first['email'] = session.username
39
+ page.forms.first['password'] = session.password
40
+
41
+ agent.submit(page.forms.first)
42
+ end
43
+ end
44
+
45
+ def agent
46
+ @agent ||= begin
47
+ require 'mechanize'
48
+ WWW::Mechanize.new # { |a| require 'logger'; a.log = Logger.new($stdout) }
49
+ end
50
+ end
51
+
52
+ def ensure_filename!
53
+ raise "File not found - #{filename}" unless File.exist?(filename)
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/helm/session.rb CHANGED
@@ -17,6 +17,16 @@ module Helm
17
17
  desc 'The token to authenticate against the server'
18
18
  end
19
19
 
20
+ option :username do
21
+ long '--username'
22
+ desc 'The username to authenticate against the server'
23
+ end
24
+
25
+ option :password do
26
+ long '--password'
27
+ desc 'The username to authenticate against the server'
28
+ end
29
+
20
30
  option :project do
21
31
  long '--project'
22
32
  short '-p'
@@ -29,6 +39,20 @@ module Helm
29
39
  configure
30
40
  end
31
41
 
42
+ # Configure the set of params to be used by the active command.
43
+ def configure_params(*names)
44
+ @params = {}
45
+ names.each_with_index do |name, index|
46
+ @params[name] = index
47
+ end
48
+ end
49
+
50
+ # Access positional parameters sent to the active command
51
+ # based on the order specified in configure_params.
52
+ def [](name)
53
+ arguments[@params[name].succ]
54
+ end
55
+
32
56
  def project
33
57
  @project ||= Lighthouse::Project.find(:all).detect {|p| p.name == options.project }
34
58
  end
@@ -38,21 +62,21 @@ module Helm
38
62
  end
39
63
 
40
64
  def ticket(id = nil)
41
- Lighthouse::Ticket.find(id || ticket_id, :params => {:project_id => project.id})
65
+ Lighthouse::Ticket.find(id || self[:ticket], :params => {:project_id => project.id})
66
+ end
67
+
68
+ def tickets(filter = nil)
69
+ project.tickets(:q => filter)
42
70
  end
43
71
 
44
72
  def milestone(id = nil)
45
73
  if id
46
74
  Lighthouse::Milestone.find(id)
47
75
  else
48
- @milestone ||= Lighthouse::Milestone.find(:all, :params => {:project_id => project.id}).detect {|m| m.title == ARGV[2] }
76
+ @milestone ||= Lighthouse::Milestone.find(:all, :params => {:project_id => project.id}).detect {|m| m.title == self[:milestone] }
49
77
  end
50
78
  end
51
79
 
52
- def ticket_id
53
- ARGV[1].to_i
54
- end
55
-
56
80
  def user(id = nil)
57
81
  if id
58
82
  Lighthouse::User.find(id)
@@ -61,20 +85,32 @@ module Helm
61
85
  end
62
86
  end
63
87
 
88
+ def uri
89
+ @uri ||= URI.parse(url)
90
+ end
91
+
92
+ def url
93
+ options.url
94
+ end
95
+
96
+ def username
97
+ options.username
98
+ end
99
+
100
+ def password
101
+ options.password
102
+ end
103
+
104
+ def ticket_path(id = nil)
105
+ Lighthouse::Ticket.element_path(id || self[:ticket], {:project_id => project.id}).sub(/\.xml$/, '')
106
+ end
107
+
64
108
  protected
65
109
 
66
110
  def account
67
111
  @account ||= uri.host.split('.').first
68
112
  end
69
113
 
70
- def uri
71
- @uri ||= URI.parse(url)
72
- end
73
-
74
- def url
75
- options.url
76
- end
77
-
78
114
  def token
79
115
  options.token
80
116
  end
@@ -84,5 +120,10 @@ module Helm
84
120
  Lighthouse.token = token
85
121
  end
86
122
 
123
+ def arguments
124
+ @arguments ||= ARGV.select do |argv|
125
+ argv !~ /^--/
126
+ end
127
+ end
87
128
  end
88
129
  end
data/lib/helm.rb CHANGED
@@ -6,3 +6,6 @@ require File.dirname(__FILE__) + '/helm/commands/info'
6
6
  require File.dirname(__FILE__) + '/helm/commands/assign'
7
7
  require File.dirname(__FILE__) + '/helm/commands/create'
8
8
  require File.dirname(__FILE__) + '/helm/commands/resolve'
9
+ require File.dirname(__FILE__) + '/helm/commands/show'
10
+ require File.dirname(__FILE__) + '/helm/commands/list'
11
+ require File.dirname(__FILE__) + '/helm/commands/upload'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-helm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski
@@ -34,7 +34,10 @@ files:
34
34
  - lib/helm/commands/command.rb
35
35
  - lib/helm/commands/create.rb
36
36
  - lib/helm/commands/info.rb
37
+ - lib/helm/commands/list.rb
37
38
  - lib/helm/commands/resolve.rb
39
+ - lib/helm/commands/show.rb
40
+ - lib/helm/commands/upload.rb
38
41
  - lib/helm/lighthouse.rb
39
42
  - lib/helm/project.rb
40
43
  - lib/helm/session.rb