lighthouse_cli 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ .rake_tasks~
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Maxim Chernyak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Lhcfile ADDED
@@ -0,0 +1,10 @@
1
+ account:
2
+ example_account
3
+ project:
4
+ example_project
5
+ # username:
6
+ # foo
7
+ # password:
8
+ # bar
9
+ # token:
10
+ # baz
@@ -0,0 +1,44 @@
1
+ lighthouse_cli
2
+ ===============
3
+
4
+ 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.
5
+
6
+ Install
7
+ --------
8
+
9
+ Add github to gem sources unless you've done that before
10
+
11
+ sudo gem sources -a http://gems.github.com
12
+ sudo gem install maxim-lighthouse_cli
13
+
14
+
15
+ Usage
16
+ ------
17
+
18
+ 1. Create Lhcfile in your project with the following yaml content (either user/pass or token, no need for both):
19
+
20
+ account:
21
+ example_account
22
+ project:
23
+ example_project
24
+ # username:
25
+ # foo
26
+ # password:
27
+ # bar
28
+ # token:
29
+ # baz
30
+
31
+ 2. Add Lhcfile to .gitignore (avoid committing your token/password).
32
+ 3. Run lh help to get started.
33
+
34
+ Contact/Contribute
35
+ -------------------
36
+
37
+ If you'd like to comment on something -- I'm [@hakunin](http://twitter.com/hakunin) on twitter.
38
+ My [blog](http://mediumexposure.com) has more ways to reach me.
39
+ For contributions simply fork, change, commit, send me pull requests.
40
+
41
+ Copyright
42
+ ----------
43
+
44
+ Copyright (c) 2009 Maxim Chernyak. See LICENSE for details.
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lighthouse_cli"
8
+ gem.summary = %Q{A quick command line interface to lighthouse.}
9
+ gem.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.}
10
+ gem.email = "max@bitsonnet.com"
11
+ gem.homepage = "http://github.com/maxim/lighthouse_cli"
12
+ gem.authors = ["Maxim Chernyak"]
13
+ gem.add_dependency "cldwalker-hirb"
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ gem.files.include %w(Lhcfile lib/lighthouse_cli/* vendor/* vendor/lighthouse-api/* vendor/lighthouse-api/lib/* vendor/lighthouse-api/lib/lighthouse/*)
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION')
49
+ version = File.read('VERSION')
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "lighthouse_cli #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.1
data/bin/lh ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'lighthouse_cli'
4
+ LighthouseCLI::Parser.parse_argv!
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'lighthouse-api', 'lib', 'lighthouse-api'))
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
+
11
+ module LighthouseCLI
12
+ DEFAULT_CONFIG_PATH = "Lhcfile"
13
+
14
+ def bootstrap!
15
+ Authenticator.authenticate!
16
+ ::Lighthouse.account = Config.account
17
+ end
18
+
19
+ def project
20
+ project_name = Config.project
21
+
22
+ @project ||= if project_name
23
+ ::Lighthouse::Project.find(:all).find{|p| p.name == Config.project}
24
+ else
25
+ nil
26
+ end
27
+
28
+ @project || (raise RuntimeError.new("Project not found or wasn't configured."))
29
+ end
30
+
31
+ module_function :bootstrap!, :project
32
+ end
@@ -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,91 @@
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
+ case which
10
+ when 'next'
11
+ puts "Milestone: #{fetch_next_milestone.title}"
12
+ tickets = fetch_tickets("responsible:me milestone:#{fetch_next_milestone.title} state:open sort:priority")
13
+ display_tickets tickets
14
+ else
15
+ milestones = fetch_milestones_by_title(which)
16
+ milestones.each do |ms|
17
+ puts "Milestone: #{ms.title}"
18
+ tickets = fetch_tickets("responsible:me milestone:#{ms.title} state:open sort:priority")
19
+ display_tickets tickets
20
+ puts "\n"
21
+ sleep 1
22
+ end
23
+ end
24
+ end
25
+
26
+ def resolve(id)
27
+ t = fetch_ticket(id)
28
+ t.state = 'resolved'
29
+ if t.save
30
+ puts "Resolved: \"#{t.title}\""
31
+ else
32
+ puts "Failed trying to resolve ticket."
33
+ end
34
+ end
35
+
36
+ def open(id)
37
+ t = fetch_ticket(id)
38
+ t.state = 'new'
39
+ if t.save
40
+ puts "Opened: \"#{t.title}\""
41
+ else
42
+ puts "Failed trying to open ticket."
43
+ end
44
+ end
45
+
46
+ def show(id)
47
+ ticket = fetch_ticket(id)
48
+ puts " Ticket ##{id} (#{ticket.state})"
49
+ puts " #{ticket.title}"
50
+ puts " #{ticket.body}" unless ticket.body.blank?
51
+ puts " #{ticket.tags.join(', ')}" unless ticket.tags.blank?
52
+ end
53
+
54
+ def ms(which = "future")
55
+ milestones = case which
56
+ when 'all'
57
+ fetch_all_milestones
58
+ when 'future'
59
+ fetch_future_milestones
60
+ end
61
+
62
+ display_milestones milestones
63
+ end
64
+
65
+ def help
66
+ puts <<-TEXT
67
+ Available commands:
68
+ help
69
+ Show this text.
70
+
71
+ list [milestone_name]
72
+ List all assigned tickets from next upcoming milestone (by default). Otherwise, list all tickets in all milestones matching milestone name.
73
+
74
+ ms [all]
75
+ List future milestones (by default). List all milestones when option "all" provided.
76
+
77
+ show 50
78
+ Show details for ticket with given id.
79
+
80
+ add "Ticket name" "tag1 tag2"
81
+ Add ticket for yourself into current milestone with (optional) tags and without any body.
82
+
83
+ resolve 50
84
+ Mark ticket 50 resolved.
85
+
86
+ open 50
87
+ Mark ticket 50 new.
88
+ TEXT
89
+ end
90
+ end
91
+ 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,64 @@
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 fetch_next_milestone
27
+ @next_milestone ||= fetch_future_milestones.min{|a,b| a.due_on <=> b.due_on}
28
+ end
29
+
30
+ def fetch_future_milestones
31
+ @future_milestones ||= fetch_all_milestones.find_all{|m| m.due_on > Time.now}
32
+ end
33
+
34
+ def fetch_all_milestones
35
+ @all_milestones ||= @project.milestones.sort{|a,b| b.due_on <=> a.due_on}
36
+ end
37
+
38
+ def fetch_milestones_by_title(title)
39
+ fetch_all_milestones.select{|m| m.title =~ /#{title}/i}
40
+ end
41
+
42
+ def display_tickets(tickets)
43
+ puts AutoTable.render tickets, :fields => [:number, :title], :max_width => width
44
+ end
45
+
46
+ def display_milestones(milestones)
47
+ puts AutoTable.render milestones, :fields => [:title, :tickets_count, :open_tickets_count, :due_on],
48
+ :headers => { :due_on => "due",
49
+ :title => "title",
50
+ :tickets_count => "tickets",
51
+ :open_tickets_count => "open"},
52
+ :filters => {
53
+ :due_on => [:strftime, "%m/%d/%Y"]
54
+ },
55
+ :max_width => width
56
+ end
57
+
58
+ def width
59
+ `stty size`.split.map { |x| x.to_i }.reverse.second
60
+ rescue
61
+ 30
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
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
+ rescue ActiveResource::TimeoutError, ActiveResource::ServerError
19
+ puts "There seems to be a problem with lighthouse server. Try again in a few."
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,81 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lighthouse_cli}
8
+ s.version = "1.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Maxim Chernyak"]
12
+ s.date = %q{2009-09-02}
13
+ s.default_executable = %q{lh}
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
+ s.email = %q{max@bitsonnet.com}
16
+ s.executables = ["lh"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "Lhcfile",
26
+ "Lhcfile",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/lh",
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",
42
+ "lighthouse_cli.gemspec",
43
+ "test/lighthouse_cli_test.rb",
44
+ "test/test_helper.rb",
45
+ "vendor/lighthouse-api/LICENSE",
46
+ "vendor/lighthouse-api/LICENSE",
47
+ "vendor/lighthouse-api/README.markdown",
48
+ "vendor/lighthouse-api/README.markdown",
49
+ "vendor/lighthouse-api/lib/lighthouse-api.rb",
50
+ "vendor/lighthouse-api/lib/lighthouse-api.rb",
51
+ "vendor/lighthouse-api/lib/lighthouse.rb",
52
+ "vendor/lighthouse-api/lib/lighthouse.rb",
53
+ "vendor/lighthouse-api/lib/lighthouse/console.rb",
54
+ "vendor/lighthouse-api/lib/lighthouse/console.rb"
55
+ ]
56
+ s.homepage = %q{http://github.com/maxim/lighthouse_cli}
57
+ s.rdoc_options = ["--charset=UTF-8"]
58
+ s.require_paths = ["lib"]
59
+ s.rubygems_version = %q{1.3.5}
60
+ s.summary = %q{A quick command line interface to lighthouse.}
61
+ s.test_files = [
62
+ "test/lighthouse_cli_test.rb",
63
+ "test/test_helper.rb"
64
+ ]
65
+
66
+ if s.respond_to? :specification_version then
67
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
68
+ s.specification_version = 3
69
+
70
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
71
+ s.add_runtime_dependency(%q<cldwalker-hirb>, [">= 0"])
72
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
73
+ else
74
+ s.add_dependency(%q<cldwalker-hirb>, [">= 0"])
75
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
76
+ end
77
+ else
78
+ s.add_dependency(%q<cldwalker-hirb>, [">= 0"])
79
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class LighthouseCliTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'lighthouse_cli'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Active Reload, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ Lighthouse API
2
+ --------------
3
+
4
+ The official Ruby library for interacting with the [Lighthouse REST API](http://lighthouseapp.com/api).
5
+
6
+ ### Documentation & Requirements
7
+ * ActiveResource
8
+ * ActiveSupport
9
+
10
+ Check out lib/lighthouse.rb for examples and documentation.
11
+
12
+
13
+ ### Using The Lighthouse Console
14
+
15
+ The Lighthouse library comes with a convenient console for testing and quick commands
16
+ (or whatever else you want to use it for).
17
+
18
+ From /lib:
19
+
20
+ irb -r lighthouse/console
21
+ Lighthouse.account = "activereload"
22
+
23
+ #### You can use `authenticate` OR `token`
24
+ Lighthouse.authenticate('username', 'password')
25
+ #Lighthouse.token = 'YOUR_TOKEN'
26
+
27
+ Project.find(:all)
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/lighthouse"
@@ -0,0 +1,366 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'uri'
5
+ require 'addressable/uri'
6
+
7
+ module URI
8
+ def decode(*args)
9
+ Addressable::URI.decode(*args)
10
+ end
11
+
12
+ def escape(*args)
13
+ Addressable::URI.escape(*args)
14
+ end
15
+
16
+ def parse(*args)
17
+ Addressable::URI.parse(*args)
18
+ end
19
+ end
20
+ rescue LoadError => e
21
+ puts "Install the Addressable gem (with dependencies) to support accounts with subdomains."
22
+ puts "# sudo gem install addressable --development"
23
+ puts e.message
24
+ end
25
+
26
+ require 'activesupport'
27
+ require 'activeresource'
28
+
29
+ # Ruby lib for working with the Lighthouse API's XML interface.
30
+ # The first thing you need to set is the account name. This is the same
31
+ # as the web address for your account.
32
+ #
33
+ # Lighthouse.account = 'activereload'
34
+ #
35
+ # Then, you should set the authentication. You can either use your login
36
+ # credentials with HTTP Basic Authentication or with an API Tokens. You can
37
+ # find more info on tokens at http://lighthouseapp.com/help/using-beacons.
38
+ #
39
+ # # with basic authentication
40
+ # Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
41
+ #
42
+ # # or, use a token
43
+ # Lighthouse.token = 'abcdefg'
44
+ #
45
+ # If no token or authentication info is given, you'll only be granted public access.
46
+ #
47
+ # This library is a small wrapper around the REST interface. You should read the docs at
48
+ # http://lighthouseapp.com/api.
49
+ #
50
+ module Lighthouse
51
+ class Error < StandardError; end
52
+ class << self
53
+ attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
54
+ attr_reader :account, :token
55
+
56
+ # Sets the account name, and updates all the resources with the new domain.
57
+ def account=(name)
58
+ resources.each do |klass|
59
+ klass.site = klass.site_format % (host_format % [protocol, domain_format % name, ":#{port}"])
60
+ end
61
+ @account = name
62
+ end
63
+
64
+ # Sets up basic authentication credentials for all the resources.
65
+ def authenticate(email, password)
66
+ @email = email
67
+ @password = password
68
+ end
69
+
70
+ # Sets the API token for all the resources.
71
+ def token=(value)
72
+ resources.each do |klass|
73
+ klass.headers['X-LighthouseToken'] = value
74
+ end
75
+ @token = value
76
+ end
77
+
78
+ def resources
79
+ @resources ||= []
80
+ end
81
+ end
82
+
83
+ self.host_format = '%s://%s%s'
84
+ self.domain_format = '%s.lighthouseapp.com'
85
+ self.protocol = 'http'
86
+ self.port = ''
87
+
88
+ class Base < ActiveResource::Base
89
+ def self.inherited(base)
90
+ Lighthouse.resources << base
91
+ class << base
92
+ attr_accessor :site_format
93
+ end
94
+ base.site_format = '%s'
95
+ super
96
+ end
97
+ end
98
+
99
+ # Find projects
100
+ #
101
+ # Lighthouse::Project.find(:all) # find all projects for the current account.
102
+ # Lighthouse::Project.find(44) # find individual project by ID
103
+ #
104
+ # Creating a Project
105
+ #
106
+ # project = Lighthouse::Project.new(:name => 'Ninja Whammy Jammy')
107
+ # project.save
108
+ # # => true
109
+ #
110
+ # Creating an OSS project
111
+ #
112
+ # project = Lighthouse::Project.new(:name => 'OSS Project')
113
+ # project.access = 'oss'
114
+ # project.license = 'mit'
115
+ # project.save
116
+ #
117
+ # OSS License Mappings
118
+ #
119
+ # 'mit' => "MIT License",
120
+ # 'apache-2-0' => "Apache License 2.0",
121
+ # 'artistic-gpl-2' => "Artistic License/GPLv2",
122
+ # 'gpl-2' => "GNU General Public License v2",
123
+ # 'gpl-3' => "GNU General Public License v3",
124
+ # 'lgpl' => "GNU Lesser General Public License"
125
+ # 'mozilla-1-1' => "Mozilla Public License 1.1"
126
+ # 'new-bsd' => "New BSD License",
127
+ # 'afl-3' => "Academic Free License v. 3.0"
128
+
129
+ #
130
+ # Updating a Project
131
+ #
132
+ # project = Lighthouse::Project.find(44)
133
+ # project.name = "Lighthouse Issues"
134
+ # project.public = false
135
+ # project.save
136
+ #
137
+ # Finding tickets
138
+ #
139
+ # project = Lighthouse::Project.find(44)
140
+ # project.tickets
141
+ #
142
+ class Project < Base
143
+ def tickets(options = {})
144
+ Ticket.find(:all, :params => options.update(:project_id => id))
145
+ end
146
+
147
+ def messages(options = {})
148
+ Message.find(:all, :params => options.update(:project_id => id))
149
+ end
150
+
151
+ def milestones(options = {})
152
+ Milestone.find(:all, :params => options.update(:project_id => id))
153
+ end
154
+
155
+ def bins(options = {})
156
+ Bin.find(:all, :params => options.update(:project_id => id))
157
+ end
158
+
159
+ def changesets(options = {})
160
+ Changeset.find(:all, :params => options.update(:project_id => id))
161
+ end
162
+
163
+ def memberships(options = {})
164
+ ProjectMembership.find(:all, :params => options.update(:project_id => id))
165
+ end
166
+
167
+ def tags(options = {})
168
+ TagResource.find(:all, :params => options.update(:project_id => id))
169
+ end
170
+ end
171
+
172
+ class User < Base
173
+ def memberships(options = {})
174
+ Membership.find(:all, :params => {:user_id => id})
175
+ end
176
+ end
177
+
178
+ class Membership < Base
179
+ site_format << '/users/:user_id'
180
+ def save
181
+ raise Error, "Cannot modify memberships from the API"
182
+ end
183
+ end
184
+
185
+ class ProjectMembership < Base
186
+ self.element_name = 'membership'
187
+ site_format << '/projects/:project_id'
188
+
189
+ def url
190
+ respond_to?(:account) ? account : project
191
+ end
192
+
193
+ def save
194
+ raise Error, "Cannot modify memberships from the API"
195
+ end
196
+ end
197
+
198
+ class Token < Base
199
+ def save
200
+ raise Error, "Cannot modify Tokens from the API"
201
+ end
202
+ end
203
+
204
+ # Find tickets
205
+ #
206
+ # Lighthouse::Ticket.find(:all, :params => { :project_id => 44 })
207
+ # Lighthouse::Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
208
+ #
209
+ # project = Lighthouse::Project.find(44)
210
+ # project.tickets
211
+ # project.tickets(:q => "state:closed tagged:committed")
212
+ #
213
+ # Creating a Ticket
214
+ #
215
+ # ticket = Lighthouse::Ticket.new(:project_id => 44)
216
+ # ticket.title = 'asdf'
217
+ # ...
218
+ # ticket.tags << 'ruby' << 'rails' << '@high'
219
+ # ticket.save
220
+ #
221
+ # Updating a Ticket
222
+ #
223
+ # ticket = Lighthouse::Ticket.find(20, :params => { :project_id => 44 })
224
+ # ticket.state = 'resolved'
225
+ # ticket.tags.delete '@high'
226
+ # ticket.save
227
+ #
228
+ class Ticket < Base
229
+ attr_writer :tags
230
+ site_format << '/projects/:project_id'
231
+
232
+ def id
233
+ attributes['number'] ||= nil
234
+ number
235
+ end
236
+
237
+ def tags
238
+ attributes['tag'] ||= nil
239
+ @tags ||= tag.blank? ? [] : parse_with_spaces(tag)
240
+ end
241
+
242
+ def body
243
+ attributes['body'] ||= ''
244
+ end
245
+
246
+ def body=(value)
247
+ attributes['body'] = value
248
+ end
249
+
250
+ def body_html
251
+ attributes['body_html'] ||= ''
252
+ end
253
+
254
+ def body_html=(value)
255
+ attributes['body_html'] = value
256
+ end
257
+
258
+ def save_with_tags
259
+ self.tag = @tags.collect do |tag|
260
+ tag.include?(' ') ? tag.inspect : tag
261
+ end.join(" ") if @tags.is_a?(Array)
262
+ @tags = nil ; save_without_tags
263
+ end
264
+
265
+ alias_method_chain :save, :tags
266
+
267
+ private
268
+ # taken from Lighthouse Tag code
269
+ def parse_with_spaces(list)
270
+ tags = []
271
+
272
+ # first, pull out the quoted tags
273
+ list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
274
+
275
+ # then, get whatever's left
276
+ tags.concat list.split(/\s/)
277
+
278
+ cleanup_tags(tags)
279
+ end
280
+
281
+ def cleanup_tags(tags)
282
+ returning tags do |tag|
283
+ tag.collect! do |t|
284
+ unless tag.blank?
285
+ t = Tag.new(t,prefix_options[:project_id])
286
+ t.downcase!
287
+ t.gsub! /(^')|('$)/, ''
288
+ t.gsub! /[^a-z0-9 \-_@\!']/, ''
289
+ t.strip!
290
+ t.prefix_options = prefix_options
291
+ t
292
+ end
293
+ end
294
+ tag.compact!
295
+ tag.uniq!
296
+ end
297
+ end
298
+ end
299
+
300
+ class Message < Base
301
+ site_format << '/projects/:project_id'
302
+ end
303
+
304
+ class Milestone < Base
305
+ site_format << '/projects/:project_id'
306
+
307
+ def tickets(options = {})
308
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{milestone:"#{title}"}))
309
+ end
310
+ end
311
+
312
+ class Bin < Base
313
+ site_format << '/projects/:project_id'
314
+
315
+ def tickets(options = {})
316
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => query))
317
+ end
318
+ end
319
+
320
+ class Changeset < Base
321
+ site_format << '/projects/:project_id'
322
+ end
323
+
324
+ class Change < Array; end
325
+
326
+ class TagResource < Base
327
+ self.element_name = 'tag'
328
+ site_format << '/projects/:project_id'
329
+
330
+ def name
331
+ @name ||= Tag.new(attributes['name'], prefix_options[:project_id])
332
+ end
333
+
334
+ def tickets(options = {})
335
+ name.tickets(options)
336
+ end
337
+ end
338
+
339
+ class Tag < String
340
+ attr_writer :prefix_options
341
+ attr_accessor :project_id
342
+
343
+ def initialize(s, project_id)
344
+ @project_id = project_id
345
+ super(s)
346
+ end
347
+
348
+ def prefix_options
349
+ @prefix_options || {}
350
+ end
351
+
352
+ def tickets(options = {})
353
+ options[:project_id] ||= @project_id
354
+ Ticket.find(:all, :params => options.merge(prefix_options).update(:q => %{tagged:"#{self}"}))
355
+ end
356
+ end
357
+ end
358
+
359
+ module ActiveResource
360
+ class Connection
361
+ private
362
+ def authorization_header
363
+ (Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
364
+ end
365
+ end
366
+ end
@@ -0,0 +1,25 @@
1
+ require 'lighthouse'
2
+ puts <<-TXT
3
+ Ruby lib for working with the Lighthouse API's XML interface.
4
+ The first thing you need to set is the account name. This is the same
5
+ as the web address for your account.
6
+
7
+ Lighthouse.account = 'activereload'
8
+
9
+ Then, you should set the authentication. You can either use your login
10
+ credentials with HTTP Basic Authentication or with an API Tokens. You can
11
+ find more info on tokens at http://lighthouseapp.com/help/using-beacons.
12
+
13
+ # with basic authentication
14
+ Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
15
+
16
+ # or, use a token
17
+ Lighthouse.token = 'abcdefg'
18
+
19
+ If no token or authentication info is given, you'll only be granted public access.
20
+
21
+ This library is a small wrapper around the REST interface. You should read the docs at
22
+ http://lighthouseapp.com/api.
23
+ TXT
24
+
25
+ include Lighthouse
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lighthouse_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Chernyak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-02 00:00:00 -04:00
13
+ default_executable: lh
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cldwalker-hirb
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: 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.
36
+ email: max@bitsonnet.com
37
+ executables:
38
+ - lh
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - Lhcfile
49
+ - README.md
50
+ - Rakefile
51
+ - VERSION
52
+ - bin/lh
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
59
+ - lighthouse_cli.gemspec
60
+ - test/lighthouse_cli_test.rb
61
+ - test/test_helper.rb
62
+ - vendor/lighthouse-api/LICENSE
63
+ - vendor/lighthouse-api/README.markdown
64
+ - vendor/lighthouse-api/lib/lighthouse-api.rb
65
+ - vendor/lighthouse-api/lib/lighthouse.rb
66
+ - vendor/lighthouse-api/lib/lighthouse/console.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/maxim/lighthouse_cli
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: A quick command line interface to lighthouse.
95
+ test_files:
96
+ - test/lighthouse_cli_test.rb
97
+ - test/test_helper.rb