diff --git a/Library/Homebrew/bintray.rb b/Library/Homebrew/bintray.rb index 6dada447d5..050dbf10f3 100644 --- a/Library/Homebrew/bintray.rb +++ b/Library/Homebrew/bintray.rb @@ -56,16 +56,27 @@ class Bintray end def create_package(repo:, package:, **extra_data_args) - url = "#{API_URL}/packages/#{@bintray_org}/#{repo}/#{package}" + url = "#{API_URL}/packages/#{@bintray_org}/#{repo}" data = { name: package, public_download_numbers: true } data[:public_stats] = official_org? data.merge! extra_data_args - open_api url, "--request", "POST", "--data", data.to_json + open_api url, "--header", "Content-Type: application/json", "--request", "POST", "--data", data.to_json end def package_exists?(repo:, package:) url = "#{API_URL}/packages/#{@bintray_org}/#{repo}/#{package}" - open_api url, "--output", "/dev/null", auth: false + begin + open_api url, "--silent", "--output", "/dev/null", auth: false + rescue ErrorDuringExecution => e + stderr = e.output.select { |type,| type == :stderr } + .map { |_, line| line } + .join + raise if e.status.exitstatus != 22 && !stderr.include?("404 Not Found") + + false + else + true + end end def file_published?(repo:, remote_file:) @@ -113,7 +124,7 @@ class Bintray end if !formula_packaged[formula_name] && !package_exists?(repo: bintray_repo, package: bintray_package) - odebug "Creating package #{@bintray_org}/#{bintray_repo}/#{package}" + odebug "Creating package #{@bintray_org}/#{bintray_repo}/#{bintray_package}" create_package repo: bintray_repo, package: bintray_package formula_packaged[formula_name] = true end diff --git a/Library/Homebrew/test/bintray_spec.rb b/Library/Homebrew/test/bintray_spec.rb index 0e1eceaf29..6e3a017dee 100644 --- a/Library/Homebrew/test/bintray_spec.rb +++ b/Library/Homebrew/test/bintray_spec.rb @@ -19,7 +19,7 @@ describe Bintray, :needs_network do describe "::package_exists?" do it "detects a package" do results = bintray.package_exists?(repo: "bottles", package: "hello") - expect(results.status.exitstatus).to be 0 + expect(results).to be true end end end