class Pronto::Github

extend stock pronto github client wrapper

Constants

GET_REVIEW_THREADS_QUERY

Public Instance Methods

approve_pull_request(message = "") click to toggle source
# File lib/pronto/github_resolver/github_client_ext.rb, line 27
def approve_pull_request(message = "")
  client.create_pull_request_review(
    slug, pull_id,
    { event: "APPROVE", body: message, accept: "application/vnd.github.v3.diff+json" }
  )
end
create_pull_request_review(comments, event: nil) click to toggle source

original, but with event param

# File lib/pronto/github_resolver/github_client_ext.rb, line 16
def create_pull_request_review(comments, event: nil)
  options = {
    event: event || @config.github_review_type,
    accept: "application/vnd.github.v3.diff+json", # https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
    comments: comments.map do |comment|
      { path: comment.path, position: comment.position, body: comment.body }
    end
  }
  client.create_pull_request_review(slug, pull_id, options)
end
existing_pull_request_reviews() click to toggle source
# File lib/pronto/github_resolver/github_client_ext.rb, line 34
def existing_pull_request_reviews
  client.pull_request_reviews(slug, pull_id)
end
fetch_review_threads() click to toggle source
# File lib/pronto/github_resolver/github_client_ext.rb, line 61
def fetch_review_threads # rubocop:disable Metrics/MethodLength
  owner, repo_name = slug.split("/")
  res = client.post :graphql, {
    query: GET_REVIEW_THREADS_QUERY,
    variables: { owner: owner, name: repo_name, pull_num: pull_id }
  }.to_json

  return [] if res.errors || !res.data # TODO: handle errors

  res.data.repository.pullRequest.reviewThreads.nodes.to_h do |node|
    [
      node.id,
      node.comments.nodes.map do |comment|
        { authored: comment.viewerDidAuthor, path: comment.path, position: comment.position, body: comment.body }
      end
    ]
  end
end
publish_pull_request_comments(comments, event: nil) click to toggle source

original, but with event param

# File lib/pronto/github_resolver/github_client_ext.rb, line 7
def publish_pull_request_comments(comments, event: nil)
  comments_left = comments.clone
  while comments_left.any?
    comments_to_publish = comments_left.slice!(0, warnings_per_review)
    create_pull_request_review(comments_to_publish, event: event)
  end
end
resolve_review_threads(node_ids) click to toggle source
# File lib/pronto/github_resolver/github_client_ext.rb, line 80
    def resolve_review_threads(node_ids)
      return unless node_ids.any?

      query = <<~GQL
        mutation {
          #{node_ids.each_with_index.map do |id, index|
              "q#{index}: resolveReviewThread(input: { threadId: \"#{id}\" }){ thread { id } } "
            end.join("\n")}
        }
      GQL
      client.post :graphql, { query: query }.to_json
    end