clockout 0.5.3 → 0.6
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.
- checksums.yaml +4 -4
- data/bin/clock +13 -21
- data/lib/clockout.rb +19 -48
- data/lib/record.rb +10 -23
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 154224b857d9ee8cf5c769c4073a6df0f7c91631
|
4
|
+
data.tar.gz: 6fe6c7a5ce04129f0427bc1ee9d95cfa7e7f3ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b4d39a6a10f94e959cd71d42991faffda8bff3770a63790a90c883ff46c26b3a45405ab6ea8d881311d5798d2f75d9fd5ff2f71abaf5e5111a7c9d018b0eda
|
7
|
+
data.tar.gz: f13404df40ad6f5098737f145249402d86b6ea21ba84096cc7ba125b85c522a7b4ed76a3b327ed4f034e80f81f33ac65ca49692374779f080187d35f15e1c22c
|
data/bin/clock
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'clockout'
|
4
4
|
|
5
|
+
VERSION = "0.6"
|
6
|
+
|
5
7
|
HELP_BANNER = <<-EOS
|
6
8
|
|
7
9
|
See hours:
|
@@ -38,32 +40,15 @@ TEMPLATE_CLOCKFILE = <<-EOF
|
|
38
40
|
|
39
41
|
#time_cutoff: 90
|
40
42
|
|
41
|
-
|
42
|
-
### Time-estimation options for each first commit of a timeblock ###
|
43
|
-
|
44
|
-
# Diffs of files matched by this regex will be included in commit time estimation.
|
45
|
-
# With some projects, there are diffs to binaries, images, files modified by an IDE, etc,
|
46
|
-
# that you don't want to report as your own work. Below is an example regex that will only
|
47
|
-
# calculate changes made to files with those extensions
|
48
|
-
# - Default: /.*/ (matches everything)
|
49
|
-
|
50
|
-
#my_files: /\\.(m|h|txt)$/
|
51
|
-
|
52
|
-
# Diffs of files matched by this regex will NOT be included in commit time estimation
|
53
|
-
# You also have the option of defining a negative regex match, to ignore certain files.
|
54
|
-
# For example, if you added an external library or something, you should ignore it
|
55
|
-
# - Default: <nothing>
|
56
|
-
|
57
|
-
#not_my_files: /SomeThirdPartyLibrary/
|
58
|
-
|
59
|
-
# Estimation factor
|
43
|
+
# Estimation factor (for each first commit of a timeblock)
|
60
44
|
# Use the -e option to see the estimations Clockout makes, and tweak them using this
|
61
45
|
# value as necessary.
|
62
46
|
# - Default: 1.0
|
63
47
|
|
64
48
|
#estimation_factor: 0.9
|
65
49
|
|
66
|
-
# Put any override times for specific commits here (minutes). (You can use SHA1 hashes
|
50
|
+
# Put any override times for specific commits here (minutes). (You can use SHA1 hashes
|
51
|
+
# of any length). Useful for ignoring commits that add 3rd party libraries, say.
|
67
52
|
# Note: keep a space before each hash for the YAML to parse properly.
|
68
53
|
|
69
54
|
#overrides:
|
@@ -90,6 +75,8 @@ def parse_options(args)
|
|
90
75
|
next_arg = args[i+1]
|
91
76
|
if (arg == "-h" || arg == "--help")
|
92
77
|
opts[:help] = true
|
78
|
+
elsif (arg == "-v" || arg == "--version")
|
79
|
+
opts[:version] = true
|
93
80
|
elsif (arg == "-e" || arg == "--estimations")
|
94
81
|
opts[:estimations] = true
|
95
82
|
elsif (arg == "-c" || arg == "--condensed")
|
@@ -183,6 +170,11 @@ else
|
|
183
170
|
exit
|
184
171
|
end
|
185
172
|
|
173
|
+
if opts[:version]
|
174
|
+
puts VERSION
|
175
|
+
exit
|
176
|
+
end
|
177
|
+
|
186
178
|
if opts[:generate]
|
187
179
|
root = Clockout.root_path(path)
|
188
180
|
exit if !root
|
@@ -221,7 +213,7 @@ else
|
|
221
213
|
puts "Showing hours for #{user}"
|
222
214
|
end
|
223
215
|
|
224
|
-
max =
|
216
|
+
max = 800
|
225
217
|
clock = Clockout.new(path, user, max)
|
226
218
|
printer = Printer.new(clock)
|
227
219
|
|
data/lib/clockout.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'rugged'
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
require 'printer'
|
@@ -7,26 +7,12 @@ require 'record'
|
|
7
7
|
COLS = 80
|
8
8
|
DAY_FORMAT = '%B %e, %Y'
|
9
9
|
|
10
|
-
# Grit does not support Ruby 2.0 right now
|
11
|
-
class String
|
12
|
-
if ((defined? RUBY_VERSION) && (RUBY_VERSION[0..2] == "1.9" || RUBY_VERSION[0].to_i >= 2))
|
13
|
-
def getord(offset); self[offset].ord; end
|
14
|
-
else
|
15
|
-
alias :getord :[]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
10
|
class Clockout
|
20
11
|
attr_accessor :blocks, :time_per_day, :maxed_out
|
21
12
|
|
22
|
-
def commits_to_records(
|
23
|
-
|
24
|
-
|
25
|
-
grit_commits.each_with_index.map do |commit, i|
|
26
|
-
c = Commit.new(commit)
|
27
|
-
c.stats = commit_stats[i][1]
|
28
|
-
c.calculate_diffs(my_files, not_my_files)
|
29
|
-
c
|
13
|
+
def commits_to_records(git_commits)
|
14
|
+
git_commits.each_with_index.map do |commit, i|
|
15
|
+
Commit.new(commit)
|
30
16
|
end
|
31
17
|
end
|
32
18
|
|
@@ -164,13 +150,13 @@ class Clockout
|
|
164
150
|
blocks
|
165
151
|
end
|
166
152
|
|
167
|
-
def prepare_blocks(commits_in,
|
153
|
+
def prepare_blocks(commits_in, author)
|
168
154
|
clockins = $opts[:in] || {}
|
169
155
|
clockouts = $opts[:out] || {}
|
170
156
|
|
171
157
|
# Convert clock-in/-outs into Clock objs & commits into Commit objs
|
172
158
|
clocks = clocks_to_records(clockins, :in) + clocks_to_records(clockouts, :out)
|
173
|
-
commits = commits_to_records(commits_in
|
159
|
+
commits = commits_to_records(commits_in)
|
174
160
|
|
175
161
|
# Merge & sort everything by date
|
176
162
|
data = (commits + clocks).sort { |a,b| a.date <=> b.date }
|
@@ -185,29 +171,9 @@ class Clockout
|
|
185
171
|
@blocks.last.last
|
186
172
|
end
|
187
173
|
|
188
|
-
def self.get_repo(path
|
189
|
-
|
190
|
-
|
191
|
-
rescue Exception => e
|
192
|
-
if e.class == Grit::NoSuchPathError
|
193
|
-
puts_error "Path '#{path}' could not be found."
|
194
|
-
return nil
|
195
|
-
else
|
196
|
-
# Must have drilled down to /
|
197
|
-
if (path.length <= 1)
|
198
|
-
puts_error "'#{original_path}' is not a Git repository."
|
199
|
-
return nil
|
200
|
-
end
|
201
|
-
|
202
|
-
# Could be that we're in a directory inside the repo
|
203
|
-
# Strip off last directory
|
204
|
-
one_up = path
|
205
|
-
while ((one_up = one_up[0..-2])[-1] != '/') do end
|
206
|
-
|
207
|
-
# Recursively try one level higher
|
208
|
-
return get_repo(one_up[0..-2], path)
|
209
|
-
end
|
210
|
-
end
|
174
|
+
def self.get_repo(path)
|
175
|
+
repo = Rugged::Repository.discover(path)
|
176
|
+
return repo, repo.workdir
|
211
177
|
end
|
212
178
|
|
213
179
|
def self.parse_clockfile(file)
|
@@ -226,7 +192,7 @@ class Clockout
|
|
226
192
|
|
227
193
|
def self.clock_path(path)
|
228
194
|
return nil if !path
|
229
|
-
path
|
195
|
+
File.join(path,"clock.yml")
|
230
196
|
end
|
231
197
|
|
232
198
|
def self.root_path(path)
|
@@ -234,11 +200,17 @@ class Clockout
|
|
234
200
|
root_path
|
235
201
|
end
|
236
202
|
|
203
|
+
def get_commits(repo, num)
|
204
|
+
walker = Rugged::Walker.new(repo)
|
205
|
+
walker.push(repo.head.target_id)
|
206
|
+
walker.each.take(num)
|
207
|
+
end
|
208
|
+
|
237
209
|
def initialize(path = nil, author = nil, num = 1)
|
238
210
|
@time_per_day = Hash.new(0)
|
239
211
|
|
240
212
|
# Default options
|
241
|
-
$opts = {time_cutoff:120,
|
213
|
+
$opts = {time_cutoff:120, estimation_factor:1.0}
|
242
214
|
|
243
215
|
if path
|
244
216
|
repo, root_path = Clockout.get_repo(path) || exit
|
@@ -249,12 +221,11 @@ class Clockout
|
|
249
221
|
# Merge with config override options
|
250
222
|
$opts.merge!(clock_opts) if clock_opts
|
251
223
|
|
252
|
-
commits = repo
|
253
|
-
commit_stats = repo.commit_stats('master', num).reverse #much faster if retrieved in batch
|
224
|
+
commits = get_commits(repo, num)
|
254
225
|
|
255
226
|
@maxed_out = (commits.size == num)
|
256
227
|
|
257
|
-
prepare_blocks(commits,
|
228
|
+
prepare_blocks(commits, author)
|
258
229
|
end
|
259
230
|
end
|
260
231
|
end
|
data/lib/record.rb
CHANGED
@@ -4,40 +4,27 @@ end
|
|
4
4
|
|
5
5
|
class Commit < Record
|
6
6
|
# From Grit::Commit object
|
7
|
-
attr_accessor :message, :
|
7
|
+
attr_accessor :message, :diffs, :sha
|
8
8
|
# Time calc
|
9
9
|
attr_accessor :minutes, :addition, :overriden, :estimated
|
10
10
|
# Whether it's been padded by a clock in/out
|
11
11
|
attr_accessor :clocked_in, :clocked_out
|
12
12
|
|
13
|
-
def initialize(commit = nil, date = nil)
|
13
|
+
def initialize(commit = nil, date = nil, paths = nil)
|
14
14
|
@addition = 0
|
15
15
|
@date = date
|
16
16
|
if commit
|
17
|
-
@author = commit.author
|
18
|
-
@date = commit.
|
17
|
+
@author = commit.author[:email]
|
18
|
+
@date = commit.time
|
19
19
|
@message = commit.message.gsub("\n",' ')
|
20
|
-
@sha = commit.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
plus, minus = 0, 0
|
28
|
-
|
29
|
-
@stats.to_diffstat.each do |diff_stat|
|
30
|
-
should_include = (diff_stat.filename =~ my_files)
|
31
|
-
should_ignore = not_my_files && (diff_stat.filename =~ not_my_files)
|
32
|
-
if should_include && !should_ignore
|
33
|
-
plus += diff_stat.additions
|
34
|
-
minus += diff_stat.deletions
|
20
|
+
@sha = commit.oid
|
21
|
+
@diffs = 0
|
22
|
+
commit.diff(commit.parents[0]).each_patch do |patch|
|
23
|
+
# Weight deletions half as much, since they are typically
|
24
|
+
# faster to do & also are 1:1 with additions when changing a line
|
25
|
+
@diffs += patch.stat[0] + patch.stat[1]/2
|
35
26
|
end
|
36
27
|
end
|
37
|
-
|
38
|
-
# Weight deletions half as much, since they are typically
|
39
|
-
# faster to do & also are 1:1 with additions when changing a line
|
40
|
-
@diffs = plus+minus/2
|
41
28
|
end
|
42
29
|
end
|
43
30
|
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Hassin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rugged
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
@@ -51,7 +51,8 @@ files:
|
|
51
51
|
- lib/printer.rb
|
52
52
|
- bin/clock
|
53
53
|
homepage: http://rubygems.org/gems/clockout
|
54
|
-
licenses:
|
54
|
+
licenses:
|
55
|
+
- license.md
|
55
56
|
metadata: {}
|
56
57
|
post_install_message:
|
57
58
|
rdoc_options: []
|