contributors 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +3 -0
- data/LICENSE +20 -0
- data/README.textile +42 -0
- data/contributors.gemspec +38 -0
- data/lib/contributors.nake +41 -0
- data/lib/contributors.rb +66 -0
- data/tasks.rb +8 -0
- metadata +63 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.rvmrc
|
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jakub Stastny aka botanicus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
h1. About
|
2
|
+
|
3
|
+
The contributors gem is useful for getting informations about project contributors. It assumes that Git is used. In particular it can be used for generating CONTRIBUTORS file.
|
4
|
+
|
5
|
+
h1. Usage
|
6
|
+
|
7
|
+
Just install it through RubyGems:
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
gem install contributors
|
11
|
+
</pre>
|
12
|
+
|
13
|
+
Use the API:
|
14
|
+
|
15
|
+
<pre>
|
16
|
+
require "contributors"
|
17
|
+
</pre>
|
18
|
+
|
19
|
+
Use the "Nake":https://github.com/botanicus/nake tasks:
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
load "contributors.nake"
|
23
|
+
|
24
|
+
# OPTIONAL: Where the project is located. Defaults to Dir.pwd.
|
25
|
+
Task[:contributors].config[:path] = Dir.pwd
|
26
|
+
|
27
|
+
# OPTIONAL: Where the CONTRIBUTORS file is located.
|
28
|
+
# It can be either a string or a callable object. Defaults to:
|
29
|
+
# Proc.new { File.join(task.config[:path], "CONTRIBUTORS") }
|
30
|
+
Task[:contributors].config[:output_path] = Proc.new { File.join(task.config[:path], "CONTRIBUTORS") }
|
31
|
+
|
32
|
+
# OPTIONAL: How to sort results, options are :commits or :LOC, :LOC is default.
|
33
|
+
Task[:contributors].config[:sort_by] = :LOC
|
34
|
+
|
35
|
+
# OPTIONAL: An array of regular expressions which should be ignored.
|
36
|
+
# Defaults to Contributors::IGNORED_PATTERNS, which is [/^vendor\//, /^gems\//, /.+\.gem$/].
|
37
|
+
Task[:contributors].config[:ignore] = Contributors::IGNORED_PATTERNS
|
38
|
+
|
39
|
+
# OPTIONAL: How to format each line. E-mail is author's e-mail and in data
|
40
|
+
there are keys :name, :commits and :LOC. Commits and LOC are both integers.
|
41
|
+
Task[:contributors].config[:format] = -> { |email, data| "#{email}: #{data[:LOC]}" }
|
42
|
+
</pre>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "contributors"
|
8
|
+
s.version = "0.1"
|
9
|
+
s.authors = ["Jakub Stastny aka botanicus"]
|
10
|
+
s.homepage = "http://github.com/botanicus/contributors"
|
11
|
+
s.summary = "API for getting info about contributors of a project which is in Git."
|
12
|
+
s.description = "The contributors gem is useful for getting informations about project contributors. It assumes that Git is used. In particular it can be used for generating CONTRIBUTORS file."
|
13
|
+
s.cert_chain = nil
|
14
|
+
s.email = Base64.decode64("c3Rhc3RueUAxMDFpZGVhcy5jeg==\n")
|
15
|
+
s.has_rdoc = true
|
16
|
+
|
17
|
+
# files
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# Ruby version
|
23
|
+
# Current JRuby with --1.9 switch has RUBY_VERSION set to "1.9.2dev"
|
24
|
+
# and RubyGems don't play well with it, so we have to set minimal
|
25
|
+
# Ruby version to 1.9, even if it actually is 1.9.1
|
26
|
+
s.required_ruby_version = ::Gem::Requirement.new("~> 1.9")
|
27
|
+
|
28
|
+
begin
|
29
|
+
require "changelog"
|
30
|
+
rescue LoadError
|
31
|
+
warn "You have to have changelog gem installed for post install message"
|
32
|
+
else
|
33
|
+
s.post_install_message = CHANGELOG.new.version_changes
|
34
|
+
end
|
35
|
+
|
36
|
+
# RubyForge
|
37
|
+
s.rubyforge_project = "contributors"
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Task.new(:contributors) do |task|
|
4
|
+
task.description = "Regenerate contributors file."
|
5
|
+
|
6
|
+
# Settings.
|
7
|
+
task.config[:path] = Dir.pwd
|
8
|
+
task.config[:output_path] = Proc.new { File.join(task.config[:path], "CONTRIBUTORS") }
|
9
|
+
task.config[:ignore] = nil
|
10
|
+
task.config[:sort_by] = :LOC
|
11
|
+
task.config[:format] = Proc.new { |email, data| "#{data[:name]}: #{data[:commits]} (#{data[:LOC]} LOC)" }
|
12
|
+
|
13
|
+
# Helpers.
|
14
|
+
def task.output_path
|
15
|
+
if self.config[:output_path].respond_to?(:call)
|
16
|
+
self.config[:output_path].call
|
17
|
+
else
|
18
|
+
self.config[:output_path]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def task.ignored_patterns
|
23
|
+
self.config[:ignore] || Contributors::IGNORED_PATTERNS
|
24
|
+
end
|
25
|
+
|
26
|
+
# Define the actual task.
|
27
|
+
task.define do
|
28
|
+
require "contributors"
|
29
|
+
|
30
|
+
Dir.chdir(task.config[:path]) do
|
31
|
+
contributors = Contributors.new(task.config[:path], task.ignored_patterns)
|
32
|
+
|
33
|
+
# Write the actual CONTRIBUTORS file.
|
34
|
+
File.open(task.output_path, "w") do |file|
|
35
|
+
contributors.results.each do |email, data|
|
36
|
+
file.puts(task.config[:format].call(email, data))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/contributors.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# TODO: Use Grit or something rather than this black magic.
|
4
|
+
class Contributors
|
5
|
+
IGNORED_PATTERNS = [/^vendor\//, /^gems\//, /.+\.gem$/]
|
6
|
+
|
7
|
+
attr_reader :path, :ignored_patterns
|
8
|
+
def initialize(path = Dir.pwd, ignored_patterns = IGNORED_PATTERNS)
|
9
|
+
@path, @ignored_patterns = path, ignored_patterns
|
10
|
+
end
|
11
|
+
|
12
|
+
def list
|
13
|
+
repo do
|
14
|
+
authors = %x{git log | grep ^Author:}.split("\n")
|
15
|
+
results = authors.reduce(Hash.new) do |results, line|
|
16
|
+
line.match(/^Author: (.+) <(.+)>$/)
|
17
|
+
name, email = $1, $2
|
18
|
+
results[email] ||= Hash.new
|
19
|
+
results[email][:name] = name
|
20
|
+
results[email][:commits] ||= 0
|
21
|
+
results[email][:commits] += 1
|
22
|
+
results[email][:LOC] = loc[email]
|
23
|
+
p loc
|
24
|
+
results
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def results(sort_by = :LOC)
|
30
|
+
unless [:commits, :LOC].include?(sort_by)
|
31
|
+
raise "Sort_by argument can be only :commits or :LOC!"
|
32
|
+
end
|
33
|
+
|
34
|
+
self.list.sort_by { |_, data| data[sort_by] }.reverse
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def repo(&block)
|
39
|
+
Dir.chdir(@path, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def files
|
43
|
+
files = %x{git ls-files}.split("\n")
|
44
|
+
files.select do |path|
|
45
|
+
self.ignored_patterns.any? do |pattern|
|
46
|
+
not path.match(pattern)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO: At the moment this are any lines, not lines of code.
|
52
|
+
# {email_1 => LOC for email_1, email_2 => LOC for email_2}
|
53
|
+
def loc
|
54
|
+
@loc ||= begin
|
55
|
+
files.reduce(Hash.new) do |buffer, path|
|
56
|
+
emails = %x{git blame '#{path}' --show-email | awk '{ print $2 }' | ruby -pe '$_.sub!(/^.*<(.+)>.*$/, "\\\\1")'}
|
57
|
+
emails.split("\n").each do |email|
|
58
|
+
buffer[email] ||= 0
|
59
|
+
buffer[email] += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
buffer
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/tasks.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contributors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.1"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jakub Stastny aka botanicus
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
date: 2011-03-07 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: The contributors gem is useful for getting informations about project contributors. It assumes that Git is used. In particular it can be used for generating CONTRIBUTORS file.
|
17
|
+
email: stastny@101ideas.cz
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- CHANGELOG
|
27
|
+
- LICENSE
|
28
|
+
- README.textile
|
29
|
+
- contributors.gemspec
|
30
|
+
- lib/contributors.nake
|
31
|
+
- lib/contributors.rb
|
32
|
+
- tasks.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/botanicus/contributors
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message: "[\e[32mVersion 0.1\e[0m] The actual library.\n\
|
38
|
+
[\e[32mVersion 0.1\e[0m] Nake tasks for generating CONTRIBUTORS.\n"
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "1.9"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: contributors
|
58
|
+
rubygems_version: 1.5.3
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: API for getting info about contributors of a project which is in Git.
|
62
|
+
test_files: []
|
63
|
+
|