gitwakatime 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d47de3815abb7edcfb65449699ce7ed4ea939de
4
- data.tar.gz: f540146be05016d14cb0272603257403cb4a31f5
3
+ metadata.gz: 168b591ace36a3aee27b46f91c877e1c7ed46dd9
4
+ data.tar.gz: ea9639102940b3d512fefb4d94ea89deab3d8d1e
5
5
  SHA512:
6
- metadata.gz: 6e9bebde6645f4b5052ef01af5d6bd7a7e6217814caa6c1766ea25aa0875fd7b1a4f6678f1083a82a97ccb2d53babeecbbef5c7b31d7a470e0b0dbbf2913e636
7
- data.tar.gz: b6065a0f59b9f06ee0b657c48c4b109c699e7afac461ff443324f7e54e095f2cf57129af079dffae46b6eef877dff21165fb02230c5336f5643f01dbe6f113f6
6
+ metadata.gz: a5d4ff163d2161129b89b98c57c5d8a3fe0067248c3ae2c54f6080cc13e3a781d5a96044336ec1d23cac22135099b0c1a5fe93a8ac597550c861dc149ce3925c
7
+ data.tar.gz: cde46c05f64e924f5a9d8128337d77542e79f2c265fe8a6d0fac046c6d7e220858af69b183cc23454a99bacb7ac693e9d423d1d8a574c32afa18936093d76dc3
@@ -51,21 +51,21 @@ module GitWakaTime
51
51
  path: File.expand_path(options.file), date: date
52
52
  ).timer
53
53
 
54
- print_output(@timer)
54
+ print_output(@timer, format: options.output)
55
55
  end
56
56
 
57
57
  no_commands do
58
- def print_output(timer)
59
- if output == 'text'
58
+ def print_output(timer, format: 'text')
59
+ if format == 'text'
60
60
  timer.each do |c_date, commits|
61
61
  print_commit(c_date, commits)
62
62
  end
63
- elsif output == 'json'
63
+ elsif format == 'json'
64
64
  @timer.to_json
65
65
  end
66
66
  end
67
67
 
68
- def print_commit
68
+ def print_commit(c_date, commits)
69
69
  sum_c_time = commits.map(&:time_in_seconds).compact.reduce(&:+).to_i
