hotspots 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ v1.1.0
2
+ ------
3
+
4
+ * Cleanup some of the internals. All compatibility layers exist in a separate file. Remove dependency on deprecated class.
5
+ * Defer to ruby for interpreting line endings
6
+
1
7
  v1.0.0
2
8
  ------
3
9
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) <2011> <Chirantan Mitra>
1
+ Copyright (c) 2011-2013 Chirantan Mitra
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://secure.travis-ci.org/chiku/hotspots.png?branch=master)](https://travis-ci.org/chiku/hotspots)
2
+ [![Code Climate](https://codeclimate.com/github/chiku/hotspots.png)](https://codeclimate.com/github/chiku/hotspots)
2
3
 
3
4
  Overview
4
5
  --------
data/TODO.md CHANGED
@@ -1,2 +1,5 @@
1
1
  * Allow better use as a library - add documentation
2
+ * Use builtin logger instead of a custom one
2
3
  * Reduce conditionals
4
+ * Split responsibilities of OptionsParser. It shouldn't be responsible for holding default options. It should just setting overrides.
5
+ * Group files based on their extensions
@@ -4,4 +4,4 @@ require 'hotspots'
4
4
 
5
5
  options = Hotspots::OptionsParser.new.parse(*ARGV)
6
6
 
7
- Hotspots::Main.new(options).output
7
+ Hotspots.new(options).output
@@ -3,81 +3,80 @@ require 'hotspots/logger'
3
3
  require 'hotspots/store'
4
4
  require 'hotspots/options_parser'
5
5
  require 'hotspots/repository'
6
+ require 'hotspots/compatibility'
6
7
 
7
- module Hotspots
8
- class Main
9
- attr_reader :logger, :repository, :verbose, :colour,
10
- :exit_strategy, :driver, :parser, :store,
11
- :time, :message_filters, :file_filter, :cutoff
8
+ class Hotspots
9
+ attr_reader :logger, :repository, :verbose, :colour,
10
+ :exit_strategy, :driver, :parser, :store,
11
+ :time, :message_filters, :file_filter, :cutoff
12
12
 
13
- def initialize(opts)
14
- options = Hotspots::OptionsParser.default_options.merge(opts)
13
+ def initialize(opts)
14
+ options = Hotspots::OptionsParser.default_options.merge(opts)
15
15
 
16
- @logger = Hotspots::Logger.new
17
- @repository = options[:repository]
18
- @verbose = options[:verbose]
19
- @colour = options[:colour]
20
- @exit_strategy = options[:exit_strategy]
16
+ @logger = Hotspots::Logger.new
17
+ @repository = options[:repository]
18
+ @verbose = options[:verbose]
19
+ @colour = options[:colour]
20
+ @exit_strategy = options[:exit_strategy]
21
21
 
22
- @time = options[:time]
23
- @message_filters = options[:message_filters]
24
- @file_filter = options[:file_filter]
25
- @cutoff = options[:cutoff]
26
- end
22
+ @time = options[:time]
23
+ @message_filters = options[:message_filters]
24
+ @file_filter = options[:file_filter]
25
+ @cutoff = options[:cutoff]
26
+ end
27
27
 
28
- def output
29
- validate
30
- set
31
- run
32
- end
28
+ def output
29
+ validate
30
+ set
31
+ run
32
+ end
33
33
 
34
- private
34
+ private
35
35
 
36
- def validate #:nodoc:
37
- exit_if_options_are_for_help
38
- exit_if_not_git_repository
39
- end
36
+ def validate #:nodoc:
37
+ exit_if_options_are_for_help
38
+ exit_if_not_git_repository
39
+ end
40
40
 
41
- def set #:nodoc:
42
- configure_logger
43
- set_path
44
- assign
45
- end
41
+ def set #:nodoc:
42
+ configure_logger
43
+ set_path
44
+ assign
45
+ end
46
46
 
47
- def run #:nodoc:
48
- puts store.to_s
49
- end
47
+ def run #:nodoc:
48
+ puts store.to_s
49
+ end
50
50
 
51
- def exit_if_options_are_for_help
52
- exit_strategy.perform
53
- end
51
+ def exit_if_options_are_for_help
52
+ exit_strategy.perform
53
+ end
54
54
 
55
- def exit_if_not_git_repository
56
- output = `git status 2>&1`
57
- unless $? == 0
58
- puts "'#{repository}' doesn't seem to be a git repository!"
59
- exit 10
60
- end
55
+ def exit_if_not_git_repository
56
+ output = `git status 2>&1`
57
+ unless $? == 0
58
+ puts "'#{repository}' doesn't seem to be a git repository!"
59
+ exit 10
61
60
  end
61
+ end
62
62
 
63
- def configure_logger
64
- if verbose
65
- logger.as_console
66
- end
67
-
68
- if colour
69
- logger.colourize
70
- end
63
+ def configure_logger
64
+ if verbose
65
+ logger.as_console
71
66
  end
72
67
 
73
- def set_path
74
- Dir.chdir(repository)
68
+ if colour
69
+ logger.colourize
75
70
  end
71
+ end
76
72
 
77
- def assign
78
- @driver = Hotspots::Repository::Driver::Git.new logger
79
- @parser = Hotspots::Repository::Parser::Git.new driver, :time => time, :message_filters => message_filters
80
- @store = Hotspots::Store.new parser.files, :cutoff => cutoff, :file_filter => file_filter
81
- end
73
+ def set_path
74
+ Dir.chdir(repository)
75
+ end
76
+
77
+ def assign
78
+ @driver = Hotspots::Repository::Driver::Git.new logger
79
+ @parser = Hotspots::Repository::Parser::Git.new driver, :time => time, :message_filters => message_filters
80
+ @store = Hotspots::Store.new parser.files, :cutoff => cutoff, :file_filter => file_filter
82
81
  end
83
82
  end
@@ -0,0 +1,4 @@
1
+ # Provides compatibility with older API
2
+ # These compatibility layers will be removed in the next major release (v2.0)
3
+
4
+ Hotspots::Main = Hotspots
@@ -1,5 +1,5 @@
1
- module Hotspots
2
- # Should understand log levels
1
+ class Hotspots
2
+ # TODO : Should understand log levels
3
3
  class Logger #:nodoc: all
4
4
  module Sink
5
5
  class Console
@@ -1,4 +1,4 @@
1
- module Hotspots
1
+ class Hotspots
2
2
  module OptionBasedExit #:nodoc: all
3
3
  class Error
4
4
  attr_reader :code, :message
@@ -3,7 +3,7 @@ require 'optparse'
3
3
  require 'hotspots/version'
4
4
  require 'hotspots/option_based_exit'
5
5
 
6
- module Hotspots
6
+ class Hotspots
7
7
  class OptionsParser #:nodoc: all
8
8
  class << self
9
9
  def default_options
@@ -60,7 +60,7 @@ module Hotspots
60
60
  opts.banner = "Tool to find most modified files over the past few days in a git repository."
61
61
 
62
62
  opts.separator "Version #{::Hotspots::VERSION}"
63
- opts.separator "Copyright (C) 2011-2012 Chirantan Mitra"
63
+ opts.separator "Copyright (C) 2011-2013 Chirantan Mitra"
64
64
  opts.separator ""
65
65
  opts.separator "Usage: ruby hotspots [options]"
66
66
  opts.separator ""
@@ -1,4 +1,4 @@
1
- module Hotspots
1
+ class Hotspots
2
2
  module Repository #:nodoc: all
3
3
  module Command
4
4
  module Git
@@ -1,4 +1,4 @@
1
- module Hotspots
1
+ class Hotspots
2
2
  module Repository #:nodoc: all
3
3
  module Driver
4
4
  class Git
@@ -1,4 +1,4 @@
1
- module Hotspots
1
+ class Hotspots
2
2
  module Repository #:nodoc: all
3
3
  module Parser
4
4
  class Git
@@ -10,24 +10,16 @@ module Hotspots
10
10
  @message_filters = options[:message_filters]
11
11
  end
12
12
 
13
- # TODO : replace with each_line
14
13
  def files
15
- filtered_commit_hashes.map do |commit_hash|
16
- driver.show_one_line_names(:commit_hash => commit_hash).
17
- gsub("\r\n", "\n").
18
- gsub("\r", "\n").
19
- split("\n")[1..-1]
20
- end.flatten
14
+ filtered_commit_hashes.reduce([]) do |acc, commit_hash|
15
+ acc + driver.show_one_line_names(:commit_hash => commit_hash).lines.map(&:strip)[1..-1]
16
+ end
21
17
  end
22
18
 
23
- # TODO : replace with each_line
24
19
  def filtered_commit_hashes
25
- message_filters.map do |filter|
26
- driver.pretty_log(:since_days => time, :message_filter => filter).
27
- gsub("\r\n", "\n").
28
- gsub("\r", "\n").
29
- split("\n")
30
- end.flatten.uniq
20
+ message_filters.reduce([]) do |acc, filter|
21
+ acc + driver.pretty_log(:since_days => time, :message_filter => filter).lines.map(&:strip)
22
+ end.uniq
31
23
  end
32
24
  end
33
25
  end
@@ -1,4 +1,4 @@
1
- module Hotspots
1
+ class Hotspots
2
2
  class Store #:nodoc: all
3
3
  def initialize(lines, options = {})
4
4
  @lines = lines
@@ -1,3 +1,3 @@
1
- module Hotspots
2
- VERSION = "1.0.0"
1
+ class Hotspots
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'minitest_helper')
2
2
 
3
- module Hotspots
3
+ class Hotspots
4
4
  describe "OptionsParser" do
5
5
  before do
6
6
  @parser = OptionsParser.new
@@ -41,20 +41,11 @@ module Hotspots::Repository
41
41
  git_parser.files.must_equal(["file1", "file2", "file2", "file3", "file5", "file4"])
42
42
  end
43
43
 
44
- describe "handles line ending" do
45
- it "of type \r\n" do
46
- options = {:time => 10, :message_filters => ["Foo", "Bar"]}
47
- git_parser = Parser::Git.new StubGitDriver.new(:line_ending => "\r\n"), options
48
-
49
- git_parser.files.must_equal(["file1", "file2", "file2", "file3", "file5", "file4"])
50
- end
51
-
52
- it "of type \r" do
53
- options = {:time => 10, :message_filters => ["Foo", "Bar"]}
54
- git_parser = Parser::Git.new StubGitDriver.new(:line_ending => "\r"), options
44
+ it "handles line ending" do
45
+ options = {:time => 10, :message_filters => ["Foo", "Bar"]}
46
+ git_parser = Parser::Git.new StubGitDriver.new, options
55
47
 
56
- git_parser.files.must_equal(["file1", "file2", "file2", "file3", "file5", "file4"])
57
- end
48
+ git_parser.files.must_equal(["file1", "file2", "file2", "file3", "file5", "file4"])
58
49
  end
59
50
  end
60
51
 
@@ -68,14 +59,12 @@ module Hotspots::Repository
68
59
  it "has a sane show one line names" do
69
60
  StubGitDriver.new.show_one_line_names(:commit_hash => "SHA2").
70
61
  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
62
  end
74
63
  end
75
64
 
76
65
  class StubGitDriver
77
- def initialize(options = {})
78
- line_ending = options[:line_ending] || "\n"
66
+ def initialize
67
+ line_ending = "\n"
79
68
  @pretty_log_enum = ["SHA1#{line_ending}SHA2", "SHA2#{line_ending}SHA3"].cycle
80
69
  @commits = {
81
70
  "SHA1" => "SHA1 commit message#{line_ending}file1#{line_ending}file2",
@@ -1,6 +1,6 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'minitest_helper')
2
2
 
3
- module Hotspots
3
+ class Hotspots
4
4
  describe "Store" do
5
5
  it "counts occurances of a line present once" do
6
6
  lines = [
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: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi
@@ -91,25 +91,26 @@ executables:
91
91
  extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
- - lib/hotspots/logger.rb
95
- - lib/hotspots/option_based_exit.rb
96
94
  - lib/hotspots/options_parser.rb
95
+ - lib/hotspots/version.rb
96
+ - lib/hotspots/option_based_exit.rb
97
+ - lib/hotspots/logger.rb
98
+ - lib/hotspots/repository.rb
97
99
  - lib/hotspots/repository/command/git.rb
98
- - lib/hotspots/repository/command.rb
99
100
  - lib/hotspots/repository/driver/git.rb
100
101
  - lib/hotspots/repository/driver.rb
101
- - lib/hotspots/repository/parser/git.rb
102
+ - lib/hotspots/repository/command.rb
102
103
  - lib/hotspots/repository/parser.rb
103
- - lib/hotspots/repository.rb
104
+ - lib/hotspots/repository/parser/git.rb
104
105
  - lib/hotspots/store.rb
105
- - lib/hotspots/version.rb
106
+ - lib/hotspots/compatibility.rb
106
107
  - lib/hotspots.rb
107
108
  - bin/hotspots
108
- - test/hotspots/options_parser_test.rb
109
+ - test/minitest_helper.rb
109
110
  - test/hotspots/repository/command/git_test.rb
110
111
  - test/hotspots/repository/parser/git_test.rb
111
112
  - test/hotspots/store_test.rb
112
- - test/minitest_helper.rb
113
+ - test/hotspots/options_parser_test.rb
113
114
  - LICENSE
114
115
  - README.md
115
116
  - CHANGELOG.md
@@ -126,27 +127,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
127
  - - ! '>='
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
- segments:
130
- - 0
131
- hash: 684827185202909371
132
130
  required_rubygems_version: !ruby/object:Gem::Requirement
133
131
  none: false
134
132
  requirements:
135
133
  - - ! '>='
136
134
  - !ruby/object:Gem::Version
137
135
  version: '0'
138
- segments:
139
- - 0
140
- hash: 684827185202909371
141
136
  requirements: []
142
137
  rubyforge_project: hotspots
143
- rubygems_version: 1.8.24
138
+ rubygems_version: 1.8.25
144
139
  signing_key:
145
140
  specification_version: 3
146
141
  summary: Find all files that changed over the past in a git repository based on conditions
147
142
  test_files:
148
- - test/hotspots/options_parser_test.rb
143
+ - test/minitest_helper.rb
149
144
  - test/hotspots/repository/command/git_test.rb
150
145
  - test/hotspots/repository/parser/git_test.rb
151
146
  - test/hotspots/store_test.rb
152
- - test/minitest_helper.rb
147
+ - test/hotspots/options_parser_test.rb