Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to update pull request branch #1472

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/octokit/client/pull_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ def pull_request_files(repo, number, options = {})
end
alias pull_files pull_request_files

# Update a pull request branch
#
# @see https://developer.github.com/v3/pulls/#update-a-pull-request-branch
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param number [Integer] Number of pull request
# @param options [Hash] Optional parameters (e.g. expected_head_sha)
# @return [Boolean] True if the pull request branch has been updated
def update_pull_request_branch(repo, number, options = {})
boolean_from_response(:put, "#{Repository.path repo}/pulls/#{number}/update-branch", options)
end

# Merge a pull request
#
# @see https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
Expand Down
34 changes: 34 additions & 0 deletions spec/octokit/client/pull_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,40 @@
end
end # new @pull methods

# stub this so we don't have to set up new fixture data
describe '.update_pull_request_branch' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test the return value of #update_pull_request_branch in here.

let(:repo) { 'api-playground/api-sandbox' }
let(:pull_number) { 321 }
let(:update_branch_url) { github_url("/repos/#{repo}/pulls/#{pull_number}/update-branch") }
let(:status) { 202 }

before(:each) do
stub_put(update_branch_url).to_return(status: status)
end

it 'updates the pull request branch' do
result = @client.update_pull_request_branch(repo, pull_number)
assert_requested :put, update_branch_url
expect(result).to eq(true)
end

context 'when the request fails with a 403 Forbidden' do
let(:status) { 403 }

it 'raises an exception' do
expect { @client.update_pull_request_branch(repo, pull_number) }.to raise_error(Octokit::Forbidden)
end
end

context 'when the request fails with a 422 Unprocessable Entity' do
let(:status) { 422 }

it 'raises an exception' do
expect { @client.update_pull_request_branch(repo, pull_number) }.to raise_error(Octokit::UnprocessableEntity)
end
end
end # .update_pull_request_branch

# stub this so we don't have to set up new fixture data
describe '.merge_pull_request' do
it 'merges the pull request' do
Expand Down