Port Homebrew::DevCmd::UpdateSponsors
This commit is contained in:
parent
7bef4b010c
commit
c789bf4475
@ -1,42 +1,29 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "utils/github"
|
||||
require "system_command"
|
||||
|
||||
module Homebrew
|
||||
extend SystemCommand::Mixin
|
||||
module DevCmd
|
||||
class UpdateSponsors < AbstractCommand
|
||||
include SystemCommand::Mixin
|
||||
|
||||
NAMED_MONTHLY_AMOUNT = 100
|
||||
URL_MONTHLY_AMOUNT = 1000
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.update_sponsors_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Update the list of GitHub Sponsors in the `Homebrew/brew` README.
|
||||
EOS
|
||||
|
||||
named_args :none
|
||||
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 = []
|
||||
logo_sponsors = []
|
||||
# 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|
|
||||
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
|
||||
|
||||
@ -71,4 +60,20 @@ module Homebrew
|
||||
puts "List of sponsors updated in the README."
|
||||
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
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user