Skip to content

Commit

Permalink
Better check that pull request creation errors have details
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Aug 7, 2019
1 parent 95e7412 commit 3262b5c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/lib/dependabot/pull_request_creator/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def create_pull_request
headers: custom_headers || {}
)
rescue Octokit::UnprocessableEntity => e
return handle_pr_creation_error(e) if e.message.include?("field:")
return handle_pr_creation_error(e) if e.message.include? "Error summary"

# Sometimes PR creation fails with no details (presumably because the
# details are internal). It doesn't hurt to retry in these cases, in
Expand Down
28 changes: 28 additions & 0 deletions common/spec/dependabot/pull_request_creator/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,34 @@
expect(WebMock).to_not have_requested(:post, "#{repo_api_url}/pulls")
end

context "but isn't initially returned (a race)" do
before do
url = "#{repo_api_url}/pulls?head=gocardless:#{branch_name}"\
"&state=all"
stub_request(:get, url).
to_return(status: 200, body: "[]", headers: json_header)
stub_request(
:patch,
"#{repo_api_url}/git/refs/heads/#{branch_name}"
).to_return(
status: 200,
body: fixture("github", "update_ref.json"),
headers: json_header
)
stub_request(:post, "#{repo_api_url}/pulls").
to_return(
status: 422,
body: fixture("github", "pull_request_already_exists.json"),
headers: json_header
)
end

it "returns nil" do
expect(creator.create).to be_nil
expect(WebMock).to have_requested(:post, "#{repo_api_url}/pulls")
end
end

context "but is merged" do
before do
url = "#{repo_api_url}/pulls?head=gocardless:#{branch_name}"\
Expand Down
11 changes: 11 additions & 0 deletions common/spec/fixtures/github/pull_request_already_exists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequest",
"code": "custom",
"message": "A pull request already exists for base branch 'develop' and head branch 'dependabot/maven/com.fasterxml.jackson.dataformat-jackson-dataformat-xml-2.9.7"
}
],
"documentation_url": "https://developer.github.com/v3/pulls/#update-a-pull-request"
}

0 comments on commit 3262b5c

Please sign in to comment.