class Stash::PullRequest

Attributes

id[RW]
repository[RW]

Public Class Methods

new(repository, id) click to toggle source
# File lib/stash/pull_request.rb, line 7
def initialize(repository, id)
  self.repository = repository
  self.id = id
end

Public Instance Methods

add_comment(file, line, text) click to toggle source
# File lib/stash/pull_request.rb, line 12
def add_comment(file, line, text)
  return unless diff.added_line?(file, line)
  return if already_commented?(file, line, text)

  post_comment(file, line, text)
end

Private Instance Methods

already_commented?(file, line, text) click to toggle source
# File lib/stash/pull_request.rb, line 21
def already_commented?(file, line, text)
  file_comments(file).detect do |comment|
    comment['anchor']['line'] == line && comment['text'] == text
  end
end
diff() click to toggle source
# File lib/stash/pull_request.rb, line 46
def diff
  @diff ||= Diff.new(get('/diff?withComments=false'))
end
endpoint() click to toggle source
# File lib/stash/pull_request.rb, line 58
def endpoint
  "/pull-requests/#{id}"
end
file_comments(file) click to toggle source
# File lib/stash/pull_request.rb, line 27
def file_comments(file)
  @file_comments ||= {}
  @file_comments[file] ||= get("/comments?path=#{file}")['values']
end
get(path) click to toggle source
# File lib/stash/pull_request.rb, line 50
def get(path)
  repository.get(endpoint + path)
end
logger() click to toggle source
# File lib/stash/pull_request.rb, line 62
def logger
  repository.logger
end
post(path, data) click to toggle source
# File lib/stash/pull_request.rb, line 54
def post(path, data)
  repository.post(endpoint + path, data)
end
post_comment(file, line, text) click to toggle source
# File lib/stash/pull_request.rb, line 32
def post_comment(file, line, text)
  data = {
    text: text,
    anchor: {
      path: file,
      line: line,
      lineType: 'ADDED'
    }
  }

  logger.info(%(Commenting #{file}, line #{line}: "#{text}"...))
  post('/comments', data)
end