Class: Octokit::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/request_sources/github/octokit_pr_review.rb

Constant Summary collapse

CUSTOM_ACCEPT_HEADER =

The Pull Request Review API is currently available for developers to preview. During the preview period, the API may change without advance notice. please see the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

"application/vnd.github.black-cat-preview+json".freeze
PULL_REQUEST_REVIEW_EVENT_APPROVE =

Approve pull request event

"APPROVE".freeze
PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES =

Request changes on the pull request event

"REQUEST_CHANGES".freeze
PULL_REQUEST_REVIEW_EVENT_COMMENT =

Left a gemeneral comment on the pull request event

"COMMENT".freeze

Instance Method Summary collapse

Instance Method Details

#create_pull_request_review(repo, pull_request_number, event, body = nil, options = {}) ⇒ Sawyer::Resource

Create a pull request review

Examples:

@client.create_pull_request_review("octokit/octokit.rb", "APPROVE", "Thanks for your contribution")

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • pull_request_number (Integer)

    Number of the pull request to create review for

  • event (String)

    The review action (event) to perform. Can be one of PULL_REQUEST_REVIEW_EVENT_APPROVE PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES PULL_REQUEST_REVIEW_EVENT_COMMENT

  • body (String) (defaults to: nil)

    The body for the pull request review (optional). Supports GFM.

Returns:

  • (Sawyer::Resource)

    The newly created pull request

See Also:



50
51
52
53
54
55
56
57
# File 'lib/danger/request_sources/github/octokit_pr_review.rb', line 50

def create_pull_request_review(repo, pull_request_number, event, body = nil, options = {})
  review = {
    event: event,
    accept: CUSTOM_ACCEPT_HEADER
  }
  review[:body] = body unless body.nil?
  post "#{Repository.path repo}/pulls/#{pull_request_number}/reviews", options.merge(review)
end

#pull_request_reviews(repo, pull_request_number, options = {}) ⇒ Array<Sawyer::Resource>

List pull request reviews for a pull request

Examples:

Octokit.pull_request_reviews('rails/rails', :state => 'closed')

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • pull_request_number (Integer)

    Number of the pull request to fetch reviews for

Returns:

  • (Array<Sawyer::Resource>)

    Array of reviews

See Also:



30
31
32
33
34
35
# File 'lib/danger/request_sources/github/octokit_pr_review.rb', line 30

def pull_request_reviews(repo, pull_request_number, options = {})
  accept = {
    accept: CUSTOM_ACCEPT_HEADER
  }
  paginate "#{Repository.path repo}/pulls/#{pull_request_number}/reviews", options.merge(accept)
end

#submit_pull_request_review(repo, pull_request_number, review_id, event, body = nil, options = {}) ⇒ Sawyer::Resource

Submit a pull request review

Examples:

@client.submit_pull_request_review("octokit/octokit.rb", "REQUEST_CHANGES",
                                   "Nice changes, but please make couple of imrovements")

Parameters:

  • repo (Integer, String, Hash, Repository)

    A GitHub repository

  • pull_request_number (Integer)

    Number of the pull request to create review for

  • review_id (Integer)

    ID of the pull request review to submit

  • event (String)

    The review action (event) to perform. Can be one of PULL_REQUEST_REVIEW_EVENT_APPROVE PULL_REQUEST_REVIEW_EVENT_REQUEST_CHANGES PULL_REQUEST_REVIEW_EVENT_COMMENT

  • body (String) (defaults to: nil)

    The body for the pull request review (optional). Supports GFM.

Returns:

  • (Sawyer::Resource)

    The newly created pull request

See Also:



74
75
76
77
78
79
80
81
# File 'lib/danger/request_sources/github/octokit_pr_review.rb', line 74

def submit_pull_request_review(repo, pull_request_number, review_id, event, body = nil, options = {})
  review = {
    event: event,
    accept: CUSTOM_ACCEPT_HEADER
  }
  review[:body] = body unless body.nil?
  post "#{Repository.path repo}/pulls/#{pull_request_number}/reviews/#{review_id}/events", options.merge(review)
end