idonethis-cli 0.19.1 → 0.20.0

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: 14ce6262770b8a91791e7659ef80beee8568a43a
4
- data.tar.gz: 740ee4fbcb73ebea819e0e65e77bedb313b506db
3
+ metadata.gz: 52ddf0a1aa33911dadfdd46c60f4367c3a4f65b5
4
+ data.tar.gz: e41021117c04ff81be509a3cd7a59f2ef1e8d5d9
5
5
  SHA512:
6
- metadata.gz: 463a71c6b3d9fd868737df92471ca9961d0c8d3927103b348e19bfc6835d2c5a892a6ca203cb6a680f650ca41d4785d471d38e653867c264872b104f6e90e42e
7
- data.tar.gz: 379aad6a548ab0660bce11bd886cff74c60611266b7c5ef5b6b2a2890d23fc7d3ccabfc9404fd8573eae9e2ebad21dadf6d16e1c5003124e0eda0bcc9f157961
6
+ metadata.gz: b4e5fca05c75c7b6f4cfc566093aa836d935cf004e282f32896d68e7f52cc2f5a2ab097762e2d408a8106b38537a3a2b347dde9b6ae77a62807591cef5f412d5
7
+ data.tar.gz: 7c780b5eb405768d7c958d41a141652dbbe28504f00a7e66a30f0fdb1d41bec3479ad57b8b34eca5fa07a05f85c3fced5ab0272d768a5da92910e9e210a542e1
@@ -1,24 +1,32 @@
1
1
  module Idonethis::Adapters
2
2
  module Git
3
3
  class << self
4
- def commits(dir, since, how_many = 1000)
4
+ def commits(opts={})
5
5
  require 'git'
6
+
7
+ fail "opts is supposed to be a hash" unless opts.is_a?(Hash)
6
8
 
7
- since_when = case since
8
- when 'yesterday'
9
- '1am yesterday'
10
- when 'today'
11
- '1am'
12
- else
13
- since
14
- end
9
+ dir, since, how_many, log = defaults.merge(opts).values_at(:dir, :since, :how_many, :log)
10
+
11
+ since_when = since.strftime("%d-%b-%Y")
12
+
13
+ since_when = '1am' if since == Date.today
14
+ since_when = '1am yesterday' if since == (Date.today - 1)
15
+
16
+ log.call("Using <#{since_when}> as the since date for git")
15
17
 
16
- ::Git.open(dir).log(how_many).since(since_when)
18
+ ::Git.open(dir).log(how_many).since("1am #{since_when}")
17
19
  end
18
20
 
19
21
  def repo?(dir)
20
22
  File.exists?(File.join(dir, ".git"))
21
23
  end
24
+
25
+ private
26
+
27
+ def defaults
28
+ { log: ->(msg) {}, how_many: 1000 }
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -2,25 +2,32 @@ module Idonethis::Adapters
2
2
  module IO
3
3
  module DirectoryInfo
4
4
  class << self
5
- def modified_today?(dir)
5
+ def modified(opts)
6
+ since,dir,log = defaults.merge(opts).values_at(:since, :dir, :log)
7
+
6
8
  return [] unless File.exists?(dir)
7
9
 
8
- now = Time.now
9
-
10
- _in(dir).select{|it| any_file_inside_changed?(it, now) }
10
+ _in(dir).select{|it| any_file_inside_changed?(it, since, log) }
11
11
  end
12
-
12
+
13
13
  private
14
14
 
15
- def any_file_inside_changed?(dir, now)
15
+ def any_file_inside_changed?(dir, since, log)
16
16
  Dir["#{dir}/**/**"].each do |file|
17
- return true if today?(File.ctime(file), now)
17
+ modified_time = File.mtime(file)
18
+ modified = modified_time >= since.to_time
19
+
20
+ log.call("[DirectoryInfo] Checking files inside <#{dir}>. <#{file}> has changed since <#{since}>. Its ctime is <#{modified_time}>") if modified
21
+
22
+ return true if modified
18
23
  end
