git_statistics 0.5.0 → 0.5.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.
Files changed (40) hide show
  1. data/bin/git-statistics +5 -0
  2. data/lib/git_statistics/collector.rb +3 -3
  3. data/lib/git_statistics/commit_line_extractor.rb +16 -30
  4. data/lib/git_statistics/core_ext/string.rb +11 -0
  5. data/lib/git_statistics/formatters/console.rb +95 -0
  6. data/lib/git_statistics/initialize.rb +5 -8
  7. data/lib/git_statistics/regex_matcher.rb +23 -0
  8. data/lib/git_statistics/utilities.rb +1 -1
  9. data/lib/git_statistics/version.rb +1 -1
  10. data/lib/git_statistics.rb +1 -1
  11. data/spec/collector_spec.rb +2 -2
  12. data/spec/commits_spec.rb +1 -1
  13. data/spec/{results_spec.rb → formatters/console_spec.rb} +4 -3
  14. data/spec/regex_matcher_spec.rb +35 -0
  15. data/spec/utilities_spec.rb +6 -3
  16. metadata +13 -43
  17. data/.gitignore +0 -24
  18. data/.travis.yml +0 -14
  19. data/CHANGELOG.md +0 -9
  20. data/Gemfile +0 -23
  21. data/Gemfile.lock +0 -67
  22. data/Guardfile +0 -7
  23. data/LICENSE +0 -19
  24. data/README.md +0 -44
  25. data/Rakefile +0 -14
  26. data/git_statistics.gemspec +0 -23
  27. data/lib/git_statistics/results.rb +0 -94
  28. data/spec/fixtures/commit_buffer_changes.txt +0 -9
  29. data/spec/fixtures/commit_buffer_information.txt +0 -1
  30. data/spec/fixtures/commit_buffer_information_first.txt +0 -1
  31. data/spec/fixtures/commit_buffer_information_with_merge.txt +0 -1
  32. data/spec/fixtures/commit_buffer_whole.txt +0 -6
  33. data/spec/fixtures/git_many_branches.txt +0 -2
  34. data/spec/fixtures/git_zero_branches.txt +0 -1
  35. data/spec/fixtures/header_output.txt +0 -4
  36. data/spec/fixtures/language_data_output.txt +0 -2
  37. data/spec/fixtures/multiple_authors.json +0 -1
  38. data/spec/fixtures/single_author_pretty.json +0 -79
  39. data/spec/fixtures/summary_output.txt +0 -17
  40. data/spec/spec_helper.rb +0 -17
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'git_statistics'
4
+
5
+ GitStatistics::GitStatistics.new(ARGV).execute
@@ -31,7 +31,7 @@ module GitStatistics
31
31
  buffer = []
32
32
  pipe.each do |line|
33
33
 
34
- line = Utilities.clean_string(line)
34
+ line = line.clean_for_authors
35
35
 
36
36
  # Extract the buffer (commit) when we match ','x5 in the log format (delimeter)
37
37
  if line.split(',').size == 5
@@ -61,7 +61,7 @@ module GitStatistics
61
61
  " --no-color --find-copies-harder --numstat --encoding=utf-8 "\
62
62
  "--summary --format=\"%H,%an,%ae,%ad,%p\"")
63
63
 
64
- buffer = pipe.map { |line| Utilities.clean_string(line) }
64
+ buffer = pipe.map { |line| line.clean_for_authors }
65
65
 
66
66
  # Check that the buffer has valid information (i.e., sha was valid)
67
67
  if !buffer.empty? && buffer.first.split(',').first == sha
@@ -78,7 +78,7 @@ module GitStatistics
78
78
 
79
79
  # Remove the '*' leading the current branch
80
80
  line = line[1..-1] if line[0] == '*'
81
- branches << Utilities.clean_string(line)
81
+ branches << line.clean_for_authors
82
82
  end
83
83
 
84
84
  return branches
@@ -1,10 +1,10 @@
1
1
  module GitStatistics
2
2
  class CommitLineExtractor
3
3
 
