diff --git a/common/lib/dependabot/pull_request_creator/github.rb b/common/lib/dependabot/pull_request_creator/github.rb index e9a3b11285..35b2c290c0 100644 --- a/common/lib/dependabot/pull_request_creator/github.rb +++ b/common/lib/dependabot/pull_request_creator/github.rb @@ -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 diff --git a/common/spec/dependabot/pull_request_creator/github_spec.rb b/common/spec/dependabot/pull_request_creator/github_spec.rb index e0877bfe84..373551ce48 100644 --- a/common/spec/dependabot/pull_request_creator/github_spec.rb +++ b/common/spec/dependabot/pull_request_creator/github_spec.rb @@ -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}"\ diff --git a/common/spec/fixtures/github/pull_request_already_exists.json b/common/spec/fixtures/github/pull_request_already_exists.json new file mode 100644 index 0000000000..89ffd3726a --- /dev/null +++ b/common/spec/fixtures/github/pull_request_already_exists.json @@ -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" +}