gil 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/Rakefile +39 -0
- data/bin/gil +20 -0
- data/lib/gil.rb +72 -0
- data/lib/lighthouse.rb +233 -0
- metadata +83 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2004-2008 David Heinemeier Hansson
|
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.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/clean"
|
3
|
+
require "rake/gempackagetask"
|
4
|
+
|
5
|
+
include FileUtils
|
6
|
+
|
7
|
+
NAME = "gil"
|
8
|
+
GILVERSION = "0.1"
|
9
|
+
|
10
|
+
CLEAN.include "pkg"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = NAME
|
14
|
+
s.version = GILVERSION
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.author = "Simon Jefford"
|
17
|
+
s.email = "simon.jefford@gmail.com"
|
18
|
+
s.homepage = "http://sjjdev.com"
|
19
|
+
s.summary = "Gil. What have you resolved today?"
|
20
|
+
s.bindir = "bin"
|
21
|
+
s.description = s.summary
|
22
|
+
s.executables = %w( gil )
|
23
|
+
s.require_path = "lib"
|
24
|
+
s.files = %w( LICENSE Rakefile ) + Dir["{bin,lib}/**/*"]
|
25
|
+
|
26
|
+
# Dependencies
|
27
|
+
s.add_dependency "activeresource"
|
28
|
+
s.add_dependency "rake"
|
29
|
+
s.add_dependency "rspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |package|
|
33
|
+
package.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run :package and install the resulting .gem"
|
37
|
+
task :install => :package do
|
38
|
+
sh %{sudo gem install --local pkg/#{NAME}-#{GILVERSION}.gem --no-rdoc --no-ri}
|
39
|
+
end
|
data/bin/gil
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "../lib"))
|
3
|
+
require 'gil'
|
4
|
+
require 'lighthouse'
|
5
|
+
include Lighthouse
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: gil revision [options]\n"
|
12
|
+
end.parse!
|
13
|
+
|
14
|
+
rev = ARGV[0]
|
15
|
+
|
16
|
+
gil = Gil.new(options)
|
17
|
+
tickets = gil.summarise_commits(rev)
|
18
|
+
tickets.each do |t|
|
19
|
+
puts "##{t.number} - #{t.title}"
|
20
|
+
end
|
data/lib/gil.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
class Git
|
2
|
+
class << self
|
3
|
+
def get_config_value(value_name)
|
4
|
+
`git config #{value_name}`.chomp
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_log_entries(rev)
|
8
|
+
`git log #{rev} --pretty=oneline --no-color`.split("\n")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class LighthouseProject
|
14
|
+
def initialize(options)
|
15
|
+
@options = options
|
16
|
+
validate_state
|
17
|
+
Lighthouse.account = account
|
18
|
+
Lighthouse.token = token
|
19
|
+
end
|
20
|
+
|
21
|
+
def project
|
22
|
+
Git.get_config_value('gil.project')
|
23
|
+
end
|
24
|
+
|
25
|
+
def token
|
26
|
+
Git.get_config_value('gil.token')
|
27
|
+
end
|
28
|
+
|
29
|
+
def account
|
30
|
+
Git.get_config_value('gil.account')
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_tickets(ticketnumbers)
|
34
|
+
ticketnumbers.map do |ticket_num|
|
35
|
+
ticket = Ticket.find(ticket_num, :params => {:project_id => project})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def validate_state
|
41
|
+
if project == ''
|
42
|
+
raise "No project was found in .git config."
|
43
|
+
end
|
44
|
+
|
45
|
+
if token == ''
|
46
|
+
raise "No token was found in .git config."
|
47
|
+
end
|
48
|
+
|
49
|
+
if account == ''
|
50
|
+
raise "No account was found in .git config."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Gil
|
56
|
+
def initialize(options)
|
57
|
+
@lighthouse = LighthouseProject.new(options)
|
58
|
+
end
|
59
|
+
|
60
|
+
def summarise_commits(rev)
|
61
|
+
logentries = Git.get_log_entries(rev)
|
62
|
+
ticketnumbers = logentries.map { |entry| find_ticket_number(entry) }.compact.uniq
|
63
|
+
@lighthouse.get_tickets(ticketnumbers)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def find_ticket_number(logentry)
|
68
|
+
re = /\[\#(\d+).*state:resolved.*\]/
|
69
|
+
match = re.match(logentry)
|
70
|
+
match[1] if match
|
71
|
+
end
|
72
|
+
end
|
data/lib/lighthouse.rb
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activesupport'
|
3
|
+
require 'activeresource'
|
4
|
+
|
5
|
+
# Ruby lib for working with the Lighthouse API's XML interface.
|
6
|
+
# The first thing you need to set is the account name. This is the same
|
7
|
+
# as the web address for your account.
|
8
|
+
#
|
9
|
+
# Lighthouse.account = 'activereload'
|
10
|
+
#
|
11
|
+
# Then, you should set the authentication. You can either use your login
|
12
|
+
# credentials with HTTP Basic Authentication or with an API Tokens. You can
|
13
|
+
# find more info on tokens at http://lighthouseapp.com/help/using-beacons.
|
14
|
+
#
|
15
|
+
# # with basic authentication
|
16
|
+
# Lighthouse.authenticate('rick@techno-weenie.net', 'spacemonkey')
|
17
|
+
#
|
18
|
+
# # or, use a token
|
19
|
+
# Lighthouse.token = 'abcdefg'
|
20
|
+
#
|
21
|
+
# If no token or authentication info is given, you'll only be granted public access.
|
22
|
+
#
|
23
|
+
# This library is a small wrapper around the REST interface. You should read the docs at
|
24
|
+
# http://lighthouseapp.com/api.
|
25
|
+
#
|
26
|
+
module Lighthouse
|
27
|
+
class Error < StandardError; end
|
28
|
+
class << self
|
29
|
+
attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port
|
30
|
+
attr_reader :account, :token
|
31
|
+
|
32
|
+
# Sets the account name, and updates all the resources with the new domain.
|
33
|
+
def account=(name)
|
34
|
+
resources.each do |klass|
|
35
|
+
klass.site = klass.site_format % (host_format % [protocol, domain_format % name, port])
|
36
|
+
end
|
37
|
+
@account = name
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets up basic authentication credentials for all the resources.
|
41
|
+
def authenticate(email, password)
|
42
|
+
@email = email
|
43
|
+
@password = password
|
44
|
+
end
|
45
|
+
|
46
|
+
# Sets the API token for all the resources.
|
47
|
+
def token=(value)
|
48
|
+
resources.each do |klass|
|
49
|
+
klass.headers['X-LighthouseToken'] = value
|
50
|
+
end
|
51
|
+
@token = value
|
52
|
+
end
|
53
|
+
|
54
|
+
def resources
|
55
|
+
@resources ||= []
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
self.host_format = '%s://%s%s'
|
60
|
+
self.domain_format = '%s.lighthouseapp.com'
|
61
|
+
self.protocol = 'http'
|
62
|
+
self.port = ''
|
63
|
+
|
64
|
+
class Base < ActiveResource::Base
|
65
|
+
def self.inherited(base)
|
66
|
+
Lighthouse.resources << base
|
67
|
+
class << base
|
68
|
+
attr_accessor :site_format
|
69
|
+
end
|
70
|
+
base.site_format = '%s'
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Find projects
|
76
|
+
#
|
77
|
+
# Project.find(:all) # find all projects for the current account.
|
78
|
+
# Project.find(44) # find individual project by ID
|
79
|
+
#
|
80
|
+
# Creating a Project
|
81
|
+
#
|
82
|
+
# project = Project.new(:name => 'Ninja Whammy Jammy')
|
83
|
+
# project.save
|
84
|
+
# # => true
|
85
|
+
#
|
86
|
+
# Updating a Project
|
87
|
+
#
|
88
|
+
# project = Project.find(44)
|
89
|
+
# project.name = "Lighthouse Issues"
|
90
|
+
# project.public = false
|
91
|
+
# project.save
|
92
|
+
#
|
93
|
+
# Finding tickets
|
94
|
+
#
|
95
|
+
# project = Project.find(44)
|
96
|
+
# project.tickets
|
97
|
+
#
|
98
|
+
class Project < Base
|
99
|
+
def tickets(options = {})
|
100
|
+
Ticket.find(:all, :params => options.update(:project_id => id))
|
101
|
+
end
|
102
|
+
|
103
|
+
def messages(options = {})
|
104
|
+
Message.find(:all, :params => options.update(:project_id => id))
|
105
|
+
end
|
106
|
+
|
107
|
+
def milestones(options = {})
|
108
|
+
Milestone.find(:all, :params => options.update(:project_id => id))
|
109
|
+
end
|
110
|
+
|
111
|
+
def bins(options = {})
|
112
|
+
Bin.find(:all, :params => options.update(:project_id => id))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class User < Base
|
117
|
+
def memberships
|
118
|
+
Membership.find(:all, :params => {:user_id => id})
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Membership < Base
|
123
|
+
site_format << '/users/:user_id'
|
124
|
+
def save
|
125
|
+
raise Error, "Cannot modify Memberships from the API"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Token < Base
|
130
|
+
def save
|
131
|
+
raise Error, "Cannot modify Tokens from the API"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Find tickets
|
136
|
+
#
|
137
|
+
# Ticket.find(:all, :params => { :project_id => 44 })
|
138
|
+
# Ticket.find(:all, :params => { :project_id => 44, :q => "state:closed tagged:committed" })
|
139
|
+
#
|
140
|
+
# project = Project.find(44)
|
141
|
+
# project.tickets
|
142
|
+
# project.tickets(:q => "state:closed tagged:committed")
|
143
|
+
#
|
144
|
+
# Creating a Ticket
|
145
|
+
#
|
146
|
+
# ticket = Ticket.new(:project_id => 44)
|
147
|
+
# ticket.title = 'asdf'
|
148
|
+
# ...
|
149
|
+
# ticket.tags << 'ruby' << 'rails' << '@high'
|
150
|
+
# ticket.save
|
151
|
+
#
|
152
|
+
# Updating a Ticket
|
153
|
+
#
|
154
|
+
# ticket = Ticket.find(20, :params => { :project_id => 44 })
|
155
|
+
# ticket.state = 'resolved'
|
156
|
+
# ticket.tags.delete '@high'
|
157
|
+
# ticket.save
|
158
|
+
#
|
159
|
+
class Ticket < Base
|
160
|
+
attr_writer :tags
|
161
|
+
site_format << '/projects/:project_id'
|
162
|
+
|
163
|
+
def id
|
164
|
+
attributes['number'] ||= nil
|
165
|
+
number
|
166
|
+
end
|
167
|
+
|
168
|
+
def tags
|
169
|
+
attributes['tag'] ||= nil
|
170
|
+
@tags ||= tag.blank? ? [] : parse_with_spaces(tag)
|
171
|
+
end
|
172
|
+
|
173
|
+
def save_with_tags
|
174
|
+
self.tag = @tags.collect do |tag|
|
175
|
+
tag.include?(' ') ? tag.inspect : tag
|
176
|
+
end.join(" ") if @tags.is_a?(Array)
|
177
|
+
@tags = nil ; save_without_tags
|
178
|
+
end
|
179
|
+
|
180
|
+
alias_method_chain :save, :tags
|
181
|
+
|
182
|
+
private
|
183
|
+
# taken from Lighthouse Tag code
|
184
|
+
def parse_with_spaces(list)
|
185
|
+
tags = []
|
186
|
+
|
187
|
+
# first, pull out the quoted tags
|
188
|
+
list.gsub!(/\"(.*?)\"\s*/ ) { tags << $1; "" }
|
189
|
+
|
190
|
+
# then, get whatever's left
|
191
|
+
tags.concat list.split(/\s/)
|
192
|
+
|
193
|
+
cleanup_tags(tags)
|
194
|
+
end
|
195
|
+
|
196
|
+
def cleanup_tags(tags)
|
197
|
+
returning tags do |tag|
|
198
|
+
tag.collect! do |t|
|
199
|
+
unless tag.blank?
|
200
|
+
t.downcase!
|
201
|
+
t.gsub! /(^')|('$)/, ''
|
202
|
+
t.gsub! /[^a-z0-9 \-_@\!']/, ''
|
203
|
+
t.strip!
|
204
|
+
t
|
205
|
+
end
|
206
|
+
end
|
207
|
+
tag.compact!
|
208
|
+
tag.uniq!
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class Message < Base
|
214
|
+
site_format << '/projects/:project_id'
|
215
|
+
end
|
216
|
+
|
217
|
+
class Milestone < Base
|
218
|
+
site_format << '/projects/:project_id'
|
219
|
+
end
|
220
|
+
|
221
|
+
class Bin < Base
|
222
|
+
site_format << '/projects/:project_id'
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
module ActiveResource
|
227
|
+
class Connection
|
228
|
+
private
|
229
|
+
def authorization_header
|
230
|
+
(Lighthouse.email || Lighthouse.password ? { 'Authorization' => 'Basic ' + ["#{Lighthouse.email}:#{Lighthouse.password}"].pack('m').delete("\r\n") } : {})
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Jefford
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-18 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activeresource
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rake
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
description: Gil. What have you resolved today?
|
43
|
+
email: simon.jefford@gmail.com
|
44
|
+
executables:
|
45
|
+
- gil
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- LICENSE
|
52
|
+
- Rakefile
|
53
|
+
- bin/gil
|
54
|
+
- lib/gil.rb
|
55
|
+
- lib/lighthouse.rb
|
56
|
+
has_rdoc: false
|
57
|
+
homepage: http://sjjdev.com
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.1.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: Gil. What have you resolved today?
|
82
|
+
test_files: []
|
83
|
+
|