4
- RENAMED_OR_COPIED = /^(rename|copy)\s+(.+)\s+=>\s+(.+)\s+\((\d+)/i
5
- CREATED_OR_DELETED = /^(create|delete) mode \d+ ([^\\\n]*)/i
6
- MODIFIED_OR_RENAMED = /^([-|\d]+)\s+([-|\d]+)\s+(.+)\s+=>\s+(.+)/i
7
- ADDITIONS_OR_DELETIONS = /^([-|\d]+)\s+([-|\d]+)\s+(.+)/i
4
+ AdditionsOrDeletions = RegexMatcher.new(/^([-|\d]+)\s+([-|\d]+)\s+(.+)/i, 3)
5
+ RenamedOrCopied = RegexMatcher.new(/^(rename|copy)\s+(.+)\s+=>\s+(.+)\s+\((\d+)/i, 4)
6
+ CreatedOrDeleted = RegexMatcher.new(/^(create|delete) mode \d+ ([^\\\n]*)/i, 2)
7
+ ModifiedOrRenamed = RegexMatcher.new(/^([-|\d]+)\s+([-|\d]+)\s+(.+)\s+=>\s+(.+)/i, 4)
8
8
 
9
9
  attr_reader :line
10
10
 
@@ -13,52 +13,38 @@ module GitStatistics
13
13
  end
14
14
 
15
15
  def changed
16
- modified_or_renamed = line.scan(MODIFIED_OR_RENAMED).first
17
- modified_or_renamed = changes_are_right_size(modified_or_renamed, 4) do |changes|
16
+ modified_or_renamed = ModifiedOrRenamed.if_matches(line) do |changes|
18
17
  split_file = Utilities.split_old_new_file(changes[2], changes[3])
19
18
  {:additions => changes[0].to_i,
20
19
  :deletions => changes[1].to_i,
21
- :file => Utilities.clean_string(split_file[:new_file]),
22
- :old_file => Utilities.clean_string(split_file[:old_file])}
20
+ :file => split_file[:new_file].clean_for_authors,
21
+ :old_file => split_file[:old_file].clean_for_authors}
23
22
  end
24
23
  return modified_or_renamed unless modified_or_renamed.empty?
25
24
 
26
- addition_or_deletion = line.scan(ADDITIONS_OR_DELETIONS).first
27
- changes_are_right_size(addition_or_deletion, 3) do |changes|
25
+ AdditionsOrDeletions.if_matches(line) do |changes|
28
26
  {:additions => changes[0].to_i,
29
27
  :deletions => changes[1].to_i,
30
- :file => Utilities.clean_string(changes[2])}
28
+ :file => changes[2].clean_for_authors}
31
29
  end
32
30
  end
33
31
 
34
32
  def created_or_deleted
35
- changes = line.scan(CREATED_OR_DELETED).first
36
- changes_are_right_size(changes, 2) do |changes|
37
- {:status => Utilities.clean_string(changes[0]),
38
- :file => Utilities.clean_string(changes[1])}
33
+ CreatedOrDeleted.if_matches(line) do |changes|
34
+ {:status => changes[0].clean_for_authors,
35
+ :file => changes[1].clean_for_authors}
39
36
  end
40
37
  end
41
38
 
42
39
  def renamed_or_copied
43
- changes = line.scan(RENAMED_OR_COPIED).first
44
- changes_are_right_size(changes, 4) do |changes|
40
+ RenamedOrCopied.if_matches(line) do |changes|
45
41
  split_file = Utilities.split_old_new_file(changes[1], changes[2])
