Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.0 #34

Merged
merged 30 commits into from
Sep 10, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3014746
Remove 'grit' from gemspec and add 'rugged'
mmozuras Jul 13, 2014
b5df669
Move Rugged::Patch out of Diff namespace
mmozuras Jul 13, 2014
d04a0ef
Remove patches that are not needed with rugged '0.2.1'
mmozuras Jul 13, 2014
65ce672
Passing parents.first is no longer necessary for diff
mmozuras Jul 13, 2014
e013c9b
Add 'pry' as development dependency
mmozuras Jul 13, 2014
e329818
Use Rugged::Blame to find the commit line
mmozuras Jul 13, 2014
5a1d93d
Bump octokit from 2.7.0 to 3.2.0
mmozuras Jul 27, 2014
27895e6
Upgrade rspec to 3.0.0
mmozuras Jul 27, 2014
16e68af
To find commit location, use orig_ instead of final_start_line_number
mmozuras Jul 27, 2014
6b09caa
Use additional tracking options for more accurate blaming
mmozuras Jul 27, 2014
90f5bb7
Get rid of Rugged monkey patches, move them to Pronto::Git namespace
mmozuras Jul 29, 2014
064f42f
Extract Git::Patches, Git::Repository and Git::Remote
mmozuras Jul 30, 2014
27ed09e
Move #blame to Patch from Line
mmozuras Jul 30, 2014
6a7c001
Some specs for Git::Line
mmozuras Aug 3, 2014
ed3688b
Use Forwardable in Git::Line
mmozuras Aug 3, 2014
565345e
Some specs for Git::Patch
mmozuras Aug 3, 2014
befc3e7
Use Forwardable in Git::Patch
mmozuras Aug 3, 2014
62c3ea9
Replace usages of OpenStruct in specs to double()
mmozuras Aug 3, 2014
b5f80b6
More pessimistic dependencies of rugged and thor
mmozuras Aug 3, 2014
fbf8d76
Extract Pronto::Github to be used by multiple formatters
mmozuras Aug 3, 2014
8002773
More specs for Git::Patch
mmozuras Aug 3, 2014
0eabaa4
Extract comment related stuff to Pronto::Github
mmozuras Aug 3, 2014
e498de7
Add CHANGELOG.md
mmozuras Aug 10, 2014
d8064e9
Performance improvement - cache comments retrieved from GitHub
mmozuras Aug 10, 2014
d4cb558
Add '--exit-code' option for 'pronto run'
mmozuras Aug 10, 2014
b2575d7
Extract Git::Patches#find_line from Git::Line
mmozuras Aug 19, 2014
013c4c4
Return a path instead of string from Repository#path
mmozuras Aug 19, 2014
d10596b
Formatter for GitHub pull requests
mmozuras Aug 19, 2014
b74d51c
Fix: pass position when creating Comment from GitHub responses
mmozuras Aug 19, 2014
122c62a
Bump version to 0.3.0
mmozuras Aug 19, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Formatter for GitHub pull requests
Closes #16
  • Loading branch information
mmozuras committed Sep 10, 2014
commit d10596b781d7ad1a50ee663166405c674066a016
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

