git_heat 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 128f12f0f840e046ac9617df4b3ff18470ebbcd4
4
+ data.tar.gz: 58ac0df4fbafd0c83fa56d35fa0b159b7b85b69f
5
+ SHA512:
6
+ metadata.gz: d32f98b2d12d2e863f16df32a50bf3fb7988565dbe5a487b22d4345d6ac036260ec391ec6c7331617ef6ff50f4baa6abef23e49aed52431d3235af5d4ea99c47
7
+ data.tar.gz: d94de469bbbd22fa9d30c3b15886640b221e36c6e198bb0a6747f1aa2c999185f0174d59fe5153ec4733a9c4e4bda97dfdf15458cdb91d3513f324f4c4d561c2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git_heat.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_heat (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.1)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.8)
16
+ rspec-expectations (2.14.5)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.6)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.3)
25
+ git_heat!
26
+ rake
27
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Serguei Filimonov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GitHeat
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'git_heat'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install git_heat
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/git-heat ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/git_heat/git_stat'
4
+ require_relative '../lib/git_heat/git_client'
5
+ require_relative '../lib/git_heat/calculator'
6
+
7
+ unless ARGV[0]
8
+ puts "Usage git-heat GIT_REPO_PATH"
9
+ exit
10
+ end
11
+
12
+ begin
13
+ puts(Calculator.new(Time.now).go(
14
+ GitStat.new(
15
+ GitClient.new(ARGV[0])
16
+ ).stats
17
+ ).map do |a|
18
+ a[0].to_s.ljust(100) + a[1].to_s
19
+ end.to_a)
20
+ rescue Errno::EPIPE
21
+ end
data/git_heat.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_heat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_heat"
8
+ spec.version = GitHeat::VERSION
9
+ spec.authors = ["Serguei Filimonov"]
10
+ spec.email = ["serguei.filimonov@gmail.com"]
11
+ spec.description = %q{Reports a measure of activity in each file of a git repo }
12
+ spec.summary = %q{Reports a measure of activity in each file of a git repo }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,23 @@
1
+ class Calculator
2
+ HALF_LIFE = 60.0*60*24
3
+
4
+ def initialize(time)
5
+ @time = time
6
+ end
7
+
8
+ def go(stats)
9
+ heat = {}
10
+ stats.each do |commit|
11
+ time_delta = @time - commit[:time]
12
+ unless commit[:affected_files]
13
+ next
14
+ end
15
+ commit[:affected_files].each do |file|
16
+ impact = (file[:insertions] + file[:deletions]).to_f
17
+ heat[file[:file]] ||= 0
18
+ heat[file[:file]] += impact*(0.5**(time_delta/HALF_LIFE))
19
+ end
20
+ end
21
+ heat.sort_by {|_key, value| value}.reverse
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ class GitClient
2
+ def initialize(dir)
3
+ @dir = dir
4
+ end
5
+ def stat_history
6
+ ret = nil
7
+ Dir.chdir(@dir) do
8
+ ret = `git log --numstat --pretty=format:"commit: %H %cd" --reverse`
9
+ end
10
+ ret
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'time'
2
+
3
+ class GitStat
4
+ def initialize(git)
5
+ @git = git
6
+ end
7
+
8
+ def stats
9
+ commits = []
10
+ @git.stat_history.each_line do |line|
11
+ if line =~ /^commit:/
12
+ commits << {}
13
+ commits.last[:commit] = line[/^commit: (.*?) /, 1]
14
+ commits.last[:time] = Time.parse(line[/^commit: .*? (.*)/, 1])
15
+ elsif line =~ /^\d/
16
+ commits.last[:affected_files] ||= []
17
+ commits.last[:affected_files] << {}
18
+ commits.last[:affected_files].last[:file] = line[/^\d+\s\d+\s(.*)$/, 1]
19
+ insertions = line[/^(\d+)/, 1]
20
+ deletions = line[/^(\d+) (\d+)/, 2]
21
+ commits.last[:affected_files].last[:insertions] = insertions.to_i
22
+ commits.last[:affected_files].last[:deletions] = deletions.to_i
23
+ end
24
+ end
25
+ commits
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module GitHeat
2
+ VERSION = "0.0.1"
3
+ end
data/lib/git_heat.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "git_heat/version"
2
+
3
+ module GitHeat
4
+ # Your code goes here...
5
+ end
data/sandbox/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "git_heat", path: '../'
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ git_heat (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ git_heat!
@@ -0,0 +1,35 @@
1
+ require 'rspec'
2
+ require_relative '../lib/git_heat/calculator'
3
+
4
+ describe Calculator do
5
+ it "works" do
6
+ stats = [
7
+ {
8
+ commit: "7c54c33bdd16606118d4c6faa41098ff85635439",
9
+ time: Time.parse("2014-04-19 15:19:17 -0700"),
10
+ affected_files: [
11
+ {file: 'file', insertions: 1, deletions: 0}
12
+ ]
13
+ },
14
+ {
15
+ commit: "c90192a6a40eee00319aa7e9b14fba84816a1697",
16
+ time: Time.parse("2014-04-19 15:20:36 -0700"),
17
+ affected_files: [
18
+ {file: 'file', insertions: 2, deletions: 0},
19
+ {file: 'file2', insertions: 3, deletions: 0}
20
+ ]
21
+ },
22
+ {
23
+ commit: "9bd48ee99f700dd2e42db330b9fc50939fc11634",
24
+ time: Time.parse("2014-04-19 15:31:01 -0700"),
25
+ affected_files: [
26
+ {file: 'file2', insertions: 2, deletions: 2}
27
+ ]
28
+ },
29
+ ]
30
+ Calculator.new(Time.parse("2014-04-20 15:31:01 -0700")).go(stats).should == [
31
+ ["file2", 3.4924976960534404],
32
+ ["file", 1.4921824906831624],
33
+ ]
34
+ end
35
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../lib/git_heat/git_stat'
2
+
3
+ class FakeGitClient
4
+ def initialize(stat_history)
5
+ @stat_history = stat_history
6
+ end
7
+
8
+ def stat_history
9
+ @stat_history
10
+ end
11
+ end
12
+ describe "GitStat" do
13
+ it "works" do
14
+ git_out = <<HERED
15
+ commit: 7c54c33bdd16606118d4c6faa41098ff85635439 Sat Apr 19 15:19:17 2014 -0700
16
+ 1 0 file
17
+
18
+ commit: c90192a6a40eee00319aa7e9b14fba84816a1697 Sat Apr 19 15:20:36 2014 -0700
19
+ 2 0 file
20
+ 3 0 file2
21
+
22
+ commit: 9bd48ee99f700dd2e42db330b9fc50939fc11634 Sat Apr 19 15:31:01 2014 -0700
23
+ 2 2 file2
24
+ HERED
25
+ st = GitStat.new(FakeGitClient.new(git_out))
26
+ st.stats.should == [
27
+ {
28
+ commit: "7c54c33bdd16606118d4c6faa41098ff85635439",
29
+ time: Time.parse("2014-04-19 15:19:17 -0700"),
30
+ affected_files: [
31
+ {file: 'file', insertions: 1, deletions: 0}
32
+ ]
33
+ },
34
+ {
35
+ commit: "c90192a6a40eee00319aa7e9b14fba84816a1697",
36
+ time: Time.parse("2014-04-19 15:20:36 -0700"),
37
+ affected_files: [
38
+ {file: 'file', insertions: 2, deletions: 0},
39
+ {file: 'file2', insertions: 3, deletions: 0}
40
+ ]
41
+ },
42
+ {
43
+ commit: "9bd48ee99f700dd2e42db330b9fc50939fc11634",
44
+ time: Time.parse("2014-04-19 15:31:01 -0700"),
45
+ affected_files: [
46
+ {file: 'file2', insertions: 2, deletions: 2}
47
+ ]
48
+ },
49
+ ]
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_heat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Serguei Filimonov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'Reports a measure of activity in each file of a git repo '
70
+ email:
71
+ - serguei.filimonov@gmail.com
72
+ executables:
73
+ - git-heat
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/git-heat
83
+ - git_heat.gemspec
84
+ - lib/git_heat.rb
85
+ - lib/git_heat/calculator.rb
86
+ - lib/git_heat/git_client.rb
87
+ - lib/git_heat/git_stat.rb
88
+ - lib/git_heat/version.rb
89
+ - sandbox/Gemfile
90
+ - sandbox/Gemfile.lock
91
+ - spec/calculator_spec.rb
92
+ - spec/git_stat_spec.rb
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.1.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Reports a measure of activity in each file of a git repo
117
+ test_files:
118
+ - spec/calculator_spec.rb
119
+ - spec/git_stat_spec.rb
120
+ has_rdoc: