contributor 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27981c96f17cd6d38c49ad821b0bb85a8edf16e2
4
+ data.tar.gz: 712a9eaac59128e730c3d95f6709ca12ccfe22ff
5
+ SHA512:
6
+ metadata.gz: c67ff6f9f63dce7f3a66cdc93a85b31a37ea6d20cd963c27ba9bf5fb2ae690515adea69dadeef7a983fae8b675ea652748384ff86e6a11f97b5f3521e7dbd3ca
7
+ data.tar.gz: 442e57ca1d02f762e3ef538f68f7374534127d9f53933be9afa95eb47c7dbd8032531be7dd8c29dea6b71b0fe91b77b92ae620228ac5030a80fe71ab1b3078c9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in contributor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 alpaca-tc
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Contributor
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/contributor`. 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 'contributor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install contributor
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 false` 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]/contributor.
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 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "contributor"
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/contributor ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path('./../../lib', __FILE__)
4
+ require 'contributor'
5
+
6
+ Contributor::Calc.run(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contributor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'contributor'
8
+ spec.version = Contributor::VERSION
9
+ spec.authors = ['alpaca-tc']
10
+ spec.email = ['alpaca-tc@alpaca.tc']
11
+
12
+ spec.summary = %q{Print detail of contribution}
13
+ spec.description = %q{Print detail of contribution}
14
+ spec.homepage = 'https://github.com/alpaca-tc/contributor'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'bin'
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
@@ -0,0 +1,14 @@
1
+ terms:
2
+ beginning_at: <%= Date.today.to_s %>
3
+ end_at: <%= (Date.today << 1).to_s %>
4
+
5
+
6
+ # authorの名前を記入する
7
+ # 例
8
+ # authors:
9
+ # alpaca-tc:
10
+ # alias:
11
+ # - Ishii Hiroyuki
12
+ # Yamada Taro: ~
13
+ # Yamada Yuuichi: ~
14
+ authors:
@@ -0,0 +1,24 @@
1
+ module Contributor
2
+ class Author
3
+ attr_reader :name
4
+
5
+ def initialize(name, options = nil)
6
+ options ||= {}
7
+
8
+ @name = name
9
+ @alias = if options['alias']
10
+ options['alias']
11
+ else
12
+ []
13
+ end
14
+ end
15
+
16
+ def alias_names
17
+ [@name] + @alias
18
+ end
19
+
20
+ def alias_names_for_git
21
+ alias_names.map { |v| v.gsub(/\s/, '\ ') }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ module Contributor
2
+ module Calc
3
+ class Commit
4
+ COMMAND = "git shortlog -s -n --since=%{beginning_at} --until=%{end_at}"
5
+
6
+ attr_reader :result
7
+
8
+ def initialize
9
+ @result = Hash.new { |h, k| h[k] = 0 }
10
+ end
11
+
12
+ def run
13
+ authors = Contributor.configuration.authors
14
+
15
+ execute_command.each do |name, count|
16
+ author = authors.find { |author| author.alias_names.include?(name) }
17
+ raise "Missing author configuration #{name}" unless author
18
+ @result[author] += count
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def execute_command
25
+ terms = Contributor.configuration.terms
26
+ command = sprintf(
27
+ COMMAND,
28
+ beginning_at: terms['beginning_at'].to_s,
29
+ end_at: terms['end_at'].to_s
30
+ )
31
+
32
+ list = `#{command}`.split("\n")
33
+ list.each_with_object({}) do |line, memo|
34
+ if /^\s*(?<count>\d+)\s*(?<name>.*)\s*$/ =~ line
35
+ memo[name] = count.to_i
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ module Contributor
2
+ module Calc
3
+ class Crease
4
+ COMMAND = {
5
+ additional: "git log --author='%{author}' --since=%{beginning_at} --until=%{end_at} --oneline --numstat --no-merges --pretty=format:"" | cut -f1 | awk 'BEGIN {sum=0} {sum+=$1} END {print sum}'",
6
+ deletional: "git log --author='%{author}' --since=%{beginning_at} --until=%{end_at} --oneline --numstat --no-merges --pretty=format:"" | cut -f2 | awk 'BEGIN {sum=0} {sum+=$1} END {print sum}'"
7
+ }.freeze
8
+
9
+ attr_reader :result
10
+
11
+ def initialize
12
+ @result = Hash.new { |h, k| h[k] = { additional: 0, deletional: 0 } }
13
+ end
14
+
15
+ def run
16
+ authors = Contributor.configuration.authors
17
+ terms = Contributor.configuration.terms
18
+
19
+ authors.each do |author|
20
+ author.alias_names_for_git.each do |name|
21
+ COMMAND.each do |key, command|
22
+ command = sprintf(
23
+ command,
24
+ author: name,
25
+ beginning_at: terms['beginning_at'].to_s,
26
+ end_at: terms['end_at'].to_s
27
+ )
28
+
29
+ @result[author][key] += `#{command}`.strip.to_i
30
+ end
31
+ end
32
+ end
33
+
34
+ @result.each do |author, values|
35
+ if values[:additional].zero? && values[:deletional].zero?
36
+ @result.delete(author)
37
+ else
38
+ @result[author] = "+#{values[:additional]}, -#{values[:deletional]}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ require 'contributor/calc/crease'
2
+ require 'contributor/calc/commit'
3
+
4
+ module Contributor
5
+ module Calc
6
+ def self.run(argv)
7
+ Contributor::OptionParser.new(argv).parse!
8
+ Contributor.configuration.load_configuration!
9
+
10
+ invoke(Calc::Crease)
11
+ invoke(Calc::Commit)
12
+ end
13
+
14
+ def self.invoke(klass)
15
+ calc = klass.new
16
+
17
+ Dir.chdir(Contributor.configuration.repository) do
18
+ calc.run
19
+ end
20
+
21
+ puts klass
22
+
23
+ calc.result.each do |author, values|
24
+ puts author.name
25
+ puts values
26
+ end
27
+
28
+ puts '---'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+
3
+ module Contributor
4
+ class Configuration < Hash
5
+ def load_configuration!
6
+ yaml = YAML.load_file(yaml_file)
7
+ self.authors = yaml['authors'].map { |key, values| Author.new(key, values) }
8
+ self.terms = yaml['terms']
9
+ end
10
+
11
+ def method_missing(action, *args)
12
+ if /^(?<method>.*)=$/ =~ action.to_s
13
+ self.send(:[]=, *([method] + args))
14
+ else
15
+ self[action.to_s] ||= self.class.new
16
+ self[action.to_s]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'optparse'
2
+ require 'erb'
3
+
4
+ module Contributor
5
+ class OptionParser
6
+ def initialize(argv)
7
+ @original_argv = argv
8
+ @argv = argv.dup
9
+ end
10
+
11
+ def parse!
12
+ option_parser.parse!(@argv)
13
+ end
14
+
15
+ def option_parser
16
+ @option_parser ||= ::OptionParser.new do |parser|
17
+ parser.on('--repository GIT REPOSITORY PATH', String) do |path|
18
+ Contributor.configuration.repository = path
19
+ end
20
+
21
+ parser.on('--configuration FILE', String) do |file|
22
+ Contributor.configuration.yaml_file = file
23
+ end
24
+
25
+ parser.on_tail('--init', 'Initialize configuration file') do
26
+ default = File.expand_path('../../../data/configuration.yml.default.erb', __FILE__)
27
+ result = ERB.new(File.read(default), 0, '<>-').result
28
+ File.write('configuration.yml', result)
29
+
30
+ puts 'Create configuration.yml!!'
31
+ exit
32
+ end
33
+
34
+ parser.on_tail('-h', '--help', 'Show this usage message and quit.') do |setting|
35
+ puts parser.help
36
+ exit
37
+ end
38
+
39
+ parser.on_tail('-v', '--version', 'Show version information about Contributor and quit.') do
40
+ puts "Contributor v#{Version}"
41
+ exit
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Contributor
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'contributor/version'
2
+ require 'contributor/author'
3
+ require 'contributor/option_parser'
4
+ require 'contributor/configuration'
5
+ require 'contributor/calc'
6
+
7
+ module Contributor
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contributor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - alpaca-tc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-28 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ description: Print detail of contribution
42
+ email:
43
+ - alpaca-tc@alpaca.tc
44
+ executables:
45
+ - console
46
+ - contributor
47
+ - setup
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - ".travis.yml"
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/contributor
59
+ - bin/setup
60
+ - contributor.gemspec
61
+ - data/configuration.yml.default.erb
62
+ - lib/contributor.rb
63
+ - lib/contributor/author.rb
64
+ - lib/contributor/calc.rb
65
+ - lib/contributor/calc/commit.rb
66
+ - lib/contributor/calc/crease.rb
67
+ - lib/contributor/configuration.rb
68
+ - lib/contributor/option_parser.rb
69
+ - lib/contributor/version.rb
70
+ homepage: https://github.com/alpaca-tc/contributor
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Print detail of contribution
94
+ test_files: []
95
+ has_rdoc: