Module: Octokit::Client::PullRequests

Included in:
Octokit::Client
Defined in:
lib/octokit/client/pull_requests.rb

Overview

Methods for the Pull Requests API

Instance Method Summary collapse

Instance Method Details

#close_pull_request(repo, number, options = {}) ⇒ Sawyer::Resource

Close a pull request

Examples:

@client.close_pull_request('octokit/octokit.rb', 67)

See Also:


129
130
131
132
# File 'lib/octokit/client/pull_requests.rb', line 129

def close_pull_request(repo, number, options = {})
  options.merge! :state => 'closed'
  update_pull_request(repo, number, options)
end

#create_pull_request(repo, base, head, title, body, options = {}) ⇒ Sawyer::Resource

Create a pull request

Examples:

@client.create_pull_request("octokit/octokit.rb", "master", "feature-branch",
  "Pull Request title", "Pull Request body")

See Also:


62
63
64
65
66
67
68
69
70
# File 'lib/octokit/client/pull_requests.rb', line 62

def create_pull_request(repo, base, head, title, body, options = {})
  pull = {
    :base  => base,
    :head  => head,
    :title => title,
    :body  => body,
  }
  post "#{Repository.path repo}/pulls", options.merge(pull)
end

#create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {}) ⇒ Sawyer::Resource Also known as: create_pull_comment, create_view_comment

Create a pull request comment

Examples:

@client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:",
  "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)

See Also:


216
217
218
219
220
221
222
223
224
# File 'lib/octokit/client/pull_requests.rb', line 216

def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {})
  options.merge!({
    :body => body,
    :commit_id => commit_id,
    :path => path,
    :position => position
  })
  post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
end

#create_pull_request_comment_reply(repo, pull_id, body, comment_id, options = {}) ⇒ Sawyer::Resource Also known as: create_pull_reply, create_review_reply

Create reply to a pull request comment

Examples:

@client.create_pull_request_comment_reply("octokit/octokit.rb", 1903950, "done.")

See Also:


238
239
240
241
242
243
244
# File 'lib/octokit/client/pull_requests.rb', line 238

def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options = {})
  options.merge!({
    :body => body,
    :in_reply_to => comment_id
  })
  post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
end

#create_pull_request_for_issue(repo, base, head, issue, options = {}) ⇒ Sawyer::Resource

Create a pull request from existing issue


83
84
85
86
87
88
89
90
# File 'lib/octokit/client/pull_requests.rb', line 83

def create_pull_request_for_issue(repo, base, head, issue, options = {})
  pull = {
    :base  => base,
    :head  => head,
    :issue => issue
  }
  post "#{Repository.path repo}/pulls", options.merge(pull)
end

#delete_pull_request_comment(repo, comment_id, options = {}) ⇒ Boolean Also known as: delete_pull_comment, delete_review_comment

Delete pull request comment

Examples:

@client.delete_pull_request_comment("octokit/octokit.rb", 1902707)

See Also:


272
273
274
# File 'lib/octokit/client/pull_requests.rb', line 272

def delete_pull_request_comment(repo, comment_id, options = {})
  boolean_from_response(:delete, "#{Repository.path repo}/pulls/comments/#{comment_id}", options)
end

#merge_pull_request(repo, number, commit_message = '', options = {}) ⇒ Array<Sawyer::Resource>

Merge a pull request


296
297
298
# File 'lib/octokit/client/pull_requests.rb', line 296

def merge_pull_request(repo, number, commit_message='', options = {})
  put "#{Repository.path repo}/pulls/#{number}/merge", options.merge({:commit_message => commit_message})
end

#pull_merged?(repo, number, options = {}) ⇒ Boolean Also known as: pull_request_merged?

Check pull request merge status


306
307
308
# File 'lib/octokit/client/pull_requests.rb', line 306

def pull_merged?(repo, number, options = {})
  boolean_from_response :get, "#{Repository.path repo}/pulls/#{number}/merge", options
end

#pull_request(repo, number, options = {}) ⇒ Sawyer::Resource Also known as: pull

Get a pull request


42
43
44
# File 'lib/octokit/client/pull_requests.rb', line 42

def pull_request(repo, number, options = {})
  get "#{Repository.path repo}/pulls/#{number}", options
end

#pull_request_comment(repo, comment_id, options = {}) ⇒ Sawyer::Resource Also known as: pull_comment, review_comment

Get a pull request comment

Examples:

@client.pull_request_comment("pengwynn/octkit", 1903950)

See Also:


197
198
199
# File 'lib/octokit/client/pull_requests.rb', line 197

def pull_request_comment(repo, comment_id, options = {})
  get "#{Repository.path repo}/pulls/comments/#{comment_id}", options
end

#pull_request_comments(repo, number, options = {}) ⇒ Array<Sawyer::Resource> Also known as: pull_comments, review_comments

