git_statistics 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
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
+ }
@@ -0,0 +1,17 @@
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 |
@@ -0,0 +1,143 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include GitStatistics
3
+
4
+ describe Results do
5
+ email = false
6
+ merge = false
7
+ sort = "commits"
8
+
9
+ commits = Commits.new
10
+ commits.load(fixture("multiple_authors.json"))
11
+ commits.calculate_statistics(email, merge)
12
+
13
+ results = Results.new(commits)
14
+
15
+ describe "#prepare_result_summary" do
16
+
17
+ context "with email and sorting" do
18
+ config = results.prepare_result_summary(sort, email)
19
+ data = config[:data]
20
+
21
+ author_1 = "Kevin Jalbert"
22
+ author_2 = "John Smith"
23
+
24
+ it {data.has_key?(author_1).should be_true}
25
+ it {data.has_key?(author_2).should be_true}
26
+
27
+ it {data[author_1][:commits].should == 1}
28
+ it {data[author_1][:additions].should == 73}
29
+ it {data[author_1][:deletions].should == 0}
30
+ it {data[author_1][:create].should == 2}
31
+
32
+ it {data[author_1][:languages][:Ruby][:additions].should == 62}
33
+ it {data[author_1][:languages][:Ruby][:deletions].should == 0}
34
+ it {data[author_1][:languages][:Ruby][:create].should == 1}
35
+ it {data[author_1][:languages][:Markdown][:additions].should == 11}
36
+ it {data[author_1][:languages][:Markdown][:deletions].should == 0}
37
+ it {data[author_1][:languages][:Markdown][:create].should == 1}
38
+
39
+ it {data[author_2][:commits].should == 1}
40
+ it {data[author_2][:additions].should == 64}
41
+ it {data[author_2][:deletions].should == 16}
42
+
43
+ it {data[author_2][:languages][:Ruby][:additions].should == 64}
44
+ it {data[author_2][:languages][:Ruby][:deletions].should == 16}
45
+
46
+ it {config[:sort].should == sort}
47
+ it {config[:email].should == email}
48
+ it {config[:top_n].should == 0}
49
+ it {config[:author_length].should == 17}
50
+ it {config[:language_length].should == 8}
51
+ end
52
+
53
+ context "with negative top_n" do
54
+ config = results.prepare_result_summary(sort, email, -1)
55
+ data = config[:data]
56
+
57
+ author_1 = "Kevin Jalbert"
58
+ author_2 = "John Smith"
59
+
60
+ it {data.has_key?(author_1).should be_true}
61
+ it {data.has_key?(author_2).should be_true}
62
+
63
+ it {data[author_1][:commits].should == 1}
64
+ it {data[author_1][:additions].should == 73}
65
+ it {data[author_1][:deletions].should == 0}
66
+ it {data[author_1][:create].should == 2}
67
+
68
+ it {data[author_1][:languages][:Ruby][:additions].should == 62}
69
+ it {data[author_1][:languages][:Ruby][:deletions].should == 0}
70
+ it {data[author_1][:languages][:Ruby][:create].should == 1}
71
+ it {data[author_1][:languages][:Markdown][:additions].should == 11}
72
+ it {data[author_1][:languages][:Markdown][:deletions].should == 0}
73
+ it {data[author_1][:languages][:Markdown][:create].should == 1}
74
+
75
+ it {data[author_2][:commits].should == 1}
76
+ it {data[author_2][:additions].should == 64}
77
+ it {data[author_2][:deletions].should == 16}
78
+
79
+ it {data[author_2][:languages][:Ruby][:additions].should == 64}
80
+ it {data[author_2][:languages][:Ruby][:deletions].should == 16}
81
+
82
+ it {config[:sort].should == sort}
83
+ it {config[:email].should == email}
84
+ it {config[:top_n].should == 0}
85
+ it {config[:author_length].should == 17}
86
+ it {config[:language_length].should == 8}
87
+ end
88
+
89
+ context "with top_n that filters to one author" do
90
+ config = results.prepare_result_summary(sort, email, 1)
91
+ data = config[:data]
92
+
93
+ author_1 = "Kevin Jalbert"
94
+ author_2 = "John Smith"
95
+
96
+ it {data.has_key?(author_1).should be_true}
97
+ it {data.has_key?(author_2).should be_false}
98
+
99
+ it {data[author_1][:commits].should == 1}
100
+ it {data[author_1][:additions].should == 73}
101
+ it {data[author_1][:deletions].should == 0}
102
+ it {data[author_1][:create].should == 2}
103
+
104
+ it {data[author_1][:languages][:Ruby][:additions].should == 62}
105
+ it {data[author_1][:languages][:Ruby][:deletions].should == 0}
106
+ it {data[author_1][:languages][:Ruby][:create].should == 1}
107
+ it {data[author_1][:languages][:Markdown][:additions].should == 11}
108
+ it {data[author_1][:languages][:Markdown][:deletions].should == 0}
109
+ it {data[author_1][:languages][:Markdown][:create].should == 1}
110
+
111
+ it {config[:sort].should == sort}
112
+ it {config[:email].should == email}
113
+ it {config[:top_n].should == 1}
114
+ it {config[:author_length].should == 17}
115
+ it {config[:language_length].should == 8}
116
+ end
117
+ end
118
+
119
+ describe "#print_summary" do
120
+ context "with valid data" do
121
+ config = results.prepare_result_summary(sort, email)
122
+ language_data = results.print_summary(sort, email)
123
+ it {language_data.should == fixture("summary_output.txt").read}
124
+ end
125
+ end
126
+
127
+ describe "#print_language_data" do
128
+ context "with valid data" do
129
+ config = results.prepare_result_summary(sort, email)
130
+ language_data = results.print_language_data(config[:pattern], config[:data]["Kevin Jalbert"])
131
+ it {language_data.should == fixture("language_data_output.txt").read}
132
+ end
133
+ end
134
+
135
+ describe "#print_header" do
136
+ context "with valid data" do
137
+ config = results.prepare_result_summary(sort, email)
138
+ header = results.print_header(config)
139
+ it {header.should == fixture("header_output.txt").read}
140
+ end
141
+ end
142
+
143
+ end
@@ -0,0 +1,169 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include GitStatistics
3
+
4
+ describe Utilities do
5
+
6
+ describe "#get_repository" do
7
+ context "with root directory" do
8
+ repo = Utilities.get_repository(Dir.pwd) # git_statistics/
9
+ it {repo.instance_of?(Grit::Repo).should be_true}
10
+ end
11
+
12
+ context "with sub directory" do
13
+ repo = Utilities.get_repository(File.dirname(__FILE__)) # git_statistics/spec/
14
+ it {repo.instance_of?(Grit::Repo).should be_true}
15
+ end
16
+
17
+ context "not in a repository directory" do
18
+ repo = Utilities.get_repository(Dir.pwd + "../") # git_statistics/../
19
+ it {repo.should == nil}
20
+ end
21
+ end
22
+
23
+ describe "#find_longest_length" do
24
+ context "with empty list" do
25
+ results = Utilities.find_longest_length([])
26
+ it {results.should == nil}
27
+ end
28
+
29
+ context "with nil list" do
30
+ results = Utilities.find_longest_length(nil)
31
+ it {results.should == nil}
32
+ end
33
+
34
+ context "with preset minimum length" do
35
+ results = Utilities.find_longest_length([], 10)
36
+ it {results.should == 10}
37
+ end
38
+
39
+ context "with valid list" do
40
+ list = ["abc", "a", "ab"]
41
+ results = Utilities.find_longest_length(list)
42
+ it {results.should == 3}
43
+ end
44
+
45
+ context "with valid hash" do
46
+ list = {"a" => "word_a", "ab" => "word_b", "abc" => "word_c"}
47
+ results = Utilities.find_longest_length(list)
48
+ it {results.should == 3}
49
+ end
50
+ end
51
+
52
+ describe "#unique_data_in_hash" do
53
+ type = "word".to_sym
54
+
55
+ context "with valid type" do
56
+ data = {:entry_a => {type => "test"},
57
+ :entry_b => {type => "a"},
58
+ :entry_c => {type => "a"},
59
+ :entry_d => {type => "is"},
60
+ :entry_e => {type => "test"}}
61
+
62
+ list = Utilities.unique_data_in_hash(data, type)
63
+
64
+ it {list.size.should == 3}
65
+ it {list.include?("is").should be_true}
66
+ it {list.include?("a").should be_true}
67
+ it {list.include?("test").should be_true}
68
+ end
69
+
70
+ context "with invalid type" do
71
+ data = {:entry_a => {:wrong => "test"},
72
+ :entry_e => {:wrong => "is"}}
73
+
74
+ list = Utilities.unique_data_in_hash(data, type)
75
+
76
+ it {list.should == [nil]}
77
+ end
78
+ end
79
+
80
+ describe "#clean_string" do
81
+ context "with trailling spaces" do
82
+ unclean = " master "
83
+ clean = Utilities.clean_string(unclean)
84
+ it {clean.should == "master"}
85
+ end
86
+ end
87
+
88
+ describe "#split_old_new_file" do
89
+ context "with a change in middle" do
90
+ old = "lib/{old_dir"
91
+ new = "new_dir}/file.rb"
92
+ files = Utilities.split_old_new_file(old, new)
93
+ it {files[:old_file].should == "lib/old_dir/file.rb"}
94
+ it {files[:new_file].should == "lib/new_dir/file.rb"}
95
+ end
96
+
97
+ context "with a change at beginning" do
98
+ old = "{src/dir/lib"
99
+ new = "lib/dir}/file.rb"
100
+ files = Utilities.split_old_new_file(old, new)
101
+ it {files[:old_file].should == "src/dir/lib/file.rb"}
102
+ it {files[:new_file].should == "lib/dir/file.rb"}
103
+ end
104
+
105
+ context "with a change at beginning, alternative" do
106
+ old = "src/{"
107
+ new = "dir}/file.rb"
108
+ files = Utilities.split_old_new_file(old, new)
109
+ it {files[:old_file].should == "src/file.rb"}
110
+ it {files[:new_file].should == "src/dir/file.rb"}
111
+ end
112
+
113
+ context "with a change at ending" do
114
+ old = "lib/dir/{old_file.rb"
115
+ new = "new_file.rb}"
116
+ files = Utilities.split_old_new_file(old, new)
117
+ it {files[:old_file].should == "lib/dir/old_file.rb"}
118
+ it {files[:new_file].should == "lib/dir/new_file.rb"}
119
+ end
120
+
121
+ context "with a simple complete change" do
122
+ old = "file.rb"
123
+ new = "lib/dir/file.rb}"
124
+ files = Utilities.split_old_new_file(old, new)
125
+ it {files[:old_file].should == "file.rb"}
126
+ it {files[:new_file].should == "lib/dir/file.rb"}
127
+ end
128
+ end
129
+
130
+ describe "find_blob_in_tree" do
131
+ repo = Utilities.get_repository(Dir.pwd)
132
+ sha = "7d6c29f0ad5860d3238debbaaf696e361bf8c541" # Commit within repository
133
+ tree = repo.tree(sha)
134
+
135
+ context "blob on root tree" do
136
+ file = "Gemfile"
137
+ blob = Utilities.find_blob_in_tree(tree, file.split(File::Separator))
138
+ it {blob.instance_of?(Grit::Blob).should be_true}
139
+ it {blob.name.should == file}
140
+ end
141
+
142
+ context "blob down tree" do
143
+ file = "lib/git_statistics/collector.rb"
144
+ blob = Utilities.find_blob_in_tree(tree, file.split(File::Separator))
145
+ it {blob.instance_of?(Grit::Blob).should be_true}
146
+ it {blob.name.should == file.split(File::Separator).last}
147
+ end
148
+
149
+ context "file is nil" do
150
+ blob = Utilities.find_blob_in_tree(tree, nil)
151
+ it {blob.should == nil}
152
+ end
153
+
154
+ context "file is empty" do
155
+ blob = Utilities.find_blob_in_tree(tree, [""])
156
+ it {blob.should == nil}
157
+ end
158
+
159
+ context "file is submodule" do
160
+ sha = "1940ef1c613a04f855d3867b874a4267d3e2c011"
161
+ tree = repo.tree(sha)
162
+ file = "Spoon-Knife"
163
+ blob = Utilities.find_blob_in_tree(tree, file.split(File::Separator))
164
+ it {blob.instance_of?(Grit::Submodule).should be_true}
165
+ it {blob.name.should == file}
166
+ end
167
+ end
168
+
169
+ end
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.2.0
4
+ version: 0.3.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-09-07 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: os
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  description: git_statistics is a gem that provides detailed git statistics
79
95
  email:
