Class: Shiba::Reviewer
- Inherits:
-
Object
- Object
- Shiba::Reviewer
- Defined in:
- lib/shiba/reviewer.rb
Overview
TODO:
-
Properly handle more than a handful of review failures
-
May make sense to edit the comment on a commit line when the code
is semi-corrected but still a problem
Constant Summary collapse
- MESSAGE_FILTER_THRESHOLD =
0.005
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#problems ⇒ Object
readonly
Returns the value of attribute problems.
-
#repo_url ⇒ Object
readonly
Returns the value of attribute repo_url.
Instance Method Summary collapse
- #comments ⇒ Object
-
#initialize(repo_url, problems, options) ⇒ Reviewer
constructor
A new instance of Reviewer.
- #repo_host ⇒ Object
- #repo_path ⇒ Object
-
#submit ⇒ Object
FIXME: Only submit 10 comments for now.
Constructor Details
#initialize(repo_url, problems, options) ⇒ Reviewer
Returns a new instance of Reviewer.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/shiba/reviewer.rb', line 17 def initialize(repo_url, problems, ) @repo_url = repo_url @problems = problems @options = @commit_id = .fetch("branch") do if ["submit"] raise Shiba::Error.new("Must specify a branch") end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/shiba/reviewer.rb', line 15 def @options end |
#problems ⇒ Object (readonly)
Returns the value of attribute problems.
15 16 17 |
# File 'lib/shiba/reviewer.rb', line 15 def problems @problems end |
#repo_url ⇒ Object (readonly)
Returns the value of attribute repo_url.
15 16 17 |
# File 'lib/shiba/reviewer.rb', line 15 def repo_url @repo_url end |
Instance Method Details
#comments ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shiba/reviewer.rb', line 28 def comments return @comments if @comments @comments = problems.map do |path, explain| file, line_number = path.split(":") if path.empty? || line_number.nil? raise Shiba::Error.new("Bad path received: #{line_number}") end position = if path == "none:-1" nil else diff_parser.find_position(file, line_number.to_i) end explain = (explain) { body: renderer.render(explain), commit_id: @commit_id, path: file, line: line_number, position: position } end end |
#repo_host ⇒ Object
81 82 83 |
# File 'lib/shiba/reviewer.rb', line 81 def repo_host @repo_host ||= api.host_and_path.first end |
#repo_path ⇒ Object
85 86 87 |
# File 'lib/shiba/reviewer.rb', line 85 def repo_path @repo_path ||= api.host_and_path.last end |
#submit ⇒ Object
FIXME: Only submit 10 comments for now. The rest just vanish. Submits commits, checking to makre sure the line doesn’t already have a review.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/shiba/reviewer.rb', line 55 def submit report("Connecting to #{api.uri}") api.connect do previous_reviews = api.previous_comments.map { |c| c['body'] } comments[0,10].each do |c| if previous_reviews.any? { |r| r == c[:body] } report("skipped duplicate comment") next end # :line isn't part of the github api comment = c.dup.tap { |dc| dc.delete(:line) } if [:verbose] comment[:body] += " (verbose mode ts=#{Time.now.to_i})" end res = api.comment_on_pull_request(comment) report("API success #{res.inspect}") end end report("HTTP request finished") end |