From a34e0c1893c2f41bb2a0198fe11a91e90a1505fd Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Mon, 27 Apr 2020 20:25:11 +0100 Subject: [PATCH 1/2] bintray: discard unused output from curl --- Library/Homebrew/bintray.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/bintray.rb b/Library/Homebrew/bintray.rb index 2aaeb1f8b4..68c7e2d1cd 100644 --- a/Library/Homebrew/bintray.rb +++ b/Library/Homebrew/bintray.rb @@ -34,6 +34,7 @@ class Bintray def open_api(url, *extra_curl_args, auth: true) args = extra_curl_args args += ["--user", "#{@bintray_user}:#{@bintray_key}"] if auth + args += ["--output", "/dev/null"] unless Homebrew.args.verbose? curl(*args, url, show_output: Homebrew.args.verbose?, secrets: @bintray_key) @@ -66,7 +67,7 @@ class Bintray def package_exists?(repo:, package:) url = "#{API_URL}/packages/#{@bintray_org}/#{repo}/#{package}" begin - open_api url, "--fail", "--silent", "--output", "/dev/null", auth: false + open_api url, "--fail", "--silent", auth: false rescue ErrorDuringExecution => e stderr = e.output .select { |type,| type == :stderr } From cc799b1f31bc252020e23e400860344568a59993 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Mon, 27 Apr 2020 20:27:42 +0100 Subject: [PATCH 2/2] dev-cmd/mirror: switch to Bintray wrapper --- Library/Homebrew/dev-cmd/mirror.rb | 40 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index bba48a7be0..9637a5a45d 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "bintray" require "cli/parser" module Homebrew @@ -12,6 +13,8 @@ module Homebrew Reupload the stable URL of a formula to Bintray for use as a mirror. EOS + flag "--bintray-org=", + description: "Upload to the specified Bintray organisation (default: homebrew)." switch :verbose switch :debug hide_from_man_page! @@ -22,25 +25,16 @@ module Homebrew def mirror mirror_args.parse - bintray_user = Homebrew::EnvConfig.bintray_user - bintray_key = Homebrew::EnvConfig.bintray_key - raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key + bintray_org = args.bintray_org || "homebrew" + bintray_repo = "mirror" + + bintray = Bintray.new(org: bintray_org) args.formulae.each do |f| bintray_package = Utils::Bottles::Bintray.package f.name - bintray_repo_url = "https://api.bintray.com/packages/homebrew/mirror" - package_url = "#{bintray_repo_url}/#{bintray_package}" - unless system curl_executable, "--silent", "--fail", "--output", "/dev/null", package_url - package_blob = <<~JSON - {"name": "#{bintray_package}", - "public_download_numbers": true, - "public_stats": true} - JSON - curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", - "--header", "Content-Type: application/json", - "--data", package_blob, bintray_repo_url - puts + unless bintray.package_exists?(repo: bintray_repo, package: bintray_package) + bintray.create_package repo: bintray_repo, package: bintray_package end downloader = f.downloader @@ -49,14 +43,18 @@ module Homebrew filename = downloader.basename - destination_url = "https://dl.bintray.com/homebrew/mirror/#{filename}" + destination_url = "https://dl.bintray.com/#{bintray_org}/#{bintray_repo}/#{filename}" ohai "Uploading to #{destination_url}" - content_url = - "https://api.bintray.com/content/homebrew/mirror/#{bintray_package}/#{f.pkg_version}/#{filename}?publish=1" - curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", - "--upload-file", downloader.cached_location, content_url - puts + bintray.upload( + downloader.cached_location, + repo: bintray_repo, + package: bintray_package, + version: f.pkg_version, + sha256: f.stable.checksum, + remote_file: filename, + ) + bintray.publish(repo: bintray_repo, package: bintray_package, version: f.pkg_version) ohai "Mirrored #{filename}!" end end