80
96
  - kevin.j.jalbert@gmail.com
@@ -85,8 +101,10 @@ extra_rdoc_files: []
85
101
  files:
86
102
  - .gitignore
87
103
  - .travis.yml
104
+ - CHANGELOG.md
88
105
  - Gemfile
89
106
  - Gemfile.lock
107
+ - Guardfile
90
108
  - LICENSE
91
109
  - README.md
92
110
  - Rakefile
@@ -97,8 +115,26 @@ files:
97
115
  - lib/git_statistics/collector.rb
98
116
  - lib/git_statistics/commits.rb
99
117
  - lib/git_statistics/initialize.rb
118
+ - lib/git_statistics/results.rb
119
+ - lib/git_statistics/utilities.rb
100
120
  - lib/git_statistics/version.rb
121
+ - spec/collector_spec.rb
122
+ - spec/commits_spec.rb
123
+ - spec/fixtures/commit_buffer_changes.txt
124
+ - spec/fixtures/commit_buffer_information.txt
125
+ - spec/fixtures/commit_buffer_information_first.txt
126
+ - spec/fixtures/commit_buffer_information_with_merge.txt
127
+ - spec/fixtures/commit_buffer_whole.txt
128
+ - spec/fixtures/git_many_branches.txt
129
+ - spec/fixtures/git_zero_branches.txt
130
+ - spec/fixtures/header_output.txt
131
+ - spec/fixtures/language_data_output.txt
132
+ - spec/fixtures/multiple_authors.json
133
+ - spec/fixtures/single_author_pretty.json
134
+ - spec/fixtures/summary_output.txt
135
+ - spec/results_spec.rb
101
136
  - spec/spec_helper.rb