List comments on a pull request


182
183
184
185
# File 'lib/octokit/client/pull_requests.rb', line 182

def pull_request_comments(repo, number, options = {})
  # return the comments for a pull request
  paginate("#{Repository.path repo}/pulls/#{number}/comments", options)
end

#pull_request_commits(repo, number, options = {}) ⇒ Array<Sawyer::Resource> Also known as: pull_commits

List commits on a pull request


140
141
142
# File 'lib/octokit/client/pull_requests.rb', line 140

def pull_request_commits(repo, number, options = {})
  paginate "#{Repository.path repo}/pulls/#{number}/commits", options
end

#pull_request_files(repo, number, options = {}) ⇒ Array<Sawyer::Resource> Also known as: pull_files

List files on a pull request


284
285
286
# File 'lib/octokit/client/pull_requests.rb', line 284

def pull_request_files(repo, number, options = {})
  paginate "#{Repository.path repo}/pulls/#{number}/files", options
end

#pull_requests(repo, options) ⇒ Array<Sawyer::Resource> #pull_requests(repo, state, options) ⇒ Array<Sawyer::Resource> Also known as: pulls

List pull requests for a repository

Examples:

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

Overloads:

  • #pull_requests(repo, options) ⇒ Array<Sawyer::Resource>

    Options Hash (options):

    • :state (String)

      open or closed.

  • #pull_requests(repo, state, options) ⇒ Array<Sawyer::Resource>
    Deprecated.

See Also:


24
25
26
27
28
29
30
31
32
33
# File 'lib/octokit/client/pull_requests.rb', line 24

def pull_requests(*args)
  arguments = Arguments.new(args)
  opts = arguments.options
  repo = arguments.shift
  if state = arguments.shift
    octokit_warn "DEPRECATED: Client#pull_requests: Passing state as positional argument is deprecated. Please use :state => '#{state}'"
    opts[:state] = state if state
  end
  paginate "#{Repository.path repo}/pulls", opts
end

#pull_requests_comments(repo, options = {}) ⇒ Array Also known as: pulls_comments, reviews_comments

List pull request comments for a repository

By default, Review Comments are ordered by ascending ID.

Examples:

Get the pull request review comments in the octokit repository

@client.issues_comments("octokit/octokit.rb")

Get review comments, sort by updated asc since a time

@client.pull_requests_comments("octokit/octokit.rb", {
  :sort => 'asc',
  :direction => 'down',
  :since => '2010-05-04T23:45:02Z'
})

Options Hash (options):

  • :sort (String)

    created or updated

  • :direction (String)

    asc or desc. Ignored without sort parameter.

  • :since (String)

    Timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ

See Also:


170
171
172
# File 'lib/octokit/client/pull_requests.rb', line 170

def pull_requests_comments(repo, options = {})
  paginate("#{Repository.path repo}/pulls/comments", options)
end

#update_pull_request(repo, id, title = nil, body = nil, state = nil, options = {}) ⇒ Sawyer::Resource #update_pull_request(repo, id, options = {}) ⇒ Sawyer::Resource

Update a pull request

Examples:

@client.update_pull_request('octokit/octokit.rb', 67, 'new title', 'updated body', 'closed')

Passing nil for optional attributes to update specific attributes.

@client.update_pull_request('octokit/octokit.rb', 67, nil, nil, 'open')

Empty body by passing empty string

@client.update_pull_request('octokit/octokit.rb', 67, nil, '')

Overloads:

  • #update_pull_request(repo, id, title = nil, body = nil, state = nil, options = {}) ⇒ Sawyer::Resource
    Deprecated.
  • #update_pull_request(repo, id, options = {}) ⇒ Sawyer::Resource

    Options Hash (options):

    • :title (String)

      Title for the pull request.

    • :body (String)

      Body for the pull request.

    • :state (String)

      State for the pull request.

See Also:


114
115
116
117
118
119
# File 'lib/octokit/client/pull_requests.rb', line 114

def update_pull_request(*args)
  arguments = Octokit::Arguments.new(args)
  repo   = arguments.shift
  number = arguments.shift
  patch "#{Repository.path repo}/pulls/#{number}", arguments.options
end

#update_pull_request_comment(repo, comment_id, body, options = {}) ⇒ Sawyer::Resource Also known as: update_pull_comment, update_review_comment

Update pull request comment

Examples:

@client.update_pull_request_comment("octokit/octokit.rb", 1903950, ":shipit:")

See Also:


257
258
259
260
# File 'lib/octokit/client/pull_requests.rb', line 257

def update_pull_request_comment(repo, comment_id, body, options = {})
  options.merge! :body => body
  patch("#{Repository.path repo}/pulls/comments/#{comment_id}", options)
end