19
24
  return false
20
25
  end
21
26
 
22
- def today?(time, now)
23
- time.year == now.year && time.month == now.month && time.day == now.day
27
+ def same_day?(a, b)
28
+ a.year == b.year &&
29
+ a.month == b.month &&
30
+ a.day == b.day
24
31
  end
25
32
 
26
33
  def _in(dir)
@@ -29,6 +36,12 @@ module Idonethis::Adapters
29
36
  select{|it| File.directory?(File.join(dir, it))}.
30
37
  map{ |it| File.expand_path(File.join(dir, it))}
31
38
  end
39
+
40
+ private
41
+
42
+ def defaults
43
+ { log: ->(msg) {}}
44
+ end
32
45
  end
33
46
  end
34
47
  end
@@ -1,5 +1,5 @@
1
1
  module Idonethis
2
2
  module Cli
3
- VERSION = "0.19.1"
3
+ VERSION = "0.20.0"
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ module Idonethis::UseCases
8
8
  git = args[:git] || fail("You need to supply :git adapter")
9
9
  view = args[:view] || fail("You need to supply :view adapter")
10
10
  fs = args[:fs] || fail("You need to supply :fs adapter")
11
- since = args[:since] || 'today'
11
+ since = Internal::Dates.from(args[:since])
12
12
 
13
13
  log.call args
14
14
 
@@ -16,24 +16,22 @@ module Idonethis::UseCases
16
16
 
17
17
  dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")
18
18
 
19
- dirs = dir
20
-
21
- if dir == FileUtils.pwd
22
- view.call "Scanning the current directory <#{dir}>\n\n"
23
- else
24
- dirs = fs.modified_today?(dir).select{|dir| git.repo?(dir) }
25
-
26
- view.call "Scanning dir <#{dir}>, which has <#{dirs.size}> repositories that have changed\n\n"
27
- end
19
+ dirs = fs.modified({since: since, dir: dir, log: log}).select{|dir| git.repo?(dir) }
20
+
21
+ view.call "Scanning dir <#{dir}>, which has <#{dirs.size}> repositories that have changed since <#{since}>\n\n"
28
22
 
29
- view.call summarise(git, view, since, *dirs)
23
+ view.call summarise(git, view, since, log, *dirs)
30
24
  view.call ""
31
25
  end
32
26
 
33
- def summarise(git, view, since, *dirs)
27
+ def summarise(git, view, since, log, *dirs)
34
28
  dirs.map do |dir|
35
- commits = git.commits(dir, since).map{|it| %Q{[#{date_from(it)}] (#{it.author.name}) #{it.message}}}
36
- %Q{#{Pathname.new(dir).basename} (#{commits.size}):\n\n-- #{commits.join("\n-- ")}}
29
+ begin
30
+ commits = git.commits({dir: dir, since: since, log: log}).map{|it| %Q{[#{date_from(it)}] (#{it.author.name}) #{it.message}}}
31
+ %Q{#{Pathname.new(dir).basename} (#{commits.size}):\n\n-- #{commits.join("\n-- ")}}
32
+ rescue Exception => e
33
+ "An error occured trying to query git repo at <#{dir}>"
34
+ end
37
35
  end.join "\n\n"
38
36
  end
39
37
 
@@ -47,4 +45,29 @@ module Idonethis::UseCases
47
45
  end
48
46
  end
49
47
  end
48
+
49
+ module Internal
50
+ module Dates
51
+ class << self
52
+ def from(text)
53
+ case text
54
+ when nil
55
+ Date.today
56
+ when 'yesterday'
57
+ (Date.today - 1)
58
+ when 'today'
59
+ Date.today
60
+ when 'one-week-ago'
61
+ (Date.today - 7)
62
+ else
63
+ begin
64
+ Date.parse(text)
65
+ rescue
66
+ Date.today
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
50
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idonethis-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Biddington
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-02 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler