2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2020-07-04 15:03:17 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cli/parser"
|
|
|
|
require "utils/github"
|
|
|
|
|
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2020-07-04 15:03:17 +10:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2020-07-04 15:03:17 +10:00
|
|
|
def sponsors_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
|
|
|
`sponsors`
|
|
|
|
|
|
|
|
Print a Markdown summary of Homebrew's GitHub Sponsors, suitable for pasting into a README.
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sponsors
|
|
|
|
sponsors_args.parse
|
|
|
|
|
|
|
|
sponsors = {
|
|
|
|
"named" => [],
|
|
|
|
"users" => 0,
|
|
|
|
"orgs" => 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
GitHub.sponsors_by_tier("Homebrew").each do |tier|
|
|
|
|
sponsors["named"] += tier["sponsors"] if tier["tier"] >= 100
|
|
|
|
sponsors["users"] += tier["count"]
|
|
|
|
sponsors["orgs"] += tier["sponsors"].count { |s| s["type"] == "organization" }
|
|
|
|
end
|
|
|
|
|
|
|
|
items = []
|
|
|
|
items += sponsors["named"].map { |s| "[#{s["name"]}](https://github.com/#{s["login"]})" }
|
|
|
|
|
|
|
|
anon_users = sponsors["users"] - sponsors["named"].length - sponsors["orgs"]
|
|
|
|
|
|
|
|
items << if items.length > 1
|
|
|
|
"#{anon_users} other users"
|
|
|
|
else
|
|
|
|
"#{anon_users} users"
|
|
|
|
end
|
|
|
|
|
|
|
|
if sponsors["orgs"] == 1
|
|
|
|
items << "#{sponsors["orgs"]} organization"
|
|
|
|
elsif sponsors["orgs"] > 1
|
|
|
|
items << "#{sponsors["orgs"]} organizations"
|
|
|
|
end
|
|
|
|
|
|
|
|
sponsor_text = if items.length > 2
|
|
|
|
items[0..-2].join(", ") + " and #{items.last}"
|
|
|
|
else
|
|
|
|
items.join(" and ")
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Homebrew is generously supported by #{sponsor_text} via [GitHub Sponsors](https://github.com/sponsors/Homebrew)."
|
|
|
|
end
|
|
|
|
end
|