forked from prontolabs/pronto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request prontolabs#34 from mmozuras/0.3.0
0.3.0
- Loading branch information
Showing
40 changed files
with
572 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
|
||
## 0.3.0 | ||
|
||
### 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 | ||
|
||
* [#29](https://github.com/mmozuras/pronto/issues/29): Be compatible and depend on rugged '0.21.0'. | ||
* Performance improvement: use Rugged::Blame instead of one provided by Grit. | ||
* Performance improvement: cache comments retrieved from GitHub. | ||
|
||
### Bugs fixed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Pronto | ||
module Git | ||
class Line < Struct.new(:line, :patch, :hunk) | ||
extend Forwardable | ||
|
||
def_delegators :line, :addition?, :deletion?, :content, :new_lineno, | ||
:old_lineno, :line_origin | ||
|
||
def position | ||
hunk_index = patch.hunks.find_index { |h| h.header == hunk.header } | ||
line_index = patch.lines.find_index(line) | ||
|
||
line_index + hunk_index + 1 | ||
end | ||
|
||
def commit_sha | ||
blame[:final_commit_id] if blame | ||
end | ||
|
||
def commit_line | ||
@commit_line ||= begin | ||
patches = patch.repo.show_commit(commit_sha) | ||
|
||
result = patches.find_line(patch.new_file_full_path, | ||
blame[:orig_start_line_number]) | ||
result || self # no commit_line means that it was just added | ||
end | ||
end | ||
|
||
def ==(other) | ||
content == other.content && | ||
line_origin == other.line_origin && | ||
old_lineno == other.old_lineno && | ||
new_lineno == other.new_lineno | ||
end | ||
|
||
private | ||
|
||
def blame | ||
@blame ||= patch.blame(new_lineno) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Pronto | ||
module Git | ||
class Patch < Struct.new(:patch, :repo) | ||
extend Forwardable | ||
|
||
def_delegators :patch, :delta, :hunks, :stat | ||
|
||
def additions | ||
stat[0] | ||
end | ||
|
||
def deletions | ||
stat[1] | ||
end | ||
|
||
def blame(lineno) | ||
repo.blame(self, lineno) | ||
end | ||
|
||
def lines | ||
@lines ||= begin | ||
hunks.flat_map do |hunk| | ||
hunk.lines.map { |line| Line.new(line, self, hunk) } | ||
end | ||
end | ||
end | ||
|
||
def added_lines | ||
lines.select(&:addition?) | ||
end | ||
|
||
def deleted_lines | ||
lines.select(&:deletion?) | ||
end | ||
|
||
def new_file_full_path | ||
repo.path.join(delta.new_file[:path]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Pronto | ||
module Git | ||
class Patches | ||
include Enumerable | ||
|
||
attr_reader :commit, :repo | ||
|
||
def initialize(repo, commit, patches) | ||
@commit = commit | ||
@patches = patches.map { |patch| Git::Patch.new(patch, repo) } | ||
end | ||
|
||
def each(&block) | ||
@patches.each(&block) | ||
end | ||
|
||
def find_line(path, line) | ||
patch = find { |p| p.new_file_full_path == path } | ||
lines = patch ? patch.lines : [] | ||
lines.find { |l| l.new_lineno == line } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Pronto | ||
module Git | ||
class Remote < Struct.new(:remote) | ||
def github_slug | ||
match = /.*github.com(:|\/)(?<slug>.*).git/.match(remote.url) | ||
match[:slug] if match | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.