pendaxes 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ retried = false
5
+ begin
6
+ require 'pendaxes'
7
+ rescue LoadError
8
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
9
+ if retried
10
+ raise
11
+ else
12
+ retried = true
13
+ retry
14
+ end
15
+ end
16
+
17
+ exit Pendaxes.oneshot_run(*ARGV)
data/lib/pendaxes.rb CHANGED
@@ -6,5 +6,9 @@ module Pendaxes
6
6
  def run(*args)
7
7
  CommandLine.new(*args).run
8
8
  end
9
+
10
+ def oneshot_run(*args)
11
+ CommandLine::Oneshot.new(*args).run
12
+ end
9
13
  end
10
14
  end
@@ -4,13 +4,14 @@ require_relative "./detector"
4
4
  require_relative "./reporter"
5
5
  require_relative "./notificator"
6
6
  require 'yaml'
7
+ require 'optparse'
7
8
 
8
9
  module Pendaxes
9
10
  class CommandLine
10
11
  DEFAULT_CONFIG_FILE = ".pendaxes.yml"
11
12
 
12
13
  def initialize(*args)
13
- @args = args
14
+ @args = args.dup
14
15
  @config = nil
15
16
  end
16
17
 
@@ -187,5 +188,77 @@ Usage:
187
188
 
188
189
  0
189
190
  end
191
+
192
+ class Oneshot
193
+ def initialize(*args)
194
+ @args = args
195
+ end
196
+
197
+ def run
198
+ quiet = false
199
+ path = Dir.pwd
200
+ reporter = :text
201
+
202
+ OptionParser.new do |opts|
203
+ opts.on('-q', '--quiet', 'Turn off progress output.') do
204
+ quiet = true
205
+ end
206
+
207
+ opts.on('-d DIR', '--repo DIR', 'Specify path to working copy of git.') do |dir|
208
+ path = dir
209
+ end
210
+
211
+ opts.on('-r REPORTER', '--reporter REPORTER', 'Specify reporter') do |name|
212
+ reporter = name.to_sym
213
+ end
214
+
215
+ opts.on_tail('--help', 'Show this help') do
216
+ return usage
217
+ end
218
+ end.parse!(@args)
219
+
220
+ files = @args.map { |pattern|
221
+ Dir[pattern].map do |file_or_directory|
222
+ if FileTest.file?(file_or_directory)
223
+ file_or_directory
224
+ elsif FileTest.directory?(file_or_directory)
225
+ Dir[File.join(file_or_directory, '**', '*_spec.rb')]
226
+ else
227
+ abort "#{$0}: #{file_or_directory}: No such file or directory"
228
+ end
229
+ end
230
+ }.flatten
231
+
232
+ workspace = Workspace.new(path: path)
233
+ $stderr.puts '=> Detecting...' unless quiet
234
+ pendings = Detector.find(:rspec).new(workspace, out: quiet ? nil : $stderr).detect
235
+ $stderr.puts '=> Total Result:' unless quiet
236
+
237
+ notificator = Notificator.find(:terminal).new(
238
+ out: $stdout,
239
+ reporter: {use: reporter}
240
+ )
241
+ notificator.add pendings
242
+ notificator.notify
243
+
244
+ 0
245
+ end
246
+
247
+ def usage
248
+ $stderr.puts "Usage: pendaxes-oneshot [--help] [-q|--quiet] [-d DIR|--repo=DIR] [-r REPORTER|--reporter REPORTER] file_or_directory [file_or_directory ...]"
249
+ $stderr.puts ""
250
+ $stderr.puts "file_or_directory:"
251
+ $stderr.puts " File name, pattern or directory name to detect pendings."
252
+ $stderr.puts " if directory name given, will use *_spec.rb files in that directory (recursive)."
253
+ $stderr.puts ""
254
+ $stderr.puts " NOTE: Files should be managed by git."
255
+ $stderr.puts ""
256
+ $stderr.puts "--help: Show this help and quit."
257
+ $stderr.puts "--quiet, -q: Turn off progress output."
258
+ $stderr.puts "--repo, -d: Specify path to working copy of git repository. (default: current directory)"
259
+ $stderr.puts "--reporter, -r: Specify reporter. (Default: text)"
260
+ 0
261
+ end
262
+ end
190
263
  end