46
- {:status => Utilities.clean_string(changes[0]),
47
- :old_file => Utilities.clean_string(split_file[:old_file]),
48
- :new_file => Utilities.clean_string(split_file[:new_file]),
42
+ {:status => changes[0].clean_for_authors,
43
+ :old_file => split_file[:old_file].clean_for_authors,
44
+ :new_file => split_file[:new_file].clean_for_authors,
49
45
  :similar => changes[3].to_i}
50
46
  end
51
47
  end
52
48
 
53
- private
54
-
55
- def changes_are_right_size(changes, size = 4)
56
- if !changes.nil? && changes.size == size
57
- yield changes
58
- else
59
- {}
60
- end
61
- end
62
-
63
49
  end
64
50
  end
@@ -0,0 +1,11 @@
1
+ module GitStatistics
2
+ module StringExt
3
+ def clean_for_authors
4
+ self.strip.force_encoding("iso-8859-1").encode("utf-8")
5
+ end
6
+ end
7
+ end
8
+
9
+ class String
10
+ include GitStatistics::StringExt
11
+ end
@@ -0,0 +1,95 @@
1
+ module GitStatistics
2
+ module Formatters
3
+ class Console
4
+
5
+ attr_accessor :commits
6
+
7
+ def initialize(commits)
8
+ @commits = commits
9
+ end
10
+
11
+ def prepare_result_summary(sort, email, top_n = 0)
12
+ # Default to a 0 if given a negative number to display
13
+ top_n = 0 if top_n < 0
14
+
15
+ # Acquire data based on sort type and top # to show
16
+ data = @commits.author_top_n_type(sort.to_sym, top_n)
17
+ raise "Parameter for --sort is not valid" if data.nil?
18
+
19
+ # Create config
20
+ config = {:data => data,
21
+ :author_length => Utilities.max_length_in_list(data.keys, 17),
22
+ :language_length => Utilities.max_length_in_list(@commits.totals[:languages].keys, 8),
23
+ :sort => sort,
24
+ :email => email,
25
+ :top_n => top_n}
26
+
27
+ # Acquire formatting pattern for output
28
+ pattern = "%-#{config[:author_length]}s | %-#{config[:language_length]}s | %7s | %9s | %9s | %7s | %7s | %7s | %6s | %6s |"
29
+ config[:pattern] = pattern
30
+ return config
31
+ end
32
+
33
+ def print_summary(sort, email, top_n = 0)
34
+ # Prepare and determine the config for the result summary based on parameters
35
+ config = prepare_result_summary(sort, email, top_n)
36
+
37
+ # Print query/header information
38
+ output = print_header(config)
39
+
40
+ # Print per author information
41
+ config[:data].each do |key,value|
42
+ output += config[:pattern] % [key, "", value[:commits], value[:additions],
43
+ value[:deletions], value[:create], value[:delete],
44
+ value[:rename], value[:copy], value[:merges]]
45
+ output += "\n"
46
+ output += print_language_data(config[:pattern], value)
47
+ end
48
+
49
+ # Reprint query/header for repository information
50
+ output += "\n"
51
+ output += print_header(config)
52
+ data = @commits.totals
53
+ output += config[:pattern] % ["Repository Totals", "", data[:commits],
54
+ data[:additions], data[:deletions], data[:create],
55
+ data[:delete], data[:rename], data[:copy], data[:merges]]
56
+ output += "\n"
57
+ output += print_language_data(config[:pattern], data)
58
+ return output
59
+ end
60
+
61
+ def print_language_data(pattern, data)
62
+ output = ""
63
+ # Print information of each language for the data
64
+ data[:languages].each do |key,value|
65
+ output += pattern % ["", key, "", value[:additions], value[:deletions],
66
+ value[:create], value[:delete], value[:rename],
67
+ value[:copy], value[:merges]]
68
+ output += "\n"
69
+ end
70
+ return output
71
+ end
72
+
73
+ def print_header(config)
74
+ total_authors = @commits.stats.size
75
+
76
+ output = ""
77
+ # Print summary information of displayed results
78
+ if config[:top_n] > 0 and config[:top_n] < total_authors
79
+ output += "Top #{config[:top_n]} authors(#{total_authors}) sorted by #{config[:sort]}\n"
80
+ else
81
+ output += "All authors(#{total_authors}) sorted by #{config[:sort]}\n"
82
+ end
83
+
84
+ # Print column headers
85
+ output += "-"*87 + "-"*config[:author_length] + "-"*config[:language_length]
86
+ output += "\n"
87
+ output += config[:pattern] % ['Name/Email', 'Language', 'Commits', 'Additions', 'Deletions', 'Creates', 'Deletes', 'Renames', 'Copies', 'Merges']
88
+ output += "\n"
89
+ output += "-"*87 + "-"*config[:author_length] + "-"*config[:language_length]
90
+ output += "\n"
91
+ return output
92
+ end
93
+ end
94
+ end
95
+ end
@@ -5,12 +5,9 @@ require 'linguist'
5
5
  require 'os'
6
6
  require 'pathname'
7
7
 
8
- # Custom Blob for Grit to enable Linguist
9
- # This must load before other modules
10
- module Grit
11
- class Blob
12
- include Linguist::BlobHelper
13
- end
14
- end
8
+ # Must be required before all other files
9
+ require 'git_statistics/core_ext/string'
10
+ require 'git_statistics/blob'
11
+ require 'git_statistics/regex_matcher'
15
12
 
16
- Dir.glob(File.dirname(__FILE__) + '/*.rb') {|file| require file}
13
+ Dir.glob(File.dirname(__FILE__) + '/**/*.rb') {|file| require file}
@@ -0,0 +1,23 @@
1
+ module GitStatistics
2
+ class RegexMatcher
3
+
4
+ attr_reader :regex, :expected_change_count
5
+ def initialize(regex, expected_change_count)
6
+ @regex = regex
7
+ @expected_change_count = expected_change_count
8
+ end
9
+
10
+ def scan(line)
11
+ line.scan(regex).first || []
12
+ end
13
+
14
+ def if_matches(line)
15
+ changes = self.scan(line)
16
+ if changes && changes.size == expected_change_count
17
+ yield changes
18
+ else
19
+ {}
20
+ end
21
+ end
22
+ end
23
+ end
@@ -100,7 +100,7 @@ module GitStatistics
100
100
  .select { |file| file =~ pattern }
101
101
  .size
102
102
  rescue SystemCallError
103
- ::Kernel.warn "No such directory #{File.expand_path(directory)}"
103
+ warn "No such directory #{File.expand_path(directory)}"
104
104
  0
105
105
  end
106
106
  end
@@ -1,3 +1,3 @@
1
1
  module GitStatistics
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -43,7 +43,7 @@ module GitStatistics
43
43
  collector.commits.calculate_statistics(@opts[:email], @opts[:merges])
44
44
 
45
45
  # Print results
46
- results = Results.new(collector.commits)
46
+ results = Formatters::Console.new(collector.commits)
47
47
  puts results.print_summary(@opts[:sort], @opts[:email], @opts[:top])
48
48
  end
49
49
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  include GitStatistics
3
3
 
4
4
  describe Collector do
@@ -11,7 +11,7 @@ describe Collector do
11
11
  # Create buffer which is an array of cleaned lines
12
12
  let(:buffer) {
13
13
  fixture(fixture_file).readlines.collect do |line|
14
- Utilities.clean_string(line)
14
+ line.clean_for_authors
15
15
  end
16
16
  }
17
17
 
data/spec/commits_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  include GitStatistics
3
3
 
4
4
  describe Commits do
@@ -1,7 +1,8 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  include GitStatistics
3
+ include GitStatistics::Formatters
3
4
 
4
- describe Results do
5
+ describe Console do
5
6
  let(:verbose) {false}
6
7
  let(:limit) {100}
7
8
  let(:fresh) {true}
@@ -21,7 +22,7 @@ describe Results do
21
22
  setup_commits(commits, fixture_file, save_file, pretty)
22
23
  commits.calculate_statistics(email, merge)
23
24
  commits.author_top_n_type(sort)
24
- results = Results.new(commits)
25
+ results = Console.new(commits)
25
26
  }
26
27
 