* [#27](https://github.com/mmozuras/pronto/issues/27): '--exit-code' option for 'pronto run'. Pronto exits with non-zero code if there were any warnings/errors.
* [#16](https://github.com/mmozuras/pronto/issues/16): New formatter: GithubPullRequestFormatter. Writes review comments on GitHub pull requests.

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'pronto/formatter/text_formatter'
require 'pronto/formatter/json_formatter'
require 'pronto/formatter/github_formatter'
require 'pronto/formatter/github_pull_request_formatter'
require 'pronto/formatter/checkstyle_formatter'
require 'pronto/formatter/formatter'

Expand Down
1 change: 1 addition & 0 deletions lib/pronto/formatter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def self.names

FORMATTERS = {
'github' => GithubFormatter,
'github_pr' => GithubPullRequestFormatter,
'json' => JsonFormatter,
'checkstyle' => CheckstyleFormatter,
'text' => TextFormatter
Expand Down
2 changes: 1 addition & 1 deletion lib/pronto/formatter/github_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def format(messages, repo)
commit_messages = messages.map do |message|
github_slug = repo.github_slug
sha = message.commit_sha
position = message.line.commit_line.position if message.line
body = message.msg
path = message.path
position = message.line.commit_line.position if message.line

comment = Github::Comment.new(github_slug, sha, body, path, position)
create_comment(github_slug, sha, comment)
Expand Down
41 changes: 41 additions & 0 deletions lib/pronto/formatter/github_pull_request_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Pronto
module Formatter
class GithubPullRequestFormatter
def format(messages, repo)
commit_messages = messages.map do |message|
github_slug = repo.github_slug
body = message.msg
path = message.path

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

position = line.position - 1

comment = Github::Comment.new(github_slug, sha, body, path, position)
create_comment(github_slug, sha, comment)
end

"#{commit_messages.compact.count} Pronto messages posted to GitHub"
end

private

def create_comment(repo, sha, comment)
comments = client.pull_comments(repo, sha)
existing = comments.any? { |c| comment == c }
client.create_pull_comment(repo, sha, comment) unless existing
end

def client
@client ||= Github.new
end
end
end
end
9 changes: 9 additions & 0 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def show_commit(sha)
Patches.new(self, sha, diff.patches)
end

def commits_until(sha)
result = []
@repo.walk('HEAD', Rugged::SORT_TOPO).take_while do |commit|
result << commit.oid
!commit.oid.start_with?(sha)
end
result
end

def path
Pathname.new(@repo.path).parent
end
Expand Down
17 changes: 17 additions & 0 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ def initialize
@comment_cache = {}
end

def pull_comments(repo, sha)
@comment_cache["#{repo}/#{pull_id}/#{sha}"] ||= begin
client.pull_comments(repo, pull_id).map do |comment|
Comment.new(repo, sha, comment.body, comment.path, comment.body)
end
end
end

def commit_comments(repo, sha)
@comment_cache["#{repo}/#{sha}"] ||= begin
client.commit_comments(repo, sha).map do |comment|
Expand All @@ -17,12 +25,21 @@ def create_commit_comment(repo, sha, comment)
nil, comment.position)
end

def create_pull_comment(repo, sha, comment)
client.create_pull_comment(repo, pull_id, comment.body, sha, comment.path,
comment.position)
end

private

def client
@client ||= Octokit::Client.new(access_token: access_token)
end

def pull_id
ENV['PULL_REQUEST_ID'].to_i
end

def access_token
ENV['GITHUB_ACCESS_TOKEN']
end
Expand Down
4 changes: 4 additions & 0 deletions lib/pronto/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def initialize(path, line, level, msg, commit_sha = nil)
@commit_sha ||= line.commit_sha if line
end

def full_path
repo.path.join(path) if repo
end

def repo
line.patch.repo if line
end
Expand Down
7 changes: 6 additions & 1 deletion spec/pronto/formatter/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module Formatter
it { should be_an_instance_of GithubFormatter }
end

context 'github_pr' do
let(:name) { 'github_pr' }
it { should be_an_instance_of GithubPullRequestFormatter }
end

context 'json' do
let(:name) { 'json' }
it { should be_an_instance_of JsonFormatter }
Expand Down Expand Up @@ -38,7 +43,7 @@ module Formatter

describe '.names' do
subject { Formatter.names }
it { should =~ %w(github json checkstyle text) }
it { should =~ %w(github github_pr json checkstyle text) }
end
end
end
2 changes: 1 addition & 1 deletion spec/pronto/git/patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Git
let(:rugged_patch) do
double(delta: double(new_file: { path: 'test.md' }))
end
let(:repo) { double(path: '/house/of/cards/orig.md') }
let(:repo) { double(path: Pathname.new('/house/of/cards')) }
its(:to_s) { should == '/house/of/cards/test.md' }
end
end
Expand Down