191
264
  end
@@ -0,0 +1,29 @@
1
+ require_relative '../notificator'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module Pendaxes
6
+ class Notificator
7
+ class GrowthForecast < Notificator
8
+ defaults service_name: 'pendaxes',
9
+ section_name: 'pendaxes',
10
+ graph_name: 'pendaxes'
11
+
12
+ def notify
13
+ post_growth_forecast @config.service_name,
14
+ @config.section_name,
15
+ @config.graph_name,
16
+ @pendings.size
17
+ end
18
+
19
+ private
20
+
21
+ def post_growth_forecast(service_name, section_name, graph_name, number, options = {})
22
+ if @config.host
23
+ uri = URI.parse("http://#{@config.host}/api/#{service_name}/#{section_name}/#{graph_name}")
24
+ Net::HTTP.post_form(uri, options.merge(:number => number))
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -7,12 +7,7 @@ module Pendaxes
7
7
 
8
8
  def notify
9
9
  io = @config.to
10
- pendings.group_by{|x| "#{x[:commit][:name]} <#{x[:commit][:email]}>" }.each do |name, pends|
11
- io.puts "#{name}:"
12
- io.puts
13
- io.puts report_for(pends)
14
- io.puts
15
- end
10
+ io.puts report_for(pendings)
16
11
  end
17
12
  end
18
13
  end
@@ -0,0 +1,12 @@
1
+ require_relative '../reporter'
2
+ require 'json'
3
+
4
+ module Pendaxes
5
+ class Reporter
6
+ class JSON < Reporter
7
+ def report
8
+ {pendings: pendings.sort_by{|x| x[:commit][:at] }}.to_json
9
+ end
10
+ end
11
+ end
12
+ end
@@ -4,9 +4,13 @@ module Pendaxes
4
4
  class Reporter
5
5
  class Text < Reporter
6
6
  def report
7
- pendings.sort_by{|x| x[:commit][:at] - Time.now }.map {|pending|
8
- "* #{pending[:example][:file]}:#{pending[:example][:line]} - #{pending[:example][:message]} (@ #{pending[:commit][:sha]} #{pending[:commit][:at]})"
9
- }.join("\n")
7
+ pendings.group_by{|x| "#{x[:commit][:name]} <#{x[:commit][:email]}>" }.map do |name, pends|
8
+ lines = pends.sort_by { |pending| pending[:commit][:at] }.map do |pending|
9
+ "* #{pending[:example][:file]}:#{pending[:example][:line]} - #{pending[:example][:message]} (@ #{pending[:commit][:sha]} #{pending[:commit][:at]})"
10
+ end.join("\n")
11
+
12
+ "#{name}:\n\n#{lines}"
13
+ end.join("\n\n")
10
14
  end
11
15
  end
12
16
  end
@@ -1,3 +1,3 @@
1
1
  module Pendaxes
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -41,7 +41,6 @@ foo <foo@example.com>:
41
41
  bar <bar@example.com>:
42
42
 