137
+ - spec/utilities_spec.rb
102
138
  homepage: https://github.com/kevinjalbert/git_statistics
103
139
  licenses: []
104
140
  post_install_message:
@@ -124,4 +160,20 @@ signing_key:
124
160
  specification_version: 3
125
161
  summary: Gem that provides the ability to gather detailed git statistics
126
162
  test_files:
163
+ - spec/collector_spec.rb
164
+ - spec/commits_spec.rb
165
+ - spec/fixtures/commit_buffer_changes.txt
166
+ - spec/fixtures/commit_buffer_information.txt
167
+ - spec/fixtures/commit_buffer_information_first.txt
168
+ - spec/fixtures/commit_buffer_information_with_merge.txt
169
+ - spec/fixtures/commit_buffer_whole.txt
170
+ - spec/fixtures/git_many_branches.txt
171
+ - spec/fixtures/git_zero_branches.txt
172
+ - spec/fixtures/header_output.txt
173
+ - spec/fixtures/language_data_output.txt
174
+ - spec/fixtures/multiple_authors.json
175
+ - spec/fixtures/single_author_pretty.json
176
+ - spec/fixtures/summary_output.txt
177
+ - spec/results_spec.rb
127
178
  - spec/spec_helper.rb
179
+ - spec/utilities_spec.rb