Refactor Bintray not to depend on args.

This commit is contained in:
Markus Reiter 2020-07-23 01:20:31 +02:00
parent e7006beefb
commit adc36a05ff
3 changed files with 18 additions and 19 deletions

View File

@ -10,30 +10,27 @@ class Bintray
end
def inspect
"#<Bintray: user=#{@bintray_user} org=#{@bintray_org} key=***>"
"#<Bintray: org=#{@bintray_org}>"
end
def initialize(user: ENV["HOMEBREW_BINTRAY_USER"], key: ENV["HOMEBREW_BINTRAY_KEY"], org: "homebrew", clear: true)
@bintray_user = user
@bintray_key = key
def initialize(org: "homebrew")
@bintray_org = org
if !@bintray_user || !@bintray_key
unless Homebrew.args.dry_run?
raise UsageError, "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!"
end
end
raise UsageError, "Must set a Bintray organisation!" unless @bintray_org
ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @bintray_org == "homebrew" && !OS.mac?
ENV.delete "HOMEBREW_BINTRAY_KEY" if clear
end
def open_api(url, *extra_curl_args, auth: true)
args = extra_curl_args
args += ["--user", "#{@bintray_user}:#{@bintray_key}"] if auth
if auth
raise UsageError, "HOMEBREW_BINTRAY_USER is unset." unless (user = EnvConfig.bintray_user)
raise UsageError, "HOMEBREW_BINTRAY_KEY is unset." unless (key = EnvConfig.bintray_key)
args += ["--user", "#{user}:#{key}"]
end
curl(*args, url,
show_output: Homebrew.args.verbose?,
secrets: @bintray_key)

View File

@ -48,13 +48,9 @@ module Homebrew
if args.dry_run?
puts "brew #{bottle_args.join " "}"
else
safe_system HOMEBREW_BREW_FILE, *bottle_args
end
if args.dry_run?
puts "Upload bottles described by these JSON files to Bintray:\n #{Dir["*.json"].join("\n ")}"
else
safe_system HOMEBREW_BREW_FILE, *bottle_args
bintray.upload_bottle_json(Dir["*.json"],
publish_package: !args.no_publish?,
warn_on_error: args.warn_on_upload_failure?)

View File

@ -3,7 +3,13 @@
require "bintray"
describe Bintray, :needs_network do
bintray = described_class.new(user: "BrewTestBot", key: "deadbeef", org: "homebrew")
subject(:bintray) { described_class.new(org: "homebrew") }
before do
ENV["HOMEBREW_BINTRAY_USER"] = "BrewTestBot"
ENV["HOMEBREW_BINTRAY_KEY"] = "deadbeef"
end
describe "::file_published?" do
it "detects a published file" do
results = bintray.file_published?(repo: "bottles", remote_file: "hello-2.10.catalina.bottle.tar.gz")