stefon 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +1 -1
- data/bin/stefon +4 -4
- data/lib/stefon/cli.rb +14 -7
- data/lib/stefon/surveyor/added_files.rb +1 -1
- data/lib/stefon/surveyor/added_lines.rb +2 -3
- data/lib/stefon/surveyor/deleted_files.rb +5 -5
- data/lib/stefon/surveyor/deleted_lines.rb +5 -4
- data/lib/stefon/surveyor/editor.rb +0 -1
- data/lib/stefon/surveyor/git_util.rb +4 -2
- data/lib/stefon/surveyor/grit_util.rb +23 -15
- data/lib/stefon/surveyor/surveyor.rb +3 -1
- data/lib/stefon/version.rb +2 -1
- data/spec/config_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/surveyor/editor_spec.rb +11 -9
- data/spec/surveyor/git_util_spec.rb +23 -22
- data/stefon.gemspec +11 -11
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NTJmYzhhZmE5NGQxYjllMmY0ZmQzM2U3OTMzOGM0ZTBjMGQ3MjlkNA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99ed35b6e8b0b48f9ba4059038361a137926a1c3
|
4
|
+
data.tar.gz: 3bcab6111636a36d3fd7436cf4f777f4cfc63de7
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
M2Y2NDg1OTNjNDM3MTM2YjlkZDYzYTgzZWU5NzdmNmRiZjFhOTAxOWJjMjBl
|
11
|
-
MDc0MGY3OTNjN2FmOWNhZWE3ZGM4MzgwZmZhMzM2OThjNTFhNWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NGE4MGQ4NWU1ODA2ZTQxOTExNzZhNjIxYTM0MTY3YTI2ODAyNGNiZjQwZDk2
|
14
|
-
ZDY4OWNhYWNkNDJiZDY4NGQ2ZTNkYTBjMWQyNDY0MTc0MTcxZTYxYmExYmUy
|
15
|
-
YTJmZjJlNGZkMzA3YTQ4NmMyMWUxOTE0ZTY3MjRlNTE1NzQxOTA=
|
6
|
+
metadata.gz: 40eca70e12bc892bbcee99cc785d0bb15171216902e3e5d5d62e3eb04f256a8e6eb96c628fd80a1f31dd2322f4bc4a4eb08491be834b85773b314bf05bd60cde
|
7
|
+
data.tar.gz: 43a61da24cd1a4c433eadf84d4a1e4d17fee58527b7a888e6d5cd735fa962164c01c31eea3e443c750f2b02eabda70b75e6edc1b8689f8ed3f1c62dac1affb28
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ which is identical to `stefon -f`, to see something like:
|
|
52
52
|
|
53
53
|
|
54
54
|
## Todos / Comming improvements
|
55
|
-
*
|
55
|
+
* use rugged instead of grit for ruby 2 support
|
56
56
|
* use Github API to get a list of contributors for a project (and filter suggestions)
|
57
57
|
* loading user preferences (list of users to exclude) - maybe with dotfiles instead of yml files
|
58
58
|
* handle errors from surveryors
|
data/bin/stefon
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
if RUBY_VERSION >= '1.9.2'
|
4
|
+
if RUBY_VERSION >= '1.9.2'
|
5
5
|
$LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
6
6
|
|
7
7
|
# test for presence of sed dependency
|
@@ -23,12 +23,12 @@ if RUBY_VERSION >= '1.9.2' && RUBY_VERSION < '2.0.0'
|
|
23
23
|
result = cli.run(opts)
|
24
24
|
end
|
25
25
|
|
26
|
-
puts "
|
27
|
-
header = '
|
26
|
+
puts "Stefon finished in #{time} seconds"
|
27
|
+
header = 'The hottest new people to ask for a code review from are:'
|
28
28
|
puts header unless opts[:full_report]
|
29
29
|
puts result
|
30
30
|
exit(0)
|
31
31
|
else
|
32
|
-
puts 'Stefon supports
|
32
|
+
puts 'Stefon only supports Ruby versions 1.9.2 and above'
|
33
33
|
exit(-1)
|
34
34
|
end
|
data/lib/stefon/cli.rb
CHANGED
@@ -13,6 +13,7 @@ module Stefon
|
|
13
13
|
|
14
14
|
# This module holds custom behavior for dealing with the gem trollop
|
15
15
|
module Options
|
16
|
+
# rubocop:disable MethodLength
|
16
17
|
def self.get
|
17
18
|
proc do
|
18
19
|
version "stefon #{Stefon::VERSION} (c) 2014 Ilya Kavalerov"
|
@@ -20,18 +21,24 @@ module Stefon
|
|
20
21
|
Stefon is a utilty that recommends who to ask for a code review.
|
21
22
|
He lets you know whose code you are affecting the most.
|
22
23
|
|
24
|
+
Run Stefon before a commit, maybe as a pre-commit hook.
|
25
|
+
|
23
26
|
Usage:
|
24
27
|
stefon [options]
|
25
28
|
where [options] are:
|
26
29
|
EOS
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
opt :limit,
|
31
|
+
'Limit the number of people that stephon suggests ' +
|
32
|
+
'sending a code review to',
|
33
|
+
default: 4,
|
34
|
+
short: '-l'
|
35
|
+
opt :full_report,
|
36
|
+
'Boolean for whether or not to include ' +
|
37
|
+
"information about how you affected someone's code",
|
38
|
+
default: false,
|
39
|
+
short: '-f'
|
34
40
|
end
|
35
41
|
end
|
42
|
+
# rubocop:enable MethodLength
|
36
43
|
end
|
37
44
|
end
|
@@ -21,9 +21,8 @@ module Stefon
|
|
21
21
|
def score_added_lines
|
22
22
|
# give credit to the most frequent commiter in the file
|
23
23
|
added_lines_by_file.each_pair do |filename, numlines|
|
24
|
-
blame =
|
25
|
-
top_author =
|
26
|
-
# multiplied by the number of lines that are added in the staged commit
|
24
|
+
blame = @grit.blame_for(filename)
|
25
|
+
top_author = @grit.file_valid_top_author(blame, filename)
|
27
26
|
@scores[top_author] += numlines
|
28
27
|
end
|
29
28
|
@scores
|
@@ -11,17 +11,17 @@ module Stefon
|
|
11
11
|
|
12
12
|
def call_verbose
|
13
13
|
array_version = score_deleted_files.to_a.map do |pair|
|
14
|
-
desc = "Deleted #{pair.last} #{pair.last == 1 ? 'file' : 'files' }
|
15
|
-
"written by: #{pair.first}"
|
14
|
+
desc = "Deleted #{pair.last} #{pair.last == 1 ? 'file' : 'files' }" +
|
15
|
+
" written by: #{pair.first}"
|
16
16
|
[pair.first, [desc]]
|
17
17
|
end
|
18
18
|
Surveyor::SurveyorStore[array_version]
|
19
19
|
end
|
20
20
|
|
21
21
|
def score_deleted_files
|
22
|
-
|
23
|
-
blame =
|
24
|
-
top_author =
|
22
|
+
@grit.repo.status.deleted.keys.each do |filename|
|
23
|
+
blame = @grit.blame_for(filename)
|
24
|
+
top_author = @grit.file_valid_top_author(blame, filename)
|
25
25
|
@scores[top_author] += 1
|
26
26
|
end
|
27
27
|
@scores
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Stefon
|
4
4
|
module Surveyor
|
5
|
+
# This class gives points to authors of lines that the user deletes
|
5
6
|
class DeletedLines < Surveyor::Base
|
6
7
|
def call
|
7
8
|
score_deleted_lines.weight_scores(@weight)
|
@@ -9,8 +10,8 @@ module Stefon
|
|
9
10
|
|
10
11
|
def call_verbose
|
11
12
|
array_version = score_deleted_lines.to_a.map do |pair|
|
12
|
-
desc = "Deleted #{pair.last} #{pair.last == 1 ? 'line' : 'lines' }
|
13
|
-
"written by: #{pair.first}"
|
13
|
+
desc = "Deleted #{pair.last} #{pair.last == 1 ? 'line' : 'lines' }" +
|
14
|
+
" written by: #{pair.first}"
|
14
15
|
[pair.first, [desc]]
|
15
16
|
end
|
16
17
|
Surveyor::SurveyorStore[array_version]
|
@@ -18,9 +19,9 @@ module Stefon
|
|
18
19
|
|
19
20
|
def score_deleted_lines
|
20
21
|
deleted_lines_by_file.each_pair do |filename, lines|
|
21
|
-
blame =
|
22
|
+
blame = @grit.blame_for(filename)
|
22
23
|
lines.each do |deleted_line|
|
23
|
-
valid_author =
|
24
|
+
valid_author = @grit.valid_line_author(blame, deleted_line)
|
24
25
|
@scores[valid_author] += 1 if valid_author
|
25
26
|
end
|
26
27
|
end
|
@@ -22,7 +22,7 @@ module Stefon
|
|
22
22
|
# none for all looks at a diff, optionally matches lines starting
|
23
23
|
# with mode char, cut off first char of each line
|
24
24
|
%x(git diff HEAD~#{GritUtil.new.num_sui_commits} -U0 |
|
25
|
-
#{mode ? "grep ^#{mode} | " :
|
25
|
+
#{mode ? "grep ^#{mode} | " : ''} sed 's/^.//'
|
26
26
|
).split("\n").map(&:strip)
|
27
27
|
end
|
28
28
|
|
@@ -39,7 +39,9 @@ module Stefon
|
|
39
39
|
git_diff_as_array.each_with_index do |e, i|
|
40
40
|
line, lines_ahead = e, 1
|
41
41
|
# if the line is a filename, we want it to point to its lines
|
42
|
-
while (line[0..1] == filename_marker) &&
|
42
|
+
while (line[0..1] == filename_marker) &&
|
43
|
+
(i + lines_ahead < git_diff_as_array.length)
|
44
|
+
|
43
45
|
next_line = git_diff_as_array[i + lines_ahead]
|
44
46
|
# next_lines should not be filenames
|
45
47
|
break if next_line[0..1] == filename_marker
|
@@ -4,27 +4,35 @@ require 'grit'
|
|
4
4
|
|
5
5
|
module Stefon
|
6
6
|
module Surveyor
|
7
|
-
# A class that abstracts dealing with the grit gem while
|
8
|
-
# restrictions, namely excluding authors
|
7
|
+
# A class that abstracts dealing with the grit gem while
|
8
|
+
# respecting/knowing some restrictions, namely excluding authors
|
9
9
|
class GritUtil
|
10
|
-
attr_reader :repo
|
10
|
+
attr_reader :repo
|
11
|
+
# The number of commits by the user (sui ~ self / origin).
|
12
|
+
# This is important to take into account when the user makes multiple
|
13
|
+
# commits when working on someone else's project, to ensure that diffs
|
14
|
+
# do not include recent changes made by the user in her last few commits
|
15
|
+
attr_reader :num_sui_commits
|
16
|
+
# The last commit not made by the user (sui ~ self) but by another
|
17
|
+
# person (xeno ~ not self / not origin).
|
18
|
+
# This is important to take into account when the user makes multiple
|
19
|
+
# commits when working on someone else's project, to ensure that diffs
|
20
|
+
# do not include recent changes made by the user in her last few commits
|
21
|
+
attr_reader :last_xenocommit
|
11
22
|
|
12
23
|
include Config::ExcludedAuthors
|
13
24
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# user (sui ~ self / origin) should be taken into account when calling
|
19
|
-
# a diff, so as to compare changes against the last commit not made by
|
20
|
-
# the user (self), but by another person (xeno ~ not self / not origin)
|
25
|
+
# sets num_sui_commits and last_xenocommit attributes, if the current
|
26
|
+
# user is the only commiter in the repo, these are set to the most
|
27
|
+
# recent commit, since in this case, stefon would always recommend
|
28
|
+
# the current user anyway. In the future, an error may be raised here
|
21
29
|
def initialize
|
22
30
|
@repo = Grit::Repo.new('.')
|
23
31
|
commits = @repo.commits(GitUtil::CURRENT_BRANCH)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@num_sui_commits
|
32
|
+
@num_sui_commits = commits.find_index do |commit|
|
33
|
+
commit.author.name != @repo.config['user.name']
|
34
|
+
end
|
35
|
+
@num_sui_commits ||= 0
|
28
36
|
@last_xeno_commit = commits[@num_sui_commits]
|
29
37
|
end
|
30
38
|
|
@@ -33,7 +41,7 @@ module Stefon
|
|
33
41
|
end
|
34
42
|
|
35
43
|
def valid_line_author(blame, line)
|
36
|
-
matched_line = blame.lines.
|
44
|
+
matched_line = blame.lines.find { |l| l.line.strip == line }
|
37
45
|
author = matched_line.commit.author.name if matched_line
|
38
46
|
author if valid?(author)
|
39
47
|
end
|
data/lib/stefon/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Stefon::Config do
|
|
21
21
|
|
22
22
|
context 'with github enabled' do
|
23
23
|
describe 'merging configurations' do
|
24
|
-
it 'ensures github
|
24
|
+
it 'ensures user github config takes prescedence over user yml config'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe 'Editor' do
|
6
|
-
let(:options)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
let(:options) do
|
7
|
+
{
|
8
|
+
limit: 4,
|
9
|
+
deleted_line: 2,
|
10
|
+
deleted_file: 4,
|
11
|
+
added_line: 1,
|
12
|
+
added_file: 1
|
13
|
+
}
|
14
|
+
end
|
13
15
|
|
14
16
|
describe 'summarize results (integration)' do
|
15
17
|
before(:each) do
|
@@ -45,8 +47,8 @@ describe 'Editor' do
|
|
45
47
|
options[:full_report] = true
|
46
48
|
editor = Stefon::Editor.new(options)
|
47
49
|
results = editor.summarize_results
|
48
|
-
results.
|
49
|
-
results.
|
50
|
+
results.should include('Deleted 4 lines by Cy Twombly')
|
51
|
+
results.should include('Deleted 2 lines by Christian Boltanski')
|
50
52
|
results.each do |reported_result|
|
51
53
|
unless reported_result =~ /The top commiter in this repo is/
|
52
54
|
reported_result.should =~ /\d/
|
@@ -4,29 +4,30 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Stefon::Surveyor::GitUtil do
|
6
6
|
describe '#lines_by_file' do
|
7
|
-
let(:git_diff_as_array)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"end"
|
19
|
-
]}
|
20
|
-
let(:right_structure) {{
|
21
|
-
"lib/stefon/surveyor/git_util.rb" => ["block.call(line, next_line)"],
|
22
|
-
"lib/stefon/surveyor/grit_util.rb" => ["repo.blame(filename, @last_xenocommit)"],
|
23
|
-
"spec/surveyor/git_util_spec.rb" => [
|
24
|
-
"describe Stefon::Surveyor::GitUtil do",
|
25
|
-
"describe '#lines_by_file' do",
|
26
|
-
"it 'correctly yields lines belonging to files'",
|
27
|
-
"end"
|
7
|
+
let(:git_diff_as_array) do
|
8
|
+
[
|
9
|
+
'-- a/bin/stefon',
|
10
|
+
'-- a/lib/stefon/surveyor/deleted_lines.rb',
|
11
|
+
'-- a/lib/stefon/surveyor/git_util.rb',
|
12
|
+
'block.call(line, next_line)',
|
13
|
+
'-- a/spec/surveyor/git_util_spec.rb',
|
14
|
+
'describe Stefon::Surveyor::GitUtil do',
|
15
|
+
'describe "#lines_by_file" do',
|
16
|
+
'it "correctly yields lines belonging to files"',
|
17
|
+
'end'
|
28
18
|
]
|
29
|
-
|
19
|
+
end
|
20
|
+
let(:right_structure) do
|
21
|
+
{
|
22
|
+
'lib/stefon/surveyor/git_util.rb' => ['block.call(line, next_line)'],
|
23
|
+
'spec/surveyor/git_util_spec.rb' => [
|
24
|
+
'describe Stefon::Surveyor::GitUtil do',
|
25
|
+
'describe "#lines_by_file" do',
|
26
|
+
'it "correctly yields lines belonging to files"',
|
27
|
+
'end'
|
28
|
+
]
|
29
|
+
}
|
30
|
+
end
|
30
31
|
let(:save_structure) { Hash.new([]) }
|
31
32
|
let(:block) { ->(filename, line) { save_structure[filename] += [line] } }
|
32
33
|
|
data/stefon.gemspec
CHANGED
@@ -5,26 +5,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'stefon/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'stefon'
|
9
9
|
spec.version = Stefon::VERSION
|
10
10
|
spec.platform = Gem::Platform::RUBY
|
11
|
-
spec.authors = [
|
12
|
-
spec.email = [
|
11
|
+
spec.authors = ['Ilya Kavalerov']
|
12
|
+
spec.email = ['ilya@artsymail.com']
|
13
13
|
spec.description = <<-EOF
|
14
|
-
A utility that recommends who to ask for a code review.
|
14
|
+
A pre-commit utility that recommends who to ask for a code review.
|
15
15
|
Stefon tells you whose code you are affecting the most.
|
16
16
|
EOF
|
17
17
|
spec.summary = %q{A utility that recommends who to ask for a code review}
|
18
|
-
spec.homepage =
|
19
|
-
spec.license =
|
18
|
+
spec.homepage = 'https://github.com/ilyakava/stefon'
|
19
|
+
spec.license = 'MIT'
|
20
20
|
|
21
21
|
spec.files = `git ls-files`.split($/)
|
22
22
|
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
23
23
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_runtime_dependency
|
27
|
-
spec.add_runtime_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
26
|
+
spec.add_runtime_dependency 'gitlab-grit', '1.0.0'
|
27
|
+
spec.add_runtime_dependency 'trollop', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
29
|
+
spec.add_development_dependency('rake', '~> 10.1')
|
30
30
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stefon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Kavalerov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: grit
|
14
|
+
name: gitlab-grit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: trollop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,18 +56,19 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '10.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
description:
|
70
|
-
|
68
|
+
version: '10.1'
|
69
|
+
description: |2
|
70
|
+
A pre-commit utility that recommends who to ask for a code review.
|
71
|
+
Stefon tells you whose code you are affecting the most.
|
71
72
|
email:
|
72
73
|
- ilya@artsymail.com
|
73
74
|
executables:
|
@@ -111,17 +112,17 @@ require_paths:
|
|
111
112
|
- lib
|
112
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
114
|
requirements:
|
114
|
-
- -
|
115
|
+
- - '>='
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: '0'
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
|
-
- -
|
120
|
+
- - '>='
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.1
|
125
|
+
rubygems_version: 2.2.1
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: A utility that recommends who to ask for a code review
|