ginbeer 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc7e7a9f18f0801013b8146a8cae19cc5ed8a7f6
4
+ data.tar.gz: 4013af2050047215aab5e4e98103abe462757a60
5
+ SHA512:
6
+ metadata.gz: 71d7f1515e41e31be88c098ec2ad3fe741c1d1927bcbf69e5b2b350aee6a30ca22c1d88c2fb3c417cbad27d1dde6c81967b776d3ff9505c4525dcc82e2b298f6
7
+ data.tar.gz: bd47036d53aa647379feda19bfa35446584089c707ab060d7255242d134ced6d15897704f7ad082a3a3201b0921cd7820ae13e094385321190b260adbe5184ff
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ginbeer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 henteko
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.
@@ -0,0 +1,29 @@
1
+ # Ginbeer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ginbeer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ginbeer
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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
+
6
+ require_relative '../lib/ginbeer'
7
+ require 'thor'
8
+
9
+ class Main < Thor
10
+ default_command :ranking
11
+
12
+ GRAF = "■"
13
+
14
+ desc 'ranking', 'show git authors ranking'
15
+ #option :dir, :type => :string, :aliases => '-d', :desc => "git dir"
16
+ option :from, :type => :string, :aliases => '-f', :desc => "from"
17
+ option :to, :type => :string, :aliases => '-t', :desc => "to"
18
+ option :count, :type => :string, :aliases => '-c', :desc => "ranking display count"
19
+ option :graf, :type => :boolean, :aliases => '-g', :desc => "display graf"
20
+ def ranking
21
+ dir = Dir.pwd
22
+ from = options[:from] || ""
23
+ to = options[:to] || ""
24
+ count = options[:count] || nil
25
+ graf_flag = options[:graf] || false
26
+
27
+ # main
28
+ gb = Ginbeer.new(dir, from, to)
29
+ authors = gb.authors
30
+
31
+ # sort!
32
+ authors.sort! do |a, b|
33
+ b.score <=> a.score
34
+ end
35
+
36
+ max = nil
37
+ authors.each_with_index do |author, i|
38
+ break if count != nil && i >= count.to_i
39
+ graf = nil
40
+ if max == nil
41
+ max = author.score
42
+ graf = 100
43
+ end
44
+ if graf == nil
45
+ graf = 100 * (author.score / max.to_f)
46
+ end
47
+
48
+ puts author.result
49
+ puts GRAF * graf if graf_flag
50
+ end
51
+ end
52
+ end
53
+
54
+ Main.start
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ginbeer/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "ginbeer"
8
+ gem.version = Ginbeer::VERSION
9
+ gem.authors = ["henteko"]
10
+ gem.email = ["henteko07@gmail.com"]
11
+ gem.description = %q{ginbeer is git authors display}
12
+ gem.summary = %q{ginbeer is git authots display}
13
+ gem.homepage = "https://github.com/henteko/ginbeer"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.executables << 'ginbeer'
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.add_dependency 'thor'
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'ginbeer/version'
2
+ require 'ginbeer/ginbeer'
@@ -0,0 +1,18 @@
1
+ class Author
2
+ attr_accessor :name, :commit_count, :insertion, :deletion
3
+
4
+ def initialize(name, commit_count)
5
+ @name = name
6
+ @commit_count = commit_count
7
+ @insertion = 0
8
+ @deletion = 0
9
+ end
10
+
11
+ def score
12
+ return @commit_count + @insertion + @deletion
13
+ end
14
+
15
+ def result
16
+ return "#{self.name}: #{self.score}(commits: #{self.commit_count}, insertion: #{self.insertion}, deletion: #{self.deletion})"
17
+ end
18
+ end
@@ -0,0 +1,74 @@
1
+ require 'time'
2
+ require File.expand_path(File.dirname(__FILE__) + '/author.rb')
3
+
4
+ class Ginbeer
5
+ def initialize(dir, from="", to=Time.now)
6
+ @dir = dir
7
+ @from = from
8
+ @from_d = nil
9
+ if @from != ""
10
+ @from_d = Time.parse(@from)
11
+ end
12
+ @to = to
13
+
14
+
15
+ # error handling
16
+ epath = File.expand_path(dir)
17
+ if File.exist?(File.join(epath, '.git'))
18
+ elsif File.exist?(epath) && (epath =~ /\.git$/)
19
+ elsif File.exist?(epath)
20
+ raise InvalidGitRepositoryError.new(epath)
21
+ else
22
+ raise NoSuchPathError.new(epath)
23
+ end
24
+ end
25
+
26
+ def authors
27
+ authors = []
28
+ commits = `#{self.shortlog_command}`
29
+ commits.each_line do |line|
30
+ line.chomp!
31
+ /\s*(\d+)\s(.+)/ =~ line
32
+
33
+ count = $1.to_i
34
+ name = $2
35
+ authors.push(Author.new(name, count))
36
+ end
37
+
38
+ authors.each do |author|
39
+ logs = `#{self.log_command(author)}`
40
+
41
+ logs.each_line do |line|
42
+ line.chomp!
43
+ if /file/ =~ line
44
+ /.*(\d+) insertion.*, (\d+) deletion/ =~ line
45
+ insertion = $1.to_i
46
+ deletion = $2.to_i
47
+
48
+ author.insertion += insertion
49
+ author.deletion += deletion
50
+ elsif /\[(.+)\]/ =~ line
51
+ data = $1
52
+ data = Time.parse(data)
53
+ break if @from_d != nil && data < @from_d # 終了
54
+ end
55
+ end
56
+ end
57
+ return authors
58
+ end
59
+
60
+ def cd_command
61
+ return "cd #{@dir} &&"
62
+ end
63
+
64
+ def shortlog_command
65
+ command = "#{self.cd_command} git shortlog -s --no-merges -n --before=#{@to}"
66
+ command += " --after=#{@from}" if @from != ""
67
+ return command
68
+ end
69
+
70
+ def log_command(author)
71
+ command = "#{self.cd_command} git log --pretty=format:'[%ad]' --shortstat --author='#{author.name}' --date=short --before=#{@to}"
72
+ return command
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ class Ginbeer
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ginbeer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - henteko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ginbeer is git authors display
28
+ email:
29
+ - henteko07@gmail.com
30
+ executables:
31
+ - ginbeer
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/ginbeer
41
+ - ginbeer.gemspec
42
+ - lib/ginbeer.rb
43
+ - lib/ginbeer/author.rb
44
+ - lib/ginbeer/ginbeer.rb
45
+ - lib/ginbeer/version.rb
46
+ homepage: https://github.com/henteko/ginbeer
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.7
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: ginbeer is git authots display
70
+ test_files: []