Skip to content

Commit

Permalink
Merge pull request #91 from jhass/ghpr_find_in_full_diff
Browse files Browse the repository at this point in the history
Pull request formatter: Find position in full diff and fix commit_id
  • Loading branch information
mmozuras committed Sep 20, 2015
2 parents a8d5928 + 4643281 commit 0a21098
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.run(commit = 'master', repo_path = '.',

result = run_all_runners(patches)

formatted = formatter.format(result, repo)
formatted = formatter.format(result, repo, patches)
puts formatted if formatted

result
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/checkstyle_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize
@output = ''
end

def format(messages, _)
def format(messages, _, _)
open_xml
process_messages(messages)
close_xml
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/github_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pronto
module Formatter
class GithubFormatter
def format(messages, repo)
def format(messages, repo, _)
messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }
client = Github.new(repo)

Expand Down
15 changes: 4 additions & 11 deletions lib/pronto/formatter/github_pull_request_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
module Pronto
module Formatter
class GithubPullRequestFormatter
def format(messages, repo)
def format(messages, repo, patches)
messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }
client = Github.new(repo)
head = repo.head_commit_sha

commit_messages = messages.map do |message|
body = message.msg
path = message.path
line = patches.find_line(message.full_path, message.line.new_lineno)

commits = repo.commits_until(message.commit_sha)

line = nil
sha = commits.find do |commit|
patches = repo.show_commit(commit)
line = patches.find_line(message.full_path, message.line.new_lineno)
line
end

create_comment(client, sha, body, path, line.position)
create_comment(client, head, body, path, line.position)
end

"#{commit_messages.compact.count} Pronto messages posted to GitHub"
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/gitlab_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pronto
module Formatter
class GitlabFormatter
def format(messages, repo)
def format(messages, repo, _)
messages = messages.uniq { |message| [message.msg, message.line.new_lineno] }
client = Gitlab.new repo

Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Pronto
module Formatter
class JsonFormatter
def format(messages, _)
def format(messages, _, _)
messages.map do |message|
lineno = message.line.new_lineno if message.line

Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/null_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pronto
module Formatter
class NullFormatter
def format(_, _)
def format(_, _, _)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/text_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pronto
module Formatter
class TextFormatter
def format(messages, _)
def format(messages, _, _)
messages.map do |message|
level = message.level[0].upcase
line = message.line
Expand Down
4 changes: 4 additions & 0 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def remote_urls
@repo.remotes.map(&:url)
end

def head_commit_sha
head.oid
end

private

def empty_patches(sha)
Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/checkstyle_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, nil) }
subject { formatter.format(messages, nil, nil) }
let(:line) { double(new_lineno: 1, commit_sha: '123') }
let(:error) { Message.new('path/to', line, :error, 'Line Error') }
let(:warning) { Message.new('path/to', line, :warning, 'Line Warning') }
Expand Down
4 changes: 2 additions & 2 deletions spec/pronto/formatter/github_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, repo) }
subject { formatter.format(messages, repo, nil) }
let(:messages) { [message, message] }
let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
Expand All @@ -28,7 +28,7 @@ module Formatter
end

describe '#format without duplicates' do
subject { formatter.format(messages, repo) }
subject { formatter.format(messages, repo, nil) }
let(:messages) { [message1, message2] }
let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:message1) { Message.new('path/to1', line1, :warning, 'crucial') }
Expand Down
3 changes: 2 additions & 1 deletion spec/pronto/formatter/github_pull_request_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ module Formatter
let(:repo) { Git::Repository.new('spec/fixtures/test.git') }

describe '#format' do
subject { formatter.format(messages, repo) }
subject { formatter.format(messages, repo, patches) }
let(:messages) { [message, message] }
let(:message) { Message.new(patch.new_file_full_path, line, :warning, 'crucial') }
let(:patch) { repo.show_commit('64dadfd').first }
let(:line) { patch.added_lines.first }
let(:patches) { repo.diff('64dadfd^') }

specify do
ENV['PULL_REQUEST_ID'] = '10'
Expand Down
4 changes: 2 additions & 2 deletions spec/pronto/formatter/gitlab_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, repo) }
subject { formatter.format(messages, repo, nil) }
let(:messages) { [message, message] }
let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
Expand All @@ -31,7 +31,7 @@ module Formatter
end

describe '#format without duplicates' do
subject { formatter.format(messages, repo) }
subject { formatter.format(messages, repo, nil) }
let(:messages) { [message1, message2] }
let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:message1) { Message.new('path/to1', line1, :warning, 'crucial') }
Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/json_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, nil) }
subject { formatter.format(messages, nil, nil) }
let(:messages) { [message, message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { double(new_lineno: 1, commit_sha: nil) }
Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/null_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, nil) }
subject { formatter.format(messages, nil, nil) }
let(:messages) { [message, message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { double(new_lineno: 1, commit_sha: '123') }
Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatter
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, nil) }
subject { formatter.format(messages, nil, nil) }
let(:messages) { [message, message] }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { double(new_lineno: 1, commit_sha: '123') }
Expand Down

0 comments on commit 0a21098

Please sign in to comment.