git_analyze 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/git_analyze +20 -0
- data/git_analyze.gemspec +25 -0
- data/lib/git_analyze/version.rb +3 -0
- data/lib/git_analyze.rb +83 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e01ab26b8402bc44ef7c90d09720c6def78e4df
|
4
|
+
data.tar.gz: a7c7bde044a5b6560ef23743d88be0eeb97d1308
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7791db52159bd60f301ab65ce2144290a89d9695d68d29f4a0d22cb8fcec303834b998ca3ae02bace0192468486fed40d1e0b0723c96656afe33df9d8e3e07c1
|
7
|
+
data.tar.gz: 71db839e0b033efa954023930459c1b59ff6d0f9e29fcbdb4346352a4609254eff77eb66052c3bd0e0dd08170c0df91f563169b870a7174fc784aeaa088fd557
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Aaron Neyer
|
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
|
+
# GitAnalyze
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'git_analyze'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install git_analyze
|
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_analyze
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'git_analyze'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on('--api-key=APIKEY', String, "AlchemyAPI api key") do |key|
|
9
|
+
options[:key] = key
|
10
|
+
end
|
11
|
+
|
12
|
+
opts.on('--oauth=OAUTH_TOKEN', String, "Github Oauth token") do |token|
|
13
|
+
options[:token] = token
|
14
|
+
end
|
15
|
+
end.parse!
|
16
|
+
|
17
|
+
overall_stats, author_commits = GitAnalyze.pull_stats(options[:key], options[:token], ARGV[0], ARGV[1])
|
18
|
+
|
19
|
+
GitAnalyze.output_overall(overall_stats)
|
20
|
+
GitAnalyze.output_author(author_commits)
|
data/git_analyze.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_analyze/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git_analyze"
|
8
|
+
spec.version = GitAnalyze::VERSION
|
9
|
+
spec.authors = ["Aaron Neyer"]
|
10
|
+
spec.email = ["aaronneyer@gmail.com"]
|
11
|
+
spec.description = %q{analyzes git}
|
12
|
+
spec.summary = %q{}
|
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_dependency "github_api"
|
24
|
+
spec.add_dependency "alchemy-api"
|
25
|
+
end
|
data/lib/git_analyze.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require "git_analyze/version"
|
2
|
+
require 'alchemy-api'
|
3
|
+
require 'github_api'
|
4
|
+
require 'thread/pool'
|
5
|
+
|
6
|
+
module GitAnalyze
|
7
|
+
class << self
|
8
|
+
def get_all_commits(github_oauth, user, repo)
|
9
|
+
@github = Github.new(oauth_token: github_oauth, per_page: 100)
|
10
|
+
commits = []
|
11
|
+
new_commits = @github.repos.commits.all(user, repo, per_page: 100)
|
12
|
+
commits.concat(new_commits)
|
13
|
+
while new_commits.length == 100
|
14
|
+
next_sha = new_commits[-1]['sha']
|
15
|
+
new_commits = @github.repos.commits.all(user, repo, sha: next_sha, per_page: 100)
|
16
|
+
commits.concat(new_commits[1..-1])
|
17
|
+
end
|
18
|
+
commits
|
19
|
+
end
|
20
|
+
|
21
|
+
def pull_stats(api_key, github_oauth, user, repo)
|
22
|
+
commits = get_all_commits(github_oauth, user, repo)
|
23
|
+
@alchemy = AlchemyAPI::Client.new(api_key)
|
24
|
+
author_commits = {} # Stores commit stats by author
|
25
|
+
overall_stats = []
|
26
|
+
|
27
|
+
pool = Thread.pool(30)
|
28
|
+
commits.each do |commit|
|
29
|
+
pool.process do
|
30
|
+
message = commit.commit.message
|
31
|
+
sentiment = @alchemy.TextGetTextSentiment(text: message)['docSentiment']
|
32
|
+
keywords = @alchemy.TextGetRankedKeywords(text: message)['keywords']
|
33
|
+
score = sentiment ? sentiment['score'].to_f : 0.0
|
34
|
+
author = commit.commit.author.name
|
35
|
+
author_commits[author] ||= []
|
36
|
+
commit_stats = {}
|
37
|
+
commit_stats[:sentiment] = score
|
38
|
+
commit_stats[:lines] = message.lines.count
|
39
|
+
commit_stats[:keywords] = keywords.map{|k| k['text']}
|
40
|
+
author_commits[author] << commit_stats
|
41
|
+
overall_stats << commit_stats
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
pool.shutdown
|
46
|
+
|
47
|
+
return overall_stats, author_commits
|
48
|
+
end
|
49
|
+
|
50
|
+
def output_overall(overall_stats)
|
51
|
+
total_commits = overall_stats.count
|
52
|
+
total_lines = overall_stats.map{|cstat| cstat[:lines]}.inject(:+).to_f
|
53
|
+
sentiments = overall_stats.map{|cstat| cstat[:sentiment]}
|
54
|
+
overall_sentiment = sentiments.inject(:+)
|
55
|
+
all_keywords = overall_stats.flat_map{|cstat| cstat[:keywords]}.group_by{|x|x}
|
56
|
+
all_keywords = all_keywords.sort_by{|k,v| v.length}.reverse
|
57
|
+
puts "Total commits: #{total_commits}"
|
58
|
+
puts "Total lines: #{total_lines}"
|
59
|
+
puts "Average lines per commit: #{total_lines/total_commits}"
|
60
|
+
puts "#{sentiments.select{|x|x>0}.count} positive messages vs #{sentiments.select{|x|x<0}.count} negative messages"
|
61
|
+
puts "Total sentiment: #{overall_sentiment.round(3)}"
|
62
|
+
puts "Average sentiment: #{(overall_sentiment/total_commits).round(3)}"
|
63
|
+
puts "Keywords:"
|
64
|
+
all_keywords.take(10).each do |k,v|
|
65
|
+
puts "\t\"#{k}\" * #{v.length}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def output_author(author_commits)
|
70
|
+
author_commits = Hash[author_commits.sort_by{|k,v| v.length}.reverse.take(10)]
|
71
|
+
puts "Most frequent committers:"
|
72
|
+
author_commits.each do |k,v|
|
73
|
+
lines = v.map{|x| x[:lines]}.inject(:+).to_f
|
74
|
+
sentiment = v.map{|x| x[:sentiment]}.inject(:+)
|
75
|
+
all_keywords = v.flat_map{|x| x[:keywords]}
|
76
|
+
big_keyword = all_keywords.sort_by{|keyword| all_keywords.count(keyword)}.last
|
77
|
+
puts "\t#{k} has #{v.length} commits. #{(lines/v.length).round(3)} lines"+
|
78
|
+
" per message, and an average sentiment of #{(sentiment/v.length).round(3)}."+
|
79
|
+
" Their most common keyword is \"#{big_keyword || "N/A"}\""
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_analyze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Neyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-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: github_api
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: alchemy-api
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: analyzes git
|
70
|
+
email:
|
71
|
+
- aaronneyer@gmail.com
|
72
|
+
executables:
|
73
|
+
- git_analyze
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/git_analyze
|
83
|
+
- git_analyze.gemspec
|
84
|
+
- lib/git_analyze.rb
|
85
|
+
- lib/git_analyze/version.rb
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: ''
|
110
|
+
test_files: []
|