hotspots 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +5 -0
- data/hotspots.gemspec +1 -0
- data/lib/hotspots.rb +9 -14
- data/lib/hotspots/exit_strategy.rb +41 -0
- data/lib/hotspots/options_parser.rb +4 -3
- data/lib/hotspots/repository/driver/git.rb +8 -8
- data/lib/hotspots/repository/parser/git.rb +8 -8
- data/lib/hotspots/store.rb +5 -5
- data/lib/hotspots/version.rb +1 -1
- data/test/hotspots/options_parser_test.rb +9 -8
- data/test/hotspots/repository/parser/git_test.rb +5 -5
- data/test/hotspots/store_test.rb +1 -1
- metadata +16 -4
data/CHANGELOG.markdown
CHANGED
data/hotspots.gemspec
CHANGED
data/lib/hotspots.rb
CHANGED
@@ -7,16 +7,14 @@ require 'hotspots/repository'
|
|
7
7
|
module Hotspots
|
8
8
|
class Main
|
9
9
|
attr_reader :logger, :options, :repository, :verbose,
|
10
|
-
:
|
11
|
-
:driver, :parser, :store
|
10
|
+
:exit_strategy, :driver, :parser, :store
|
12
11
|
|
13
12
|
def initialize
|
14
|
-
@options
|
15
|
-
@repository
|
16
|
-
@verbose
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@logger = Hotspots::Logger.new
|
13
|
+
@options = Hotspots::OptionsParser.new.parse(*ARGV)
|
14
|
+
@repository = options[:repository]
|
15
|
+
@verbose = options[:verbose]
|
16
|
+
@exit_strategy = options[:exit_strategy]
|
17
|
+
@logger = Hotspots::Logger.new
|
20
18
|
end
|
21
19
|
|
22
20
|
def execute!
|
@@ -26,7 +24,7 @@ module Hotspots
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def validate!
|
29
|
-
|
27
|
+
validate_early_exit!
|
30
28
|
validate_git_repository!
|
31
29
|
end
|
32
30
|
|
@@ -42,11 +40,8 @@ module Hotspots
|
|
42
40
|
|
43
41
|
private
|
44
42
|
|
45
|
-
def
|
46
|
-
|
47
|
-
puts exit_message
|
48
|
-
exit exit_code
|
49
|
-
end
|
43
|
+
def validate_early_exit!
|
44
|
+
exit_strategy.perform
|
50
45
|
end
|
51
46
|
|
52
47
|
def validate_git_repository!
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hotspots
|
2
|
+
class ExitStrategy
|
3
|
+
attr_reader :code, :message
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@message = options[:message]
|
7
|
+
@code = options[:code]
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform
|
11
|
+
puts @message
|
12
|
+
exit @code
|
13
|
+
end
|
14
|
+
|
15
|
+
class Safe
|
16
|
+
attr_reader :code, :message
|
17
|
+
|
18
|
+
def initialize(options)
|
19
|
+
@message = options[:message]
|
20
|
+
@code = 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform
|
24
|
+
puts @message
|
25
|
+
exit @code
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Null
|
30
|
+
attr_reader :code, :message
|
31
|
+
|
32
|
+
def initialize(options = {})
|
33
|
+
@message = ""
|
34
|
+
@code = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def perform
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
3
|
require 'hotspots/version'
|
4
|
+
require 'hotspots/exit_strategy'
|
4
5
|
|
5
6
|
module Hotspots
|
6
7
|
class OptionsParser
|
@@ -12,7 +13,7 @@ module Hotspots
|
|
12
13
|
:message_filters => [""],
|
13
14
|
:cutoff => 0,
|
14
15
|
:verbose => false,
|
15
|
-
:
|
16
|
+
:exit_strategy => ExitStrategy::Null.new
|
16
17
|
}
|
17
18
|
end
|
18
19
|
|
@@ -21,7 +22,7 @@ module Hotspots
|
|
21
22
|
begin
|
22
23
|
parser.parse args
|
23
24
|
rescue ::OptionParser::InvalidOption, ::OptionParser::InvalidArgument => ex
|
24
|
-
@options[:
|
25
|
+
@options[:exit_strategy] = ExitStrategy.new(:code => 1, :message => (ex.to_s << "\nUse -h for help\n"))
|
25
26
|
end
|
26
27
|
@options
|
27
28
|
end
|
@@ -105,7 +106,7 @@ module Hotspots
|
|
105
106
|
def handle_help_on(opts)
|
106
107
|
opts.on_tail("-h", "--help",
|
107
108
|
"Show this message") do
|
108
|
-
@options[:
|
109
|
+
@options[:exit_strategy] = ExitStrategy::Safe.new(:message => opts.to_s)
|
109
110
|
end
|
110
111
|
end
|
111
112
|
end
|
@@ -10,17 +10,17 @@ module Hotspots
|
|
10
10
|
|
11
11
|
def pretty_log(options)
|
12
12
|
grep_clause = options[:message_filter].empty? ? "" : " --grep \"#{options[:message_filter]}\""
|
13
|
-
command = %Q(git log --pretty="%H" --since #{options[:since_days]}.days.ago#{grep_clause})
|
14
|
-
|
15
|
-
%x(#{command})
|
16
|
-
|
13
|
+
command = %Q(git log --pretty="%H" --since #{options[:since_days]}.days.ago#{grep_clause}).
|
14
|
+
tap {|raw| logger.log "<Input> #{raw}"}
|
15
|
+
%x(#{command}).
|
16
|
+
tap {|raw| logger.log raw}
|
17
17
|
end
|
18
18
|
|
19
19
|
def show_one_line_names(options)
|
20
|
-
command = %Q(git show --oneline --name-only #{options[:commit_hash]})
|
21
|
-
|
22
|
-
%x(#{command})
|
23
|
-
|
20
|
+
command = %Q(git show --oneline --name-only #{options[:commit_hash]}).
|
21
|
+
tap {|raw| logger.log "<Input> #{raw}"}
|
22
|
+
%x(#{command}).
|
23
|
+
tap {|raw| logger.log "<Output> #{raw}"}
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -10,19 +10,19 @@ module Hotspots
|
|
10
10
|
|
11
11
|
def files
|
12
12
|
filtered_commit_hashes.map do |commit_hash|
|
13
|
-
@driver.show_one_line_names(:commit_hash => commit_hash)
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
@driver.show_one_line_names(:commit_hash => commit_hash).
|
14
|
+
gsub("\r\n", "\n").
|
15
|
+
gsub("\r", "\n").
|
16
|
+
split("\n")[1..-1]
|
17
17
|
end.flatten
|
18
18
|
end
|
19
19
|
|
20
20
|
def filtered_commit_hashes
|
21
21
|
@message_filters.map do |filter|
|
22
|
-
@driver.pretty_log(:since_days => @time, :message_filter => filter)
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
@driver.pretty_log(:since_days => @time, :message_filter => filter).
|
23
|
+
gsub("\r\n", "\n").
|
24
|
+
gsub("\r", "\n").
|
25
|
+
split("\n")
|
26
26
|
end.flatten.uniq
|
27
27
|
end
|
28
28
|
end
|
data/lib/hotspots/store.rb
CHANGED
@@ -6,9 +6,9 @@ module Hotspots
|
|
6
6
|
@cutoff = options[:cutoff] || 0
|
7
7
|
@filter = options[:file_filter] || ""
|
8
8
|
|
9
|
-
@lines.map { |line| line.strip }
|
10
|
-
|
11
|
-
|
9
|
+
@lines.map { |line| line.strip }.
|
10
|
+
select{ |line| not line.empty? and line =~ Regexp.new(@filter) }.
|
11
|
+
each { |line| @store[line] += 1 }
|
12
12
|
end
|
13
13
|
|
14
14
|
def on(line)
|
@@ -16,8 +16,8 @@ module Hotspots
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_s
|
19
|
-
sorted_array.select { |key, value| value >= @cutoff }
|
20
|
-
|
19
|
+
sorted_array.select { |key, value| value >= @cutoff }.
|
20
|
+
reduce("") { |acc, (key, value)| acc << "#{key},#{value}\n" }
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
data/lib/hotspots/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'lib', 'hotspots', 'options_parser')
|
2
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'lib', 'hotspots', 'exit_strategy')
|
2
3
|
|
3
4
|
module Hotspots
|
4
5
|
describe "OptionsParser" do
|
@@ -32,11 +33,11 @@ module Hotspots
|
|
32
33
|
end
|
33
34
|
|
34
35
|
it "exit code to nil" do
|
35
|
-
@parser.parse[:
|
36
|
+
@parser.parse[:exit_strategy].code.must_equal nil
|
36
37
|
end
|
37
38
|
|
38
39
|
it "exit message to empty string" do
|
39
|
-
@parser.parse[:
|
40
|
+
@parser.parse[:exit_strategy].message.must_equal ""
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -111,11 +112,11 @@ module Hotspots
|
|
111
112
|
["--help", "-h"].each do |option|
|
112
113
|
describe option do
|
113
114
|
it "sets exit code to zero" do
|
114
|
-
@parser.parse(option)[:
|
115
|
+
@parser.parse(option)[:exit_strategy].code.must_equal 0
|
115
116
|
end
|
116
117
|
|
117
118
|
it "sets an exit message" do
|
118
|
-
@parser.parse(option)[:
|
119
|
+
@parser.parse(option)[:exit_strategy].message.wont_be_empty
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
@@ -126,11 +127,11 @@ module Hotspots
|
|
126
127
|
end
|
127
128
|
|
128
129
|
it "sets an exit code" do
|
129
|
-
@options[:
|
130
|
+
@options[:exit_strategy].code.must_equal 1
|
130
131
|
end
|
131
132
|
|
132
133
|
it "sets an exit message" do
|
133
|
-
@options[:
|
134
|
+
@options[:exit_strategy].message.wont_be_empty
|
134
135
|
end
|
135
136
|
end
|
136
137
|
|
@@ -140,11 +141,11 @@ module Hotspots
|
|
140
141
|
end
|
141
142
|
|
142
143
|
it "sets an exit code" do
|
143
|
-
@options[:
|
144
|
+
@options[:exit_strategy].code.must_equal 1
|
144
145
|
end
|
145
146
|
|
146
147
|
it "sets an exit message" do
|
147
|
-
@options[:
|
148
|
+
@options[:exit_strategy].message.wont_be_empty
|
148
149
|
end
|
149
150
|
end
|
150
151
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', '..', 'lib', 'hotspots', 'repository', 'parser', 'git')
|
2
2
|
|
3
3
|
module Hotspots::Repository
|
4
|
-
describe "Parser::Git
|
4
|
+
describe "Parser::Git" do
|
5
5
|
it "fetches a commit hash based on filter and time" do
|
6
6
|
mock_git_driver = MiniTest::Mock.new
|
7
7
|
options = {:time => 10, :message_filters => ["Foo"]}
|
@@ -66,10 +66,10 @@ module Hotspots::Repository
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "has a sane show one line names" do
|
69
|
-
StubGitDriver.new.show_one_line_names(:commit_hash => "SHA2")
|
70
|
-
|
71
|
-
StubGitDriver.new(:line_ending => "\r\n").show_one_line_names(:commit_hash => "SHA2")
|
72
|
-
|
69
|
+
StubGitDriver.new.show_one_line_names(:commit_hash => "SHA2").
|
70
|
+
must_equal "SHA1 commit message\nfile2\nfile3\nfile5"
|
71
|
+
StubGitDriver.new(:line_ending => "\r\n").show_one_line_names(:commit_hash => "SHA2").
|
72
|
+
must_equal "SHA1 commit message\r\nfile2\r\nfile3\r\nfile5"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
data/test/hotspots/store_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotspots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: simplecov
|
16
|
-
requirement: &
|
16
|
+
requirement: &16854320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16854320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &16853500 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *16853500
|
25
36
|
description: ! 'Find all files that changed over the past days for a git repository.
|
26
37
|
If the same file is modified over
|
27
38
|
|
@@ -47,6 +58,7 @@ files:
|
|
47
58
|
- bin/hotspots
|
48
59
|
- hotspots.gemspec
|
49
60
|
- lib/hotspots.rb
|
61
|
+
- lib/hotspots/exit_strategy.rb
|
50
62
|
- lib/hotspots/logger.rb
|
51
63
|
- lib/hotspots/options_parser.rb
|
52
64
|
- lib/hotspots/repository.rb
|