bigtiger-rolex 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/bin/rolex +34 -0
- data/lib/rolex.rb +42 -4
- data/lib/rolex/line_item.rb +15 -8
- data/lib/rolex/report.rb +13 -12
- data/lib/time_ext.rb +5 -0
- data/rolex.gemspec +20 -7
- data/spec/rolex/line_item_spec.rb +35 -0
- data/spec/rolex_spec.rb +35 -9
- data/spec/spec_helper.rb +2 -2
- metadata +33 -9
data/Rakefile
CHANGED
@@ -9,6 +9,9 @@ begin
|
|
9
9
|
gem.email = "dev+bigtiger+sandro@hashrocket.com"
|
10
10
|
gem.homepage = "http://github.com/bigtiger/rolex"
|
11
11
|
gem.authors = ["bigtiger", "sandro"]
|
12
|
+
gem.add_dependency('mojombo-grit', '>= 1.1.1')
|
13
|
+
gem.add_dependency('mojombo-chronic', '>= 0.3.0')
|
14
|
+
gem.add_dependency('trollop', '>= 1.14')
|
12
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
16
|
end
|
14
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/rolex
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__) + "/../lib"))
|
4
|
+
require 'rolex'
|
5
|
+
|
6
|
+
opts = Trollop.options do
|
7
|
+
banner <<-EOS
|
8
|
+
Rolex is awesome
|
9
|
+
Examples:
|
10
|
+
rolex --author 'Sandro Turriate' --project '.' --date 'two days ago'
|
11
|
+
rolex --author 'sandro' --project '.' last week
|
12
|
+
rolex --author 'sandro' --project '.' this week
|
13
|
+
|
14
|
+
Usage:
|
15
|
+
rolex [options]
|
16
|
+
where [options] are:
|
17
|
+
EOS
|
18
|
+
|
19
|
+
opt :author, "Name of the git author", :type => String, :required => true
|
20
|
+
opt :project, "Directory with the git repo", :type => String, :default => Dir.pwd
|
21
|
+
opt :date, "The day you want to report", :type => String, :default => "today"
|
22
|
+
end
|
23
|
+
|
24
|
+
rolex = Rolex.new(opts[:project], opts[:author])
|
25
|
+
|
26
|
+
case ARGV.join(" ").downcase
|
27
|
+
when "last week"
|
28
|
+
rolex.last_week
|
29
|
+
when "this week"
|
30
|
+
rolex.this_week
|
31
|
+
else
|
32
|
+
rolex.report_for(opts[:date])
|
33
|
+
end
|
34
|
+
|
data/lib/rolex.rb
CHANGED
@@ -2,12 +2,17 @@ $:.unshift(File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
begin; require 'rubygems'; rescue LoadError; end
|
4
4
|
require 'grit'
|
5
|
+
require 'trollop'
|
6
|
+
require 'chronic'
|
7
|
+
|
5
8
|
require 'float_ext'
|
9
|
+
require 'time_ext'
|
6
10
|
|
7
11
|
class Rolex
|
8
12
|
autoload :Report, 'rolex/report'
|
9
13
|
autoload :LineItem, 'rolex/line_item'
|
10
|
-
|
14
|
+
|
15
|
+
attr_reader :repo
|
11
16
|
attr_accessor :who
|
12
17
|
|
13
18
|
def initialize(repo_location, who)
|
@@ -15,9 +20,42 @@ class Rolex
|
|
15
20
|
@repo = Grit::Repo.new(repo_location)
|
16
21
|
end
|
17
22
|
|
23
|
+
def last_week
|
24
|
+
report_range("last week monday", "last week sunday")
|
25
|
+
end
|
26
|
+
|
27
|
+
def report_for(date)
|
28
|
+
date = date_for(date)
|
29
|
+
commits = repo.commits_since nil, date, :until => date + 1, :author => who
|
30
|
+
Report.new(commits).run
|
31
|
+
end
|
32
|
+
|
33
|
+
def report_range(starting, ending)
|
34
|
+
starting = date_for starting
|
35
|
+
ending = date_for ending
|
36
|
+
(starting..ending).each do |date|
|
37
|
+
report_for date
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def this_week
|
42
|
+
report_range("last monday", "today")
|
43
|
+
end
|
44
|
+
|
18
45
|
def today
|
19
|
-
|
20
|
-
Report.new(commits, who).run
|
46
|
+
report_for Date.today
|
21
47
|
end
|
22
|
-
end
|
23
48
|
|
49
|
+
private
|
50
|
+
|
51
|
+
def date_for(time)
|
52
|
+
case time
|
53
|
+
when String
|
54
|
+
Chronic.parse(time).to_date
|
55
|
+
when Time
|
56
|
+
time.to_date
|
57
|
+
when Date
|
58
|
+
time
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/rolex/line_item.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
class Rolex
|
2
2
|
class LineItem
|
3
|
-
|
3
|
+
attr_reader :commit_message, :elapsed
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(commit_message, elapsed)
|
6
|
+
@commit_message = commit_message
|
7
7
|
@elapsed = elapsed
|
8
8
|
end
|
9
9
|
|
10
|
-
def to_s
|
11
|
-
"#{message} - #{elapsed_time_in_hours}"
|
12
|
-
end
|
13
|
-
|
14
10
|
def elapsed_time_in_hours
|
15
11
|
elapsed.nil? ? 0 : (elapsed / 60 / 60).round_to(2)
|
16
12
|
end
|
13
|
+
|
14
|
+
def message
|
15
|
+
commit_message.map do |line|
|
16
|
+
new_line = line.strip.gsub(/^- /,'')
|
17
|
+
new_line unless new_line.empty?
|
18
|
+
end.compact.join "; "
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
sprintf "%-4s - %s", elapsed_time_in_hours, message
|
23
|
+
end
|
17
24
|
end
|
18
|
-
end
|
25
|
+
end
|
data/lib/rolex/report.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Rolex
|
2
2
|
class Report
|
3
|
-
attr_reader :commits, :
|
3
|
+
attr_reader :commits, :lines
|
4
|
+
private :lines
|
4
5
|
|
5
|
-
def initialize(commits
|
6
|
-
@who = who
|
6
|
+
def initialize(commits)
|
7
7
|
@commits = commits.reverse
|
8
8
|
@lines = []
|
9
9
|
end
|
@@ -13,25 +13,26 @@ class Rolex
|
|
13
13
|
elapsed = nil
|
14
14
|
if c != commits.first
|
15
15
|
previous = commits[i-1]
|
16
|
-
elapsed = c.
|
16
|
+
elapsed = c.authored_date - previous.authored_date
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
lines << LineItem.new(c.message, elapsed)
|
20
|
+
end
|
21
|
+
|
22
|
+
if lines.any?
|
23
|
+
lines << "Total time: #{total_elapsed_time}\n\n"
|
24
|
+
lines.unshift "Commits on #{commits.first.authored_date.to_date}"
|
25
|
+
puts lines.join("\n")
|
22
26
|
end
|
23
|
-
@lines << "Total time: #{total_elapsed_time}"
|
24
|
-
@lines.join("\n")
|
25
27
|
end
|
26
28
|
|
27
29
|
def total_elapsed_time
|
28
30
|
total = 0
|
29
|
-
|
31
|
+
lines.each do |l|
|
30
32
|
total += l.elapsed_time_in_hours
|
31
33
|
end
|
32
34
|
|
33
35
|
total
|
34
36
|
end
|
35
|
-
|
36
37
|
end
|
37
|
-
end
|
38
|
+
end
|
data/lib/time_ext.rb
ADDED
data/rolex.gemspec
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rolex}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["
|
9
|
-
s.date = %q{2009-
|
10
|
-
s.
|
8
|
+
s.authors = ["bigtiger", "sandro"]
|
9
|
+
s.date = %q{2009-07-17}
|
10
|
+
s.default_executable = %q{rolex}
|
11
|
+
s.email = %q{dev+bigtiger+sandro@hashrocket.com}
|
12
|
+
s.executables = ["rolex"]
|
11
13
|
s.extra_rdoc_files = [
|
12
14
|
"LICENSE",
|
13
15
|
"README.rdoc"
|
@@ -19,11 +21,14 @@ Gem::Specification.new do |s|
|
|
19
21
|
"README.rdoc",
|
20
22
|
"Rakefile",
|
21
23
|
"VERSION",
|
24
|
+
"bin/rolex",
|
22
25
|
"lib/float_ext.rb",
|
23
26
|
"lib/rolex.rb",
|
24
27
|
"lib/rolex/line_item.rb",
|
25
28
|
"lib/rolex/report.rb",
|
29
|
+
"lib/time_ext.rb",
|
26
30
|
"rolex.gemspec",
|
31
|
+
"spec/rolex/line_item_spec.rb",
|
27
32
|
"spec/rolex_spec.rb",
|
28
33
|
"spec/spec_helper.rb"
|
29
34
|
]
|
@@ -34,7 +39,8 @@ Gem::Specification.new do |s|
|
|
34
39
|
s.rubygems_version = %q{1.3.1}
|
35
40
|
s.summary = %q{TODO}
|
36
41
|
s.test_files = [
|
37
|
-
"spec/
|
42
|
+
"spec/rolex/line_item_spec.rb",
|
43
|
+
"spec/rolex_spec.rb",
|
38
44
|
"spec/spec_helper.rb"
|
39
45
|
]
|
40
46
|
|
@@ -43,10 +49,17 @@ Gem::Specification.new do |s|
|
|
43
49
|
s.specification_version = 2
|
44
50
|
|
45
51
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<mojombo-grit>, [">= 1.1.1"])
|
53
|
+
s.add_runtime_dependency(%q<mojombo-chronic>, [">= 0.3.0"])
|
54
|
+
s.add_runtime_dependency(%q<trollop>, [">= 1.14"])
|
46
55
|
else
|
56
|
+
s.add_dependency(%q<mojombo-grit>, [">= 1.1.1"])
|
57
|
+
s.add_dependency(%q<mojombo-chronic>, [">= 0.3.0"])
|
58
|
+
s.add_dependency(%q<trollop>, [">= 1.14"])
|
47
59
|
end
|
48
60
|
else
|
61
|
+
s.add_dependency(%q<mojombo-grit>, [">= 1.1.1"])
|
62
|
+
s.add_dependency(%q<mojombo-chronic>, [">= 0.3.0"])
|
63
|
+
s.add_dependency(%q<trollop>, [">= 1.14"])
|
49
64
|
end
|
50
|
-
|
51
|
-
s.add_dependency("grit", [">= 1.1.1"])
|
52
65
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Rolex::LineItem do
|
4
|
+
describe "#message" do
|
5
|
+
it "replaces new lines with semi-colons" do
|
6
|
+
line = Rolex::LineItem.new("refactored\nthing 1\nthing 2", 500)
|
7
|
+
line.message.should == "refactored; thing 1; thing 2"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "gets rid of multiple new lines" do
|
11
|
+
line = Rolex::LineItem.new("refactored\n\n\n\nthing 1", 500)
|
12
|
+
line.message.should == "refactored; thing 1"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesn't add semi-colons when there is only one new line" do
|
16
|
+
line = Rolex::LineItem.new("refactored\n", 500)
|
17
|
+
line.message.should == "refactored"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't add semi-colons when there is no new line" do
|
21
|
+
line = Rolex::LineItem.new("refactored", 500)
|
22
|
+
line.message.should == "refactored"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "removes hyphens at the beginning of a new line" do
|
26
|
+
line = Rolex::LineItem.new("refactored\n- thing 1\n- thing 2", 500)
|
27
|
+
line.message.should == "refactored; thing 1; thing 2"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "removes leading and trailing whitespace" do
|
31
|
+
line = Rolex::LineItem.new(" refactored\n - thing 1\n- thing 2 ", 500)
|
32
|
+
line.message.should == "refactored; thing 1; thing 2"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/rolex_spec.rb
CHANGED
@@ -3,24 +3,50 @@ require File.join(File.dirname(__FILE__),'spec_helper')
|
|
3
3
|
describe "Rolex" do
|
4
4
|
before do
|
5
5
|
@commits = ["commit1", "commit2"]
|
6
|
-
@
|
7
|
-
@rolex = Rolex.new(@repo, "someuser")
|
6
|
+
@rolex = Rolex.new('.', "someuser")
|
8
7
|
@report = stub('report', :run => true)
|
8
|
+
@now = Time.now
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
it "reports on today" do
|
12
|
+
@rolex.should_receive(:report_for).with(Date.today)
|
13
|
+
@rolex.today
|
14
|
+
end
|
15
|
+
|
16
|
+
it "reports on last week" do
|
17
|
+
@rolex.should_receive(:report_range).with("last week monday", "last week sunday")
|
18
|
+
@rolex.last_week
|
19
|
+
end
|
20
|
+
|
21
|
+
it "reports on this week" do
|
22
|
+
@rolex.should_receive(:report_range).with("last monday", "today")
|
23
|
+
@rolex.this_week
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#report_for" do
|
27
|
+
it "parses strings with Chronic" do
|
28
|
+
Chronic.should_receive(:parse).with("yesterday").and_return(Time.now)
|
29
|
+
@rolex.report_for("yesterday")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "retrieves commits" do
|
33
|
+
@rolex.repo.should_receive(:commits_since).with(nil, @now.to_date, :until => @now.to_date + 1, :author => @rolex.who).and_return(@commits)
|
34
|
+
Rolex::Report.should_receive(:new).with(@commits).and_return(@report)
|
35
|
+
@rolex.report_for(@now)
|
16
36
|
end
|
17
|
-
|
37
|
+
|
18
38
|
it "runs a report" do
|
19
|
-
|
39
|
+
@rolex.repo.stub!(:commits_since => @commits)
|
20
40
|
Rolex::Report.stub!(:new).and_return(@report)
|
21
41
|
@report.should_receive(:run)
|
22
42
|
@rolex.today
|
23
43
|
end
|
24
44
|
end
|
25
45
|
|
46
|
+
describe "#report_range" do
|
47
|
+
it "finds the commits for the given time period" do
|
48
|
+
@rolex.should_receive(:report_for).at_least(2).times
|
49
|
+
@rolex.report_range("yesterday", "today")
|
50
|
+
end
|
51
|
+
end
|
26
52
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigtiger-rolex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- bigtiger
|
8
|
+
- sandro
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
14
|
-
default_executable:
|
13
|
+
date: 2009-07-17 00:00:00 -07:00
|
14
|
+
default_executable: rolex
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name: grit
|
17
|
+
name: mojombo-grit
|
18
18
|
type: :runtime
|
19
19
|
version_requirement:
|
20
20
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -23,10 +23,30 @@ dependencies:
|
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 1.1.1
|
25
25
|
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mojombo-chronic
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.3.0
|
35
|
+
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: trollop
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "1.14"
|
45
|
+
version:
|
26
46
|
description:
|
27
|
-
email: bigtiger+
|
28
|
-
executables:
|
29
|
-
|
47
|
+
email: dev+bigtiger+sandro@hashrocket.com
|
48
|
+
executables:
|
49
|
+
- rolex
|
30
50
|
extensions: []
|
31
51
|
|
32
52
|
extra_rdoc_files:
|
@@ -39,11 +59,14 @@ files:
|
|
39
59
|
- README.rdoc
|
40
60
|
- Rakefile
|
41
61
|
- VERSION
|
62
|
+
- bin/rolex
|
42
63
|
- lib/float_ext.rb
|
43
64
|
- lib/rolex.rb
|
44
65
|
- lib/rolex/line_item.rb
|
45
66
|
- lib/rolex/report.rb
|
67
|
+
- lib/time_ext.rb
|
46
68
|
- rolex.gemspec
|
69
|
+
- spec/rolex/line_item_spec.rb
|
47
70
|
- spec/rolex_spec.rb
|
48
71
|
- spec/spec_helper.rb
|
49
72
|
has_rdoc: true
|
@@ -73,5 +96,6 @@ signing_key:
|
|
73
96
|
specification_version: 2
|
74
97
|
summary: TODO
|
75
98
|
test_files:
|
99
|
+
- spec/rolex/line_item_spec.rb
|
76
100
|
- spec/rolex_spec.rb
|
77
101
|
- spec/spec_helper.rb
|