idonethis-cli 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adapters/git_adapter.rb +18 -10
- data/lib/adapters/io/directory_info.rb +22 -9
- data/lib/idonethis/cli/version.rb +1 -1
- data/lib/idonethis/use_cases/git.rb +37 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52ddf0a1aa33911dadfdd46c60f4367c3a4f65b5
|
4
|
+
data.tar.gz: e41021117c04ff81be509a3cd7a59f2ef1e8d5d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e5fca05c75c7b6f4cfc566093aa836d935cf004e282f32896d68e7f52cc2f5a2ab097762e2d408a8106b38537a3a2b347dde9b6ae77a62807591cef5f412d5
|
7
|
+
data.tar.gz: 7c780b5eb405768d7c958d41a141652dbbe28504f00a7e66a30f0fdb1d41bec3479ad57b8b34eca5fa07a05f85c3fced5ab0272d768a5da92910e9e210a542e1
|
data/lib/adapters/git_adapter.rb
CHANGED
@@ -1,24 +1,32 @@
|
|
1
1
|
module Idonethis::Adapters
|
2
2
|
module Git
|
3
3
|
class << self
|
4
|
-
def commits(
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
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
|
-
|
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,
|
15
|
+
def any_file_inside_changed?(dir, since, log)
|
16
16
|
Dir["#{dir}/**/**"].each do |file|
|
17
|
-
|
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
|
23
|
-
|
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
|
@@ -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]
|
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
|
-
|
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
|
-
|
36
|
-
|
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.
|
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
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|