gitstatsakido 0.1.0

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: 5c9ebebb8f89485cea0d4838dbbb7397a16c9433
4
+ data.tar.gz: 87595171c9dd191246f37088cee909ef4205099f
5
+ SHA512:
6
+ metadata.gz: c104c1f0e0d09de36e5a0bdc9570916d3d2bc93d9bbd5c31545e458c0f5a592f714fd6355328d928fc4d7a0aba7d9e795c5c01e9d569d526ddbd08ca7de4830b
7
+ data.tar.gz: b707294877b91aeb912178bbdf45f773bef34a38a3411b1bb06ff5b168af54e5a30b1155fb9afe25707796e21beedc94141f7712f376a7f655987f61b236220c
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /Gemfile.lock
4
+ /pkg/
data/.idea/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build gitstats-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install gitstats-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install gitstats-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push gitstats-0.1.0.gem to Rubygems" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
data/.idea/misc.xml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+ <OptionsSetting value="true" id="Add" />
5
+ <OptionsSetting value="true" id="Remove" />
6
+ <OptionsSetting value="true" id="Checkout" />
7
+ <OptionsSetting value="true" id="Update" />
8
+ <OptionsSetting value="true" id="Status" />
9
+ <OptionsSetting value="true" id="Edit" />
10
+ <ConfirmationsSetting value="0" id="Add" />
11
+ <ConfirmationsSetting value="0" id="Remove" />
12
+ </component>
13
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.2.1" project-jdk-type="RUBY_SDK" />
14
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/gitstats.iml" filepath="$PROJECT_DIR$/.idea/gitstats.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.12.1
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at lei@akidolabs.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitstats.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Gitstats
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitstats`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gitstats'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gitstats
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitstats. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gitstats"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/gitstats ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gitstats'
4
+
5
+ runme = Gitstats::Stats.new
6
+
7
+ runme.print_info
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/gitstats.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitstats/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gitstatsakido"
8
+ spec.version = Gitstats::VERSION
9
+ spec.authors = ["Lei Wang"]
10
+ spec.email = ["lei@akidolabs.com"]
11
+
12
+ spec.summary = %q{Display Git Coding Stats}
13
+ spec.description = %q{Display code change stats for the current git repository by Author}
14
+ spec.homepage = "http://www.akidolabs.com"
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.executables = ["gitstats"]
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
data/lib/b.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Lei Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ module Gitstats
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gitstats.rb ADDED
@@ -0,0 +1,187 @@
1
+ require "gitstats/version"
2
+ require "open3"
3
+
4
+ module Gitstats
5
+
6
+ class Commit
7
+ def initialize(id, commit_text_chunk)
8
+ # ignore_files = []
9
+ ignore_files = ['.txt', '.xml', '.dat', '.csv', 'out', 'swp', '.class']
10
+ @id = id
11
+ @text = commit_text_chunk
12
+ @ignore_add = 0
13
+ @ignore_del = 0
14
+ @inserts = 0
15
+ @deletes = 0
16
+ @files = 0
17
+ commit_text_chunk.split(/\r?\n/).each do |line|
18
+ words = line.split()
19
+ if /Author: [^<]+<[^>]+>/.match(line)
20
+ # TODO use name instead of email
21
+ @author = words[-1]
22
+ elsif /Date: /.match(line)
23
+ @time = Time.parse(line[7..-1])
24
+ elsif / [0-9]+ files? changed/.match(line)
25
+ words.each_with_index do |item, index|
26
+ if item[0..3] == 'file'
27
+ @files = words[index-1].to_i
28
+ elsif item[0..3] == 'inse'
29
+ @inserts = words[index-1].to_i
30
+ elsif item[0..3] == 'dele'
31
+ @deletes = words[index-1].to_i
32
+ end
33
+ end
34
+ @inserts -= @ignore_add
35
+ @deletes -= @ignore_del
36
+ @files = words[0].to_i
37
+ elsif / [^|]+ \| [0-9]+ [+-]+/.match(line)
38
+ file_name = words[0].split()[-1]
39
+ count = words[2].to_i
40
+ plus_count = 0
41
+ minus_count = 0
42
+ plus_c = 0
43
+ minus_c = 0
44
+ if count > 0
45
+ words[3].each_char do |c|
46
+ if c == '+'
47
+ plus_count += 1
48
+ else
49
+ minus_count += 1
50
+ end
51
+ end
52
+ plus_c = count * plus_count / (plus_count + minus_count)
53
+ minus_c = count - plus_c
54
+ end
55
+ ignore_files.each do |ext|
56
+ comp_length = ext.length
57
+ if file_name[-1 * comp_length..-1] == ext
58
+ @ignore_add += plus_c
59
+ @ignore_del += minus_c
60
+ break
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def print_info
68
+ puts "Commit: #{@id} Author: #{@author} Time: #{@time} Files changed: #{@files}"
69
+ end
70
+
71
+ def author()
72
+ @author
73
+ end
74
+
75
+ def set_author(author)
76
+ @author = author
77
+ end
78
+
79
+ def inserts()
80
+ @inserts
81
+ end
82
+
83
+ def deletes
84
+ @deletes
85
+ end
86
+
87
+ def files
88
+ @files
89
+ end
90
+ end
91
+
92
+ class Author
93
+ def initialize(name)
94
+ @name = name
95
+ @commits = Array.new
96
+ @total_lines = 0
97
+ @total_files = 0
98
+ @total_inserts = 0
99
+ @total_deletes = 0
100
+ end
101
+
102
+ def add_commit(commit)
103
+ @commits << commit
104
+
105
+ if commit.inserts != nil
106
+ @total_lines += commit.inserts
107
+ @total_inserts += commit.inserts
108
+ end
109
+ if commit.deletes != nil
110
+ @total_lines += commit.deletes
111
+ @total_deletes += commit.deletes
112
+ end
113
+
114
+ @total_files += commit.files
115
+ end
116
+
117
+ def total_commits
118
+ @commits.length
119
+ end
120
+
121
+ def total_lines
122
+ @total_lines
123
+ end
124
+
125
+ def total_files
126
+ @total_files
127
+ end
128
+
129
+ def total_inserts
130
+ @total_inserts
131
+ end
132
+
133
+ def total_deletes
134
+ @total_deletes
135
+ end
136
+ end
137
+
138
+
139
+
140
+ class Stats
141
+ output, error, status = Open3.capture3('git log --stat -M')
142
+ error = error.strip
143
+ @@authors = Hash.new
144
+ auth_mapping = {"<hgordon@gmail.com>" => "<hugh@akidolabs.com>", "hgordon@gmail.com" => "<hugh@akidolabs.com", "<hugh@Hugh-Mac.local>" => "<hugh@akidolabs.com>"}
145
+ auth_mapping["<poksay.andrew@gmail.com>"] = "<andrew@akidolabs.com>"
146
+ if error == 'fatal: Not a git repository (or any of the parent directories): .git'
147
+ @@result = "Please run this gem from a git repository's directory (that you have run git init on)"
148
+ elsif !error.empty?
149
+ @@result = 'Unknown error from git: ' + error
150
+ else
151
+ commit_regex = /commit [a-z0-9]{40}\r?\n/
152
+ commits = output.enum_for(:scan, commit_regex).map { Regexp.last_match.begin(0) }
153
+ commits.each_with_index do |x, index|
154
+ if index >= commits.length - 1
155
+ end_match = output.length
156
+ else
157
+ end_match = commits[index+1]
158
+ end
159
+
160
+ commit_data = Commit.new(output[x+7,40], output[x+48..end_match-1])
161
+ if auth_mapping.key?(commit_data.author)
162
+ commit_data.set_author(auth_mapping[commit_data.author])
163
+ end
164
+ auth = commit_data.author
165
+ if @@authors.key?(auth)
166
+ @@authors[auth].add_commit(commit_data)
167
+ else
168
+ @@authors[auth] = Author.new(auth)
169
+ end
170
+ end
171
+ @@result = @@authors["<lei@akidolabs.com>"].total_commits
172
+
173
+ end
174
+
175
+ def print_info
176
+ @@authors.each do |k, v|
177
+ puts "Author #{k}:"
178
+ puts " Total # of commits: #{v.total_commits}"
179
+ puts " Total # of files changed: #{v.total_files}"
180
+ puts " Total # of lines changed: #{v.total_lines}"
181
+ puts " # of inserts: #{v.total_inserts}"
182
+ puts " # of deletes: #{v.total_deletes}"
183
+ end
184
+ end
185
+ end
186
+
187
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitstatsakido
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lei Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-03 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Display code change stats for the current git repository by Author
56
+ email:
57
+ - lei@akidolabs.com
58
+ executables:
59
+ - gitstats
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".idea/.rakeTasks"
65
+ - ".idea/misc.xml"
66
+ - ".idea/modules.xml"
67
+ - ".idea/vcs.xml"
68
+ - ".rspec"
69
+ - ".travis.yml"
70
+ - CODE_OF_CONDUCT.md
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/gitstats
76
+ - bin/setup
77
+ - gitstats.gemspec
78
+ - lib/b.txt
79
+ - lib/gitstats.rb
80
+ - lib/gitstats/version.rb
81
+ homepage: http://www.akidolabs.com
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.4
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Display Git Coding Stats
105
+ test_files: []