70
70
  Log.new format(
71
71
  '%-40s %-40s'.blue,
@@ -25,18 +25,16 @@ module GitWakaTime
25
25
  # out of commits to check
26
26
  def find_dependent_commit(name, i = 1)
27
27
  commits = load_dependent_commits(name)
28
- loop do
28
+ begin
29
29
  commit = commits[i]
30
- break if commit.nil?
31
30
 
32
- next unless allowed_commit(commit)
31
+ if commit && allowed_commit(commit)
32
+ set dependent_sha: commit.sha, dependent_date: commit.date
33
+ check_and_correct_split_tree(commit)
34
+ end
33
35
 
34
- set dependent_sha: commit.sha, dependent_date: commit.date
35
-
36
- check_and_correct_split_tree(commit)
37
36
  i += 1
38
- break unless dependent_sha.blank?
39
- end
37
+ end until !dependent_sha.nil? || commit.nil?
40
38
  end
41
39
 
42
40
  def check_and_correct_split_tree(commit)
@@ -44,16 +44,17 @@ module GitWakaTime
44
44
 
45
45
  def cached?
46
46
  # Check to see if this date range might be stale?
47
- if cached_heartbeats.count > 0
48
- max_local_timetamp = (
49
- Time.parse(cached_heartbeats.max(:time)) + 3.day
50
- ).to_date
51
- !(
52
- @args[:start].to_date..@args[:end].to_date
53
- ).include?(max_local_timetamp)
54
- else
55
- false
56
- end
47
+ # if cached_heartbeats.count > 0
48
+ # max_local_timetamp = (
49
+ # Time.parse(cached_heartbeats.max(:time)) + 15.day
50
+ # ).to_date
51
+ # !(
52
+ # @args[:start].to_date..@args[:end].to_date
53
+ # ).include?(max_local_timetamp)
54
+ # else
55
+ # false
56
+ # end
57
+ false
57
58
  end
58
59
 
59
60
  def cached_heartbeats
@@ -8,7 +8,7 @@ module GitWakaTime
8
8
  def initialize(commits, files, project, _path = nil)
9
9
  @commits = commits
10
10
  @files = files
11
- @api_limit = 35
11
+ @api_limit = 1
12
12
  @project = project
13
13
  @requests = build_requests
14
14
  end
@@ -19,8 +19,9 @@ module GitWakaTime
19
19
  timestamps = (commits + d_commits.flatten).uniq.sort
20
20
 
21
21
  # Don't query before the Wakatime Epoch
22
- @start_at = if timestamps.first >= Time.new(2013, 5, 1)
23
- timestamps.first
22
+ first_commit_at = timestamps.first
23
+ @start_at = if first_commit_at && first_commit_at >= Time.new(2013, 5, 1)
24
+ first_commit_at
24
25
  else
25
26
  Time.new(2013, 5, 1)
26
27
  end
@@ -1,4 +1,4 @@
1
1
  # Version Number Definition
2
2
  module GitWakaTime
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitWakaTime::Cli do
4
+ before do
5
+ stub_request(:get, /wakatime\.com/)
6
+ .with(query: hash_including(:start, :end))
7
+ .to_return(body: File.read('./spec/fixtures/heartbeats.json'), status: 200)
8
+ end
9
+ it 'should be able to be called' do
10
+ ARGV.replace %w[tally --start_on 2012-01-01 --file] << @wdir.to_s
11
+ expect(capture(:stdout) { GitWakaTime::Cli.start }).to eq ''
12
+ # puts GitWakaTime::Cli.start('tally', "--file #{@wdir.to_s}")
13
+ end
14
+ end
data/spec/spec_helper.rb CHANGED
@@ -41,6 +41,19 @@ require 'webmock/rspec'
41
41
 
42
42
  WebMock.disable_net_connect!(allow: 'codeclimate.com')
43
43
 
44
+ def capture(stream)
45
+ begin
46
+ stream = stream.to_s
47
+ eval "$#{stream} = StringIO.new"
48
+ yield
49
+ result = eval("$#{stream}").string
50
+ ensure
51
+ eval("$#{stream} = #{stream.upcase}")
52
+ end
53
+
54
+ result
55
+ end
56
+
44
57
  def set_file_paths
45
58
  @test_dir = File.join(File.dirname(__FILE__))
46
59
  @wdir_dot = File.expand_path(File.join(@test_dir, 'dummy'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitwakatime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-13 00:00:00.000000000 Z
13
+ date: 2015-03-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: git
@@ -239,6 +239,7 @@ files:
239
239
  - lib/gitwakatime/query.rb
240
240
  - lib/gitwakatime/timer.rb
241
241
  - lib/gitwakatime/version.rb
242
+ - spec/cli_spec.rb
242
243
  - spec/commit_spec.rb
243
244
  - spec/commited_file_spec.rb
244
245
  - spec/dummy/dot_git/FETCH_HEAD
@@ -315,12 +316,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
316
  version: '0'
316
317
  requirements: []
317
318
  rubyforge_project:
318
- rubygems_version: 2.4.5
319
+ rubygems_version: 2.2.2
319
320
  signing_key:
320
321
  specification_version: 4
321
322
  summary: A Tool that will compile git data with wakatime data to establish time per
322
323
  commit
323
324
  test_files:
325
+ - spec/cli_spec.rb
324
326
  - spec/commit_spec.rb
325
327
  - spec/commited_file_spec.rb
326
328
  - spec/dummy/dot_git/FETCH_HEAD