43
43
  * a_spec.rb:25 - pending 'because it fails...' (@ d #{now-864000})
44
-
45
44
  EOF
46
45
  end
47
46
 
@@ -59,7 +58,6 @@ bar <bar@example.com>:
59
58
 
60
59
  * a_spec.rb:25 - pending 'because it fails...' (@ d #{now-864000})
61
60
  * a_spec.rb:20 - pending 'because it fails..' (@ c #{now-86400})
62
-
63
61
  EOF
64
62
  end
65
63
  end
@@ -0,0 +1,32 @@
1
+ require_relative '../spec_helper'
2
+ require 'json'
3
+ require 'pendaxes/reporters/json'
4
+
5
+ describe Pendaxes::Reporter::JSON do
6
+ it "has Pendaxes::Reporter as superclass" do
7
+ described_class.superclass.should == Pendaxes::Reporter
8
+ end
9
+
10
+ describe "#report" do
11
+ subject { described_class.new }
12
+ let!(:now) { Time.now }
13
+
14
+ let(:pends) do
15
+ [
16
+ {commit: {sha: 'a', name: 'foo', email: 'foo@example.com', at: (now-86400)},
17
+ example: {file: 'a_spec.rb', line: 10, message: "pending 'because it fails'"}, allowed: true},
18
+ {commit: {sha: 'b', name: 'foo', email: 'foo@example.com', at: (now-864000)},
19
+ example: {file: 'a_spec.rb', line: 15, message: "pending 'because it fails.'"}, allowed: false}
20
+ ]
21
+ end
22
+
23
+ before do
24
+ subject.add(pends)
25
+ end
26
+
27
+ it "reports in JSON" do
28
+ subject.report.should == \
29
+ {pendings: pends.sort_by { |_| _[:commit][:at] }}.to_json
30
+ end
31
+ end
32
+ end
@@ -26,6 +26,8 @@ describe Pendaxes::Reporter::Text do
26
26
 
27
27
  it "reports older pending first" do
28
28
  subject.report.should == (<<-EOR).chomp
29
+ foo <foo@example.com>:
30
+
29
31
  * a_spec.rb:15 - pending 'because it fails.' (@ b #{now-864000})
30
32
  * a_spec.rb:10 - pending 'because it fails' (@ a #{now-86400})
31
33
  EOR
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pendaxes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashr
@@ -112,6 +112,7 @@ email:
112
112
  - sorah@cookpad.com
113
113
  executables:
114
114
  - pendaxes
115
+ - pendaxes-oneshot
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -122,6 +123,7 @@ files:
122
123
  - README.md
123
124
  - Rakefile
124
125
  - bin/pendaxes
126
+ - bin/pendaxes-oneshot
125
127
  - fixtures/repo.tar.gz
126
128
  - lib/pendaxes.rb
127
129
  - lib/pendaxes/command_line.rb
@@ -132,11 +134,13 @@ files:
132
134
  - lib/pendaxes/finder.rb
133
135
  - lib/pendaxes/notificator.rb
134
136
  - lib/pendaxes/notificators/file.rb
137
+ - lib/pendaxes/notificators/growth_forecast.rb
135
138
  - lib/pendaxes/notificators/mail.rb
136
139
  - lib/pendaxes/notificators/terminal.rb
137
140
  - lib/pendaxes/pending_manager.rb
138
141
  - lib/pendaxes/reporter.rb
139
142
  - lib/pendaxes/reporters/haml.rb
143
+ - lib/pendaxes/reporters/json.rb
140
144
  - lib/pendaxes/reporters/template.haml
141
145
  - lib/pendaxes/reporters/text.rb
142
146
  - lib/pendaxes/version.rb
@@ -152,6 +156,7 @@ files:
152
156
  - spec/pendaxes_spec.rb
153
157
  - spec/pending_manager_spec.rb
154
158
  - spec/reporter_spec.rb
159
+ - spec/reporters/json_spec.rb
155
160
  - spec/reporters/text_spec.rb
156
161
  - spec/spec_helper.rb
157
162
  - spec/workspace_spec.rb
@@ -169,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
174
  version: '0'
170
175
  segments:
171
176
  - 0
172
- hash: -1582125588923772707
177
+ hash: -175182318362856480
173
178
  required_rubygems_version: !ruby/object:Gem::Requirement
174
179
  none: false
175
180
  requirements:
@@ -178,10 +183,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
183
  version: '0'
179
184
  segments:
180
185
  - 0
181
- hash: -1582125588923772707
186
+ hash: -175182318362856480
182
187
  requirements: []
183
188
  rubyforge_project:
184
- rubygems_version: 1.8.23
189
+ rubygems_version: 1.8.24
185
190
  signing_key:
186
191
  specification_version: 3
187
192
  summary: Throw axes to pending makers! Leaving a pending long time is really bad,
@@ -199,6 +204,7 @@ test_files:
199
204
  - spec/pendaxes_spec.rb
200
205
  - spec/pending_manager_spec.rb
201
206
  - spec/reporter_spec.rb
207
+ - spec/reporters/json_spec.rb
202
208
  - spec/reporters/text_spec.rb
203
209
  - spec/spec_helper.rb
204
210
  - spec/workspace_spec.rb