27
28
  let(:config) {
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ include GitStatistics
3
+
4
+ describe RegexMatcher do
5
+ let(:change_info) { RegexMatcher.new(/(match)/i, 1) }
6
+ let(:text) { 'matching string' }
7
+
8
+ describe "#scan" do
9
+ subject { change_info.scan(text) }
10
+ context "with matching string" do
11
+ its(:size) { should == 1 }
12
+ end
13
+ context "without matching string" do
14
+ let(:text) { 'does not matter' }
15
+ its(:size) { should == 0 }
16
+ end
17
+ end
18
+ describe "#if_matches" do
19
+ it "should yield the result with matching string" do
20
+ original = :original
21
+ change_info.if_matches(text) do |changes|
22
+ original = :new_value
23
+ end
24
+ original.should == :new_value
25
+ end
26
+ it "should not yield the result without a matching string" do
27
+ text = 'does not yield'
28
+ original = :original
29
+ change_info.if_matches(text) do |changes|
30
+ original = :new_value
31
+ end
32
+ original.should == :original
33
+ end
34
+ end
35
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require 'spec_helper'
2
2
  include GitStatistics
3
3
 
4
4
  describe Utilities do
@@ -54,7 +54,7 @@ describe Utilities do
54
54
 
55
55
  describe "#clean_string" do
56
56
  let(:unclean) {" master "}
57
- let(:clean) {Utilities.clean_string(unclean)}
57
+ let(:clean) {unclean.clean_for_authors}
58
58
 
59
59
  context "with trailling spaces" do
60
60
  it {clean.should == "master"}
@@ -162,7 +162,10 @@ describe Utilities do
162
162
 
163
163
  context "with missing directory" do
164
164
  subject { files }
165
- before { FileUtils.rmdir(directory) }
165
+ before do
166
+ subject.class.stub(:warn)
167
+ FileUtils.rmdir(directory)
168
+ end
166
169
  it { should == 0 }
167
170
  end
168
171
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
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: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -96,47 +96,29 @@ email:
96
96
  - kevin.j.jalbert@gmail.com
97
97
  executables:
98
98
  - git_statistics
99
+ - git-statistics
99
100
  extensions: []
100
101
  extra_rdoc_files: []
101
102
  files:
102
- - .gitignore
103
- - .travis.yml
104
- - CHANGELOG.md
105
- - Gemfile
106
- - Gemfile.lock
107
- - Guardfile
108
- - LICENSE
109
- - README.md
110
- - Rakefile
111
- - bin/git_statistics
112
- - git_statistics.gemspec
113
- - lib/git_statistics.rb
114
103
  - lib/git_statistics/blob.rb
115
104
  - lib/git_statistics/collector.rb
116
105
  - lib/git_statistics/commit_line_extractor.rb
117
106
  - lib/git_statistics/commits.rb
107
+ - lib/git_statistics/core_ext/string.rb
108
+ - lib/git_statistics/formatters/console.rb
118
109
  - lib/git_statistics/initialize.rb
119
- - lib/git_statistics/results.rb
110
+ - lib/git_statistics/regex_matcher.rb
120
111
  - lib/git_statistics/utilities.rb
121
112
  - lib/git_statistics/version.rb
113
+ - lib/git_statistics.rb
122
114
  - spec/collector_spec.rb
123
115
  - spec/commit_line_extractor_spec.rb
124
116
  - spec/commits_spec.rb
125
- - spec/fixtures/commit_buffer_changes.txt
126
- - spec/fixtures/commit_buffer_information.txt
127
- - spec/fixtures/commit_buffer_information_first.txt
128
- - spec/fixtures/commit_buffer_information_with_merge.txt
129
- - spec/fixtures/commit_buffer_whole.txt
130
- - spec/fixtures/git_many_branches.txt
131
- - spec/fixtures/git_zero_branches.txt
132
- - spec/fixtures/header_output.txt
133
- - spec/fixtures/language_data_output.txt
134
- - spec/fixtures/multiple_authors.json
135
- - spec/fixtures/single_author_pretty.json
136
- - spec/fixtures/summary_output.txt
137
- - spec/results_spec.rb
138
- - spec/spec_helper.rb
117
+ - spec/formatters/console_spec.rb
118
+ - spec/regex_matcher_spec.rb
139
119
  - spec/utilities_spec.rb
120
+ - bin/git_statistics
121
+ - bin/git-statistics
140
122
  homepage: https://github.com/kevinjalbert/git_statistics
141
123
  licenses: []
142
124
  post_install_message:
@@ -165,18 +147,6 @@ test_files:
165
147
  - spec/collector_spec.rb
166
148
  - spec/commit_line_extractor_spec.rb
167
149
  - spec/commits_spec.rb
168
- - spec/fixtures/commit_buffer_changes.txt
169
- - spec/fixtures/commit_buffer_information.txt
170
- - spec/fixtures/commit_buffer_information_first.txt
171
- - spec/fixtures/commit_buffer_information_with_merge.txt
172
- - spec/fixtures/commit_buffer_whole.txt
173
- - spec/fixtures/git_many_branches.txt
174
- - spec/fixtures/git_zero_branches.txt
175
- - spec/fixtures/header_output.txt
176
- - spec/fixtures/language_data_output.txt
177
- - spec/fixtures/multiple_authors.json
178
- - spec/fixtures/single_author_pretty.json
179
- - spec/fixtures/summary_output.txt
180
- - spec/results_spec.rb
181
- - spec/spec_helper.rb
150
+ - spec/formatters/console_spec.rb
151
+ - spec/regex_matcher_spec.rb
182
152
  - spec/utilities_spec.rb
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
-
15
- # YARD artifacts
16
- .yardoc
17
- _yardoc
18
- doc/
19
-
20
- # Mac artifacts
21
- .DS_Store
22
-
23
- # Application artifacts
24
- .git_statistics/
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 1.9.2
5
- - 1.9.3
6
-
7
- bundler_args: --without development darwin
8
-
9
- before_install:
10
- - sudo apt-get update
11
- - sudo apt-get install libicu-dev
12
-
13
- notifications:
14
- email: false
data/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- # CHANGELOG
2
-
3
- * [0.5.0 - January 16, 2013](https://github.com/kevinjalbert/git_statistics/compare/v0.4.1...v0.5.0)
4
- * [0.4.1 - October 9, 2012](https://github.com/kevinjalbert/git_statistics/compare/v0.4.0...v0.4.1)
5
- * [0.4.0 - September 25, 2012](https://github.com/kevinjalbert/git_statistics/compare/v0.3.0...v0.4.0)
6
- * [0.3.0 - September 12, 2012](https://github.com/kevinjalbert/git_statistics/compare/v0.2.0...v0.3.0)
7
- * [0.2.0 - September 6, 2012](https://github.com/kevinjalbert/git_statistics/compare/v0.1.2...v0.2.0)
8
- * [0.1.2 - April 12, 2012](https://github.com/kevinjalbert/git_statistics/compare/v0.1.1...v0.1.2)
9
- * [0.1.1 - April 12, 2012](https://github.com/kevinjalbert/git_statistics/compare/0e82e507e5b64a1140623c702015b97b1b3f7f81...v0.1.1)
data/Gemfile DELETED
@@ -1,23 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem "json"
4
- gem "trollop"
5
- gem "grit"
6
- gem "github-linguist"
7
- gem "os"
8
-
9
- group :test do
10
- gem "simplecov"
11
- gem "rspec"
12
- gem "rake"
13
- end
14
-
15
- group :development do
16
- gem "guard"
17
- gem "guard-rspec"
18
- end
19
-
20
- group :darwin do
21
- gem "rb-fsevent"
22
- gem "terminal-notifier-guard"
23
- end
data/Gemfile.lock DELETED
@@ -1,67 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- blankslate (2.1.2.4)
5
- charlock_holmes (0.6.9)
6
- diff-lcs (1.1.3)
7
- escape_utils (0.2.4)
8
- ffi (1.0.11)
9
- github-linguist (2.3.3)
10
- charlock_holmes (~> 0.6.6)
11
- escape_utils (~> 0.2.3)
12
- mime-types (~> 1.19)
13
- pygments.rb (>= 0.2.13)
14
- grit (2.5.0)
15
- diff-lcs (~> 1.1)
16
- mime-types (~> 1.15)
17
- posix-spawn (~> 0.3.6)
18
- guard (1.3.2)
19
- listen (>= 0.4.2)
20
- thor (>= 0.14.6)
21
- guard-rspec (1.2.1)
22
- guard (>= 1.1)
23
- json (1.7.5)
24
- listen (0.5.0)
25
- mime-types (1.19)
26
- multi_json (1.3.6)
27
- os (0.9.6)
28
- posix-spawn (0.3.6)
29
- pygments.rb (0.2.13)
30
- rubypython (~> 0.5.3)
31
- rake (0.9.2.2)
32
- rb-fsevent (0.9.1)
33
- rspec (2.11.0)
34
- rspec-core (~> 2.11.0)
35
- rspec-expectations (~> 2.11.0)
36
- rspec-mocks (~> 2.11.0)
37
- rspec-core (2.11.1)
38
- rspec-expectations (2.11.3)
39
- diff-lcs (~> 1.1.3)
40
- rspec-mocks (2.11.2)
41
- rubypython (0.5.3)
42
- blankslate (>= 2.1.2.3)
43
- ffi (~> 1.0.7)
44
- simplecov (0.6.4)
45
- multi_json (~> 1.0)
46
- simplecov-html (~> 0.5.3)
47
- simplecov-html (0.5.3)
48
- terminal-notifier-guard (1.5.3)
49
- thor (0.16.0)
50
- trollop (2.0)
51
-
52
- PLATFORMS
53
- ruby
54
-
55
- DEPENDENCIES
56
- github-linguist
57
- grit
58
- guard
59
- guard-rspec
60
- json
61
- os
62
- rake
63
- rb-fsevent
64
- rspec
65
- simplecov
66
- terminal-notifier-guard
67
- trollop
data/Guardfile DELETED
@@ -1,7 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
- guard :rspec, :version => 2, :notifications => false, :all_on_start => false do
4
- watch(%r{^spec/.+_spec\.rb$})
5
- watch(%r{^lib/git_statistics/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
- watch('spec/spec_helper.rb') { "spec" }
7
- end
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2012 Kevin Jalbert
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
data/README.md DELETED
@@ -1,44 +0,0 @@
1
- [![Build Status](https://secure.travis-ci.org/kevinjalbert/git_statistics.png?branch=master)](http://travis-ci.org/kevinjalbert/git_statistics)
2
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kevinjalbert/git_statistics)
3
-
4
- # Instructions
5
-
6
- ### Using the gem
7
- 1. Acquire gem (`gem install git_statistics`)
8
- 2. Run `git_statistics` in any directory that is a git repository (use -h for options)
9
-
10
- ### Working with source
11
- 1. Clone the repository
12
- 2. Install dependencies (`bundle install`)
13
- 3. Run tests `bundle exec rake`
14
- 4. Build and install local gem `bundle exec rake install`
15
-
16
- # Functions
17
-
18
- This gem will analyze every commit within a git repository using `git log` and [mojombo/grit](https://github.com/mojombo/grit). The following author statistics in relation to the git repository are collected and displayed:
19
-
20
- * Total number of commits
21
- * Total number of merge commits
22
- * Total source line additions
23
- * Total source line deletions
24
- * Total file creates
25
- * Total file deletes
26
- * Total file renames
27
- * Total file copies
28
-
29
- This gem also uses [github/linguist](https://github.com/github/linguist) to determine the language of each individual file within commits. This augments the reported statistics by breaking down the author's statistics by languages.
30
-
31
- This gem also has the ability to save the acquired data into a JSON file (in either a compressed or pretty format). If a saved file is present for the repository you can use the gem to load the data from the file, thus saving time for re-displaying the statistics using a different set of display flags (what statistic to sort on, number of authors to show, consider merges, etc...). In the event that a repository updates with new commits the gem allows you to update the saved file with the new commits.
32
-
33
- # Example Output
34
- The following is the output produced by *git_statistics* when used on the [pengwynn/octokit](https://github.com/pengwynn/octokit) (at commit [95a9de3](https://github.com/pengwynn/octokit/commit/95a9de325bee4ca03c9c1d61de2d643666c90037)) git repository. In this output we show the top three authors in rankings based on number of commits (merge commits are excluded from these results).
35
-
36
- ![screenshot](http://cloud.github.com/downloads/kevinjalbert/git_statistics/pengwynn_octokit_output.png)
37
-
38
- # Contributing
39
-
40
- 1. Fork it
41
- 2. Create your feature branch (`git checkout -b my-new-feature`)
42
- 3. Commit your changes (`git commit -am 'Added some feature'`)
43
- 4. Push to the branch (`git push origin my-new-feature`)
44
- 5. Create new Pull Request
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env rake
2
-
3
- require 'rake/clean'
4
- require 'rspec/core/rake_task'
5
- require "bundler/gem_tasks"
6
-
7
- CLOBBER.include('coverage')
8
-
9
- desc "Run all specs"
10
- RSpec::Core::RakeTask.new do |t|
11
- t.pattern = "./spec/**/*spec.rb"
12
- end
13
-
14
- task :default => :spec
@@ -1,23 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/git_statistics/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.homepage = 'https://github.com/kevinjalbert/git_statistics'
6
- gem.authors = ["Kevin Jalbert"]
7
- gem.email = ["kevin.j.jalbert@gmail.com"]
8
- gem.name = 'git_statistics'
9
- gem.version = GitStatistics::VERSION
10
- gem.summary = "Gem that provides the ability to gather detailed git statistics"
11
- gem.description = "git_statistics is a gem that provides detailed git statistics"
12
- gem.require_paths = ["lib"]
13
- gem.files = `git ls-files`.split($\)
14
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- gem.executables << 'git_statistics'
17
- gem.required_ruby_version = '>= 1.9.1'
18
- gem.add_dependency('json')
19
- gem.add_dependency('trollop')
20
- gem.add_dependency('grit')
21
- gem.add_dependency('github-linguist')
22
- gem.add_dependency('os')
23
- end
@@ -1,94 +0,0 @@
1
- module GitStatistics
2
- class Results
3
-
4
- attr_accessor :commits
5
-
6
- def initialize(commits)
7
- @commits = commits
8
- end
9
-
10
- def prepare_result_summary(sort, email, top_n = 0)
11
- # Default to a 0 if given a negative number to display
12
- top_n = 0 if top_n < 0
13
-
14
- # Acquire data based on sort type and top # to show
15
- data = @commits.author_top_n_type(sort.to_sym, top_n)
16
- raise "Parameter for --sort is not valid" if data.nil?
17
-
18
- # Create config
19
- config = {:data => data,
20
- :author_length => Utilities.max_length_in_list(data.keys, 17),
21
- :language_length => Utilities.max_length_in_list(@commits.totals[:languages].keys, 8),
22
- :sort => sort,
23
- :email => email,
24
- :top_n => top_n}
25
-
26
- # Acquire formatting pattern for output
27
- pattern = "%-#{config[:author_length]}s | %-#{config[:language_length]}s | %7s | %9s | %9s | %7s | %7s | %7s | %6s | %6s |"
28
- config[:pattern] = pattern
29
- return config
30
- end
31
-
32
- def print_summary(sort, email, top_n = 0)
33
- # Prepare and determine the config for the result summary based on parameters
34
- config = prepare_result_summary(sort, email, top_n)
35
-
36
- # Print query/header information
37
- output = print_header(config)
38
-
39
- # Print per author information
40
- config[:data].each do |key,value|
41
- output += config[:pattern] % [key, "", value[:commits], value[:additions],
42
- value[:deletions], value[:create], value[:delete],
43
- value[:rename], value[:copy], value[:merges]]
44
- output += "\n"
45
- output += print_language_data(config[:pattern], value)
46
- end
47
-
48
- # Reprint query/header for repository information
49
- output += "\n"
50
- output += print_header(config)
51
- data = @commits.totals
52
- output += config[:pattern] % ["Repository Totals", "", data[:commits],
53
- data[:additions], data[:deletions], data[:create],
54
- data[:delete], data[:rename], data[:copy], data[:merges]]
55
- output += "\n"
56
- output += print_language_data(config[:pattern], data)
57
- return output
58
- end
59
-
60
- def print_language_data(pattern, data)
61
- output = ""
62
- # Print information of each language for the data
63
- data[:languages].each do |key,value|
64
- output += pattern % ["", key, "", value[:additions], value[:deletions],
65
- value[:create], value[:delete], value[:rename],
66
- value[:copy], value[:merges]]
67
- output += "\n"
68
- end
69
- return output
70
- end
71
-
72
- def print_header(config)
73
- total_authors = @commits.stats.size
74
-
75
- output = ""
76
- # Print summary information of displayed results
77
- if config[:top_n] > 0 and config[:top_n] < total_authors
78
- output += "Top #{config[:top_n]} authors(#{total_authors}) sorted by #{config[:sort]}\n"
79
- else
80
- output += "All authors(#{total_authors}) sorted by #{config[:sort]}\n"
81
- end
82
-
83
- # Print column headers
84
- output += "-"*87 + "-"*config[:author_length] + "-"*config[:language_length]
85
- output += "\n"
86
- output += config[:pattern] % ['Name/Email', 'Language', 'Commits', 'Additions', 'Deletions', 'Creates', 'Deletes', 'Renames', 'Copies', 'Merges']
87
- output += "\n"
88
- output += "-"*87 + "-"*config[:author_length] + "-"*config[:language_length]
89
- output += "\n"
90
- return output
91
- end
92
- end
93
- end
94
-
@@ -1,9 +0,0 @@
1
- 45 1 dir/README
2
- 6 5 dir/lib/{old_dir => new_dir}/copy_file.rb
3
- 0 0 dir/lib/rename/{old_file.rb => new_file.rb}
4
- 0 127 dir/lib/delete_file.rb
5
- 60 0 dir/lib/create_file.rb
6
- copy dir/lib/{old_dir => new_dir}/copy_file.rb (65%)
7
- rename dir/lib/rename/{old_file.rb => new_file.rb} (100%)
8
- delete mode 100644 dir/lib/delete_file.rb
9
- create mode 100644 dir/lib/create_file.rb
@@ -1 +0,0 @@
1
- 111111aa111a11111a11aa11aaaa11a111111a11,Test Author,author@test.com,2011-01-11 11:11:11 +0000,22bbbb2
@@ -1 +0,0 @@
1
- 111111aa111a11111a11aa11aaaa11a111111a11,Test Author,author@test.com,2011-01-11 11:11:11 +0000,
@@ -1 +0,0 @@
1
- 111111aa111a11111a11aa11aaaa11a111111a11,Test Author,author@test.com,2011-01-11 11:11:11 +0000,22bbbb2 33cccc3
@@ -1,6 +0,0 @@
1
- 260bc61e2c42930d91f3503c5849b0a2351275cf,Kevin Jalbert,kevin.j.jalbert@gmail.com,2012-04-12 14:13:56 -0400,caf6716
2
-
3
- 0 1 Gemfile
4
- 30 0 Gemfile.lock
5
- 0 1 lib/git_statistics/initialize.rb
6
- create mode 100644 Gemfile.lock
@@ -1,2 +0,0 @@
1
- * issue_2
2
- master
@@ -1 +0,0 @@
1
- * master
@@ -1,4 +0,0 @@
1
- All authors(2) sorted by commits
2
- ----------------------------------------------------------------------------------------------------------------
3
- Name/Email | Language | Commits | Additions | Deletions | Creates | Deletes | Renames | Copies | Merges |
4
- ----------------------------------------------------------------------------------------------------------------
@@ -1,2 +0,0 @@
1
- | Markdown | | 11 | 0 | 1 | 0 | 0 | 0 | 0 |
2
- | Ruby | | 62 | 0 | 1 | 0 | 0 | 0 | 0 |
@@ -1 +0,0 @@
1
- {"0e82e507e5b64a1140623c702015b97b1b3f7f81":{"author":"Kevin Jalbert","author_email":"kevin.j.jalbert@gmail.com","time":"2012-04-04 13:46:56 -0400","files":[{"name":"README.md","additions":11,"deletions":0,"status":"create","binary":false,"image":false,"vendored":false,"generated":false,"language":"Markdown"},{"name":"git_statistics.rb","additions":62,"deletions":0,"status":"create","binary":false,"image":false,"vendored":false,"generated":false,"language":"Ruby"}],"merge":false,"create":2,"additions":73,"deletions":0},"fe947ea47b3d6240f2bb103ff51636038b3bb1d7":{"author":"John Smith","author_email":"john.smith@sample.com","time":"2012-04-04 19:22:04 -0400","files":[{"name":"git_statistics.rb","additions":64,"deletions":16,"status":null,"binary":false,"image":false,"vendored":false,"generated":false,"language":"Ruby"}],"merge":false,"additions":64,"deletions":16},"354e8a3795470d75388549d7326d9c12f6e0bf1a":{"author":"Kevin Jalbert","author_email":"kevin.j.jalbert@gmail.com","time":"2012-04-04 23:50:04 -0400","files":[{"name":"README.md","additions":7,"deletions":1,"status":null,"binary":false,"image":false,"vendored":false,"generated":false,"language":"Markdown"},{"name":"commits.rb","additions":64,"deletions":0,"status":"create","binary":false,"image":false,"vendored":false,"generated":false,"language":"Ruby"},{"name":"git_statistics.rb","additions":9,"deletions":4,"status":null,"binary":false,"image":false,"vendored":false,"generated":false,"language":"Ruby"}],"merge":true,"additions":80,"deletions":5,"create":1}}
@@ -1,79 +0,0 @@
1
- {
2
- "0e82e507e5b64a1140623c702015b97b1b3f7f81": {
3
- "author": "Kevin Jalbert",
4
- "author_email": "kevin.j.jalbert@gmail.com",
5
- "time": "2012-04-04 13:46:56 -0400",
6
- "files": [
7
- {
8
- "name": "README.md",
9
- "additions": 11,
10
- "deletions": 0,
11
- "status": "create",
12
- "binary": false,
13
- "image": false,
14
- "vendored": false,
15
- "generated": false,
16
- "language": "Markdown"
17
- },
18
- {
19
- "name": "git_statistics.rb",
20
- "additions": 62,
21
- "deletions": 0,
22
- "status": "create",
23
- "binary": false,
24
- "image": false,
25
- "vendored": false,
26
- "generated": false,
27
- "language": "Ruby"
28
- }
29
- ],
30
- "merge": false,
31
- "create": 2,
32
- "additions": 73,
33
- "deletions": 0
34
- },
35
- "354e8a3795470d75388549d7326d9c12f6e0bf1a": {
36
- "author": "Kevin Jalbert",
37
- "author_email": "kevin.j.jalbert@gmail.com",
38
- "time": "2012-04-04 23:50:04 -0400",
39
- "files": [
40
- {
41
- "name": "README.md",
42
- "additions": 7,
43
- "deletions": 1,
44
- "status": null,
45
- "binary": false,
46
- "image": false,
47
- "vendored": false,
48
- "generated": false,
49
- "language": "Markdown"
50
- },
51
- {
52
- "name": "commits.rb",
53
- "additions": 64,
54
- "deletions": 0,
55
- "status": "create",
56
- "binary": false,
57
- "image": false,
58
- "vendored": false,
59
- "generated": false,
60
- "language": "Ruby"
61
- },
62
- {
63
- "name": "git_statistics.rb",
64
- "additions": 9,
65
- "deletions": 4,
66
- "status": null,
67
- "binary": false,
68
- "image": false,
69
- "vendored": false,
70
- "generated": false,
71
- "language": "Ruby"
72
- }
73
- ],
74
- "merge": true,
75
- "additions": 80,
76
- "deletions": 5,
77
- "create": 1
78
- }
79
- }
@@ -1,17 +0,0 @@
1
- All authors(2) sorted by commits
2
- ----------------------------------------------------------------------------------------------------------------
3
- Name/Email | Language | Commits | Additions | Deletions | Creates | Deletes | Renames | Copies | Merges |
4
- ----------------------------------------------------------------------------------------------------------------
5
- Kevin Jalbert | | 1 | 73 | 0 | 2 | 0 | 0 | 0 | 0 |
6
- | Markdown | | 11 | 0 | 1 | 0 | 0 | 0 | 0 |
7
- | Ruby | | 62 | 0 | 1 | 0 | 0 | 0 | 0 |
8
- John Smith | | 1 | 64 | 16 | 0 | 0 | 0 | 0 | 0 |
9
- | Ruby | | 64 | 16 | 0 | 0 | 0 | 0 | 0 |
10
-
11
- All authors(2) sorted by commits
12
- ----------------------------------------------------------------------------------------------------------------
13
- Name/Email | Language | Commits | Additions | Deletions | Creates | Deletes | Renames | Copies | Merges |
14
- ----------------------------------------------------------------------------------------------------------------
15
- Repository Totals | | 2 | 137 | 16 | 2 | 0 | 0 | 0 | 0 |
16
- | Markdown | | 11 | 0 | 1 | 0 | 0 | 0 | 0 |
17
- | Ruby | | 126 | 16 | 1 | 0 | 0 | 0 | 0 |
data/spec/spec_helper.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.start do
4
- add_filter "/spec/"
5
- end
6
-
7
- require File.dirname(__FILE__) + '/../lib/git_statistics/initialize.rb'
8
-
9
- def fixture(file)
10
- File.new(File.dirname(__FILE__) + '/fixtures/' + file, 'r')
11
- end
12
-
13
- def setup_commits(commits, file_load, file_save, pretty)
14
- return if file_load.nil? || file_save.nil?
15
- commits.load(fixture(file_load))
16
- commits.save(file_save, pretty)
17
- end