contributors 0.1.2 → 0.2
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.
- data/CHANGELOG +7 -0
- data/README.textile +15 -9
- data/contributors.gemspec +5 -2
- data/lib/contributors.nake +8 -9
- data/lib/contributors.rb +39 -46
- data/tasks.rb +1 -1
- metadata +18 -7
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= Version 0.2
|
2
|
+
* Rewritten using Grit.
|
3
|
+
* Ignored patterns don't work anymore.
|
4
|
+
* Contributors#results takes the criterium for counting
|
5
|
+
lines of code as the second argument. It can be either
|
6
|
+
:additions, :deletions or :total, which is the default value.
|
7
|
+
|
1
8
|
= Version 0.1
|
2
9
|
* The actual library.
|
3
10
|
* Nake tasks for generating CONTRIBUTORS.
|
data/README.textile
CHANGED
@@ -17,13 +17,19 @@ require "contributors"
|
|
17
17
|
|
18
18
|
contributors = Contributors.new
|
19
19
|
contributors.results
|
20
|
-
# => {"stastny@101ideas.cz" => {:
|
20
|
+
# => {#<Grit::Actor "Jakub Stastny aka botanicus <stastny@101ideas.cz>"> => {:commits => 9, :LOC => 255}}
|
21
21
|
|
22
|
-
# You can optionally specify project path
|
23
|
-
contributors = Contributors.new(Dir.pwd
|
22
|
+
# You can optionally specify project path thusly:
|
23
|
+
contributors = Contributors.new(Dir.pwd)
|
24
24
|
|
25
|
-
# The Contributors#result method takes an optional argument
|
26
|
-
|
25
|
+
# The Contributors#result method takes an optional argument
|
26
|
+
# determining by which field you want to sort the results:
|
27
|
+
contributors.results(:LOC) # or :commits
|
28
|
+
|
29
|
+
# By default it takes all the changes (as the second argument
|
30
|
+
# defaults to :total), but if you want, you can limit changes
|
31
|
+
# on :additions or :deletions only:
|
32
|
+
contributors.results(:LOC, :additions)
|
27
33
|
</pre>
|
28
34
|
|
29
35
|
Use the "Nake":https://github.com/botanicus/nake tasks:
|
@@ -42,11 +48,11 @@ Task[:contributors].config[:output_path] = Proc.new { File.join(task.config[:pat
|
|
42
48
|
# OPTIONAL: How to sort results, options are :commits or :LOC, :LOC is default.
|
43
49
|
Task[:contributors].config[:sort_by] = :LOC
|
44
50
|
|
45
|
-
# OPTIONAL:
|
46
|
-
#
|
47
|
-
Task[:contributors].config[:
|
51
|
+
# OPTIONAL: Criterium for counting lines of code. Can be either
|
52
|
+
# :additions, :deletions or :total (which is the default value).
|
53
|
+
Task[:contributors].config[:criterium] = :total
|
48
54
|
|
49
55
|
# OPTIONAL: How to format each line. E-mail is author's e-mail and in data
|
50
56
|
there are keys :name, :commits and :LOC. Commits and LOC are both integers.
|
51
|
-
Task[:contributors].config[:format] = -> { |
|
57
|
+
Task[:contributors].config[:format] = -> { |author, data| "#{author.email}: #{data[:LOC]}" }
|
52
58
|
</pre>
|
data/contributors.gemspec
CHANGED
@@ -5,9 +5,9 @@ require "base64"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "contributors"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2"
|
9
9
|
s.authors = ["Jakub Stastny aka botanicus"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://github.com/botanicus/contributors"
|
11
11
|
s.summary = "API for getting info about contributors of a project which is in Git."
|
12
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
13
|
s.cert_chain = nil
|
@@ -33,6 +33,9 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.post_install_message = CHANGELOG.new.version_changes
|
34
34
|
end
|
35
35
|
|
36
|
+
# Dependencies
|
37
|
+
s.add_dependency "grit"
|
38
|
+
|
36
39
|
# RubyForge
|
37
40
|
s.rubyforge_project = "contributors"
|
38
41
|
end
|
data/lib/contributors.nake
CHANGED
@@ -6,9 +6,9 @@ Task.new(:contributors) do |task|
|
|
6
6
|
# Settings.
|
7
7
|
task.config[:path] = Dir.pwd
|
8
8
|
task.config[:output_path] = Proc.new { File.join(task.config[:path], "CONTRIBUTORS") }
|
9
|
-
task.config[:ignore] = nil
|
10
9
|
task.config[:sort_by] = :LOC
|
11
|
-
task.config[:
|
10
|
+
task.config[:criterium] = :total
|
11
|
+
task.config[:format] = Proc.new { |author, data| "#{author.name}: #{data[:commits]} commits, #{data[:LOC]} LOC" }
|
12
12
|
|
13
13
|
# Helpers.
|
14
14
|
def task.output_path
|
@@ -19,21 +19,20 @@ Task.new(:contributors) do |task|
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def task.ignored_patterns
|
23
|
-
self.config[:ignore] || Contributors::IGNORED_PATTERNS
|
24
|
-
end
|
25
|
-
|
26
22
|
# Define the actual task.
|
27
23
|
task.define do
|
28
24
|
require "contributors"
|
29
25
|
|
30
26
|
Dir.chdir(task.config[:path]) do
|
31
|
-
contributors = Contributors.new(task.config[:path]
|
27
|
+
contributors = Contributors.new(task.config[:path])
|
32
28
|
|
33
29
|
# Write the actual CONTRIBUTORS file.
|
34
30
|
File.open(task.output_path, "w") do |file|
|
35
|
-
|
36
|
-
|
31
|
+
sort_by = self.config[:sort_by]
|
32
|
+
criterium = self.config[:criterium]
|
33
|
+
|
34
|
+
contributors.results(sort_by, criterium).each do |author, data|
|
35
|
+
file.puts(task.config[:format].call(author, data))
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
data/lib/contributors.rb
CHANGED
@@ -1,65 +1,58 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require "grit"
|
4
|
+
|
4
5
|
class Contributors
|
5
|
-
|
6
|
+
attr_reader :path
|
7
|
+
def initialize(path = Dir.pwd)
|
8
|
+
@path = path
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
@path, @ignored_patterns = path, ignored_patterns
|
11
|
+
def repo
|
12
|
+
@repo ||= Grit::Repo.new(@path)
|
10
13
|
end
|
11
14
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
results[email][:commits] ||= 0
|
21
|
-
results[email][:commits] += 1
|
22
|
-
results[email][:LOC] = loc[email] || 0
|
23
|
-
results
|
24
|
-
end
|
15
|
+
def authors_and_commits
|
16
|
+
hash = Hash.new { |hash, key| hash[key] = Array.new }
|
17
|
+
repo.commits("master", false).reduce(hash) do |buffer, commit|
|
18
|
+
key = buffer.keys.find { |author| author.email == commit.author.email }
|
19
|
+
key ||= commit.author
|
20
|
+
|
21
|
+
buffer[key] << commit
|
22
|
+
buffer
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# ["additions", "deletions", "total"]
|
27
|
+
def list(criterium = :total)
|
28
|
+
unless [:additions, :deletions, :total].include?(criterium)
|
29
|
+
raise ArgumentError.new("Criterium can be one of: :additions, :deletions or :total.")
|
31
30
|
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
authors_and_commits.reduce(Hash.new) do |buffer, pair|
|
33
|
+
author, commits = pair
|
34
|
+
buffer[author] = {
|
35
|
+
commits: commits.length,
|
36
|
+
LOC: commits.reduce(0) do |lines, commit|
|
37
|
+
lines + commit.stats.to_hash[criterium.to_s]
|
38
|
+
end
|
39
|
+
}
|
40
40
|
|
41
|
-
|
42
|
-
files = %x{git ls-files}.split("\n")
|
43
|
-
files.select do |path|
|
44
|
-
self.ignored_patterns.any? do |pattern|
|
45
|
-
not path.match(pattern)
|
46
|
-
end
|
41
|
+
buffer
|
47
42
|
end
|
48
43
|
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
files.reduce(Hash.new) do |buffer, path|
|
55
|
-
emails = %x{git blame '#{path}' --show-email | awk '{ print $2 }' | ruby -pe '$_.sub!(/^.*<(.+)>.*$/, "\\\\1")'}
|
56
|
-
emails.split("\n").each do |email|
|
57
|
-
buffer[email] ||= 0
|
58
|
-
buffer[email] += 1
|
59
|
-
end
|
45
|
+
def results(sort_by = :LOC, criterium = :total)
|
46
|
+
unless [:commits, :LOC].include?(sort_by)
|
47
|
+
raise "Sort_by argument can be only :commits or :LOC!"
|
48
|
+
end
|
60
49
|
|
61
|
-
|
62
|
-
|
50
|
+
# Note: Hash#sort_by(&block) returns an Array, even on 1.9,
|
51
|
+
# which isn't really necessary, as hashes on 1.9 are sorted.
|
52
|
+
sorted_array = self.list(criterium).sort_by { |_, data| data[sort_by] }
|
53
|
+
sorted_array.reverse.reduce(Hash.new) do |buffer, pair|
|
54
|
+
author, stats = pair
|
55
|
+
buffer.merge(author => stats)
|
63
56
|
end
|
64
57
|
end
|
65
58
|
end
|
data/tasks.rb
CHANGED
@@ -5,4 +5,4 @@ $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
|
5
5
|
|
6
6
|
load "contributors.nake"
|
7
7
|
|
8
|
-
Task[:contributors].config[:format] = Proc.new { |
|
8
|
+
Task[:contributors].config[:format] = Proc.new { |author, data| "#{author.inspect}: #{data.inspect}" }
|
metadata
CHANGED
@@ -2,17 +2,27 @@
|
|
2
2
|
name: contributors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: "0.2"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jakub Stastny aka botanicus
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-05-02 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: grit
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
16
26
|
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
27
|
email: stastny@101ideas.cz
|
18
28
|
executables: []
|
@@ -31,11 +41,12 @@ files:
|
|
31
41
|
- lib/contributors.rb
|
32
42
|
- tasks.rb
|
33
43
|
has_rdoc: true
|
34
|
-
homepage:
|
44
|
+
homepage: https://github.com/botanicus/contributors
|
35
45
|
licenses: []
|
36
46
|
|
37
|
-
post_install_message: "[\e[32mVersion 0.
|
38
|
-
[\e[32mVersion 0.
|
47
|
+
post_install_message: "[\e[32mVersion 0.2\e[0m] Rewritten using Grit.\n\
|
48
|
+
[\e[32mVersion 0.2\e[0m] Ignored patterns don't work anymore.\n\
|
49
|
+
[\e[32mVersion 0.2\e[0m] Contributors#results takes the criterium for counting lines of code as the second argument. It can be either :additions, :deletions or :total, which is the default value.\n"
|
39
50
|
rdoc_options: []
|
40
51
|
|
41
52
|
require_paths:
|