Port Homebrew::DevCmd::UpdateSponsors

This commit is contained in:
Douglas Eichelberger 2024-03-21 22:12:37 -07:00
parent 7bef4b010c
commit c789bf4475
2 changed files with 54 additions and 48 deletions

View File

@ -1,42 +1,29 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "cli/parser" require "cli/parser"
require "utils/github" require "utils/github"
require "system_command" require "system_command"
module Homebrew module Homebrew
extend SystemCommand::Mixin module DevCmd
class UpdateSponsors < AbstractCommand
include SystemCommand::Mixin
NAMED_MONTHLY_AMOUNT = 100 NAMED_MONTHLY_AMOUNT = 100
URL_MONTHLY_AMOUNT = 1000 URL_MONTHLY_AMOUNT = 1000
sig { returns(CLI::Parser) } cmd_args do
def self.update_sponsors_args
Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
Update the list of GitHub Sponsors in the `Homebrew/brew` README. Update the list of GitHub Sponsors in the `Homebrew/brew` README.
EOS EOS
named_args :none named_args :none
end end
end
def self.sponsor_name(sponsor)
sponsor[:name] || sponsor[:login]
end
def self.sponsor_logo(sponsor)
"https://github.com/#{sponsor[:login]}.png?size=64"
end
def self.sponsor_url(sponsor)
"https://github.com/#{sponsor[:login]}"
end
def self.update_sponsors
update_sponsors_args.parse
sig { override.void }
def run
named_sponsors = [] named_sponsors = []
logo_sponsors = [] logo_sponsors = []
# FIXME: This T.let should be unnecessary https://github.com/sorbet/sorbet/issues/6894 # FIXME: This T.let should be unnecessary https://github.com/sorbet/sorbet/issues/6894
@ -44,7 +31,9 @@ module Homebrew
GitHub.sponsorships("Homebrew").each do |s| GitHub.sponsorships("Homebrew").each do |s|
largest_monthly_amount = [s[:monthly_amount], s[:closest_tier_monthly_amount]].max largest_monthly_amount = [s[:monthly_amount], s[:closest_tier_monthly_amount]].max
named_sponsors << "[#{sponsor_name(s)}](#{sponsor_url(s)})" if largest_monthly_amount >= NAMED_MONTHLY_AMOUNT if largest_monthly_amount >= NAMED_MONTHLY_AMOUNT
named_sponsors << "[#{sponsor_name(s)}](#{sponsor_url(s)})"
end
next if largest_monthly_amount < URL_MONTHLY_AMOUNT next if largest_monthly_amount < URL_MONTHLY_AMOUNT
@ -71,4 +60,20 @@ module Homebrew
puts "List of sponsors updated in the README." puts "List of sponsors updated in the README."
end end
end end
private
def sponsor_name(sponsor)
sponsor[:name] || sponsor[:login]
end
def sponsor_logo(sponsor)
"https://github.com/#{sponsor[:login]}.png?size=64"
end
def sponsor_url(sponsor)
"https://github.com/#{sponsor[:login]}"
end
end
end
end end

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
require "dev-cmd/update-sponsors"
RSpec.describe "brew update-sponsors" do RSpec.describe Homebrew::DevCmd::UpdateSponsors do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
end end