Class: Homebrew::DevCmd::UpdateSponsors

Inherits:
AbstractCommand show all
Includes:
SystemCommand::Mixin
Defined in:
dev-cmd/update-sponsors.rb

Constant Summary collapse

NAMED_MONTHLY_AMOUNT =
100
URL_MONTHLY_AMOUNT =
1000

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'dev-cmd/update-sponsors.rb', line 25

def run
  named_sponsors = []
  logo_sponsors = []
  # FIXME: This T.let should be unnecessary https://github.com/sorbet/sorbet/issues/6894
  largest_monthly_amount = T.let(0, T.untyped)

  GitHub.sponsorships("Homebrew").each do |s|
    largest_monthly_amount = [s[:monthly_amount], s[:closest_tier_monthly_amount]].max
    if largest_monthly_amount >= NAMED_MONTHLY_AMOUNT
      named_sponsors << "[#{sponsor_name(s)}](#{sponsor_url(s)})"
    end

    next if largest_monthly_amount < URL_MONTHLY_AMOUNT

    logo_sponsors << "[![#{sponsor_name(s)}](#{(s)})](#{sponsor_url(s)})"
  end

  odie "No sponsorships amounts found! Ensure you have sufficient permissions!" if largest_monthly_amount.zero?

  named_sponsors << "many other users and organisations via [GitHub Sponsors](https://github.com/sponsors/Homebrew)"

  readme = HOMEBREW_REPOSITORY/"README.md"
  content = readme.read
  content.gsub!(/(Homebrew is generously supported by) .*\Z/m, "\\1 #{named_sponsors.to_sentence}.\n")
  content << "\n#{logo_sponsors.join}\n" if logo_sponsors.presence

  File.write(readme, content)

  diff = system_command "git", args: [
    "-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", "README.md"
  ]
  if diff.status.success?
    ofail "No changes to list of sponsors."
  else
    puts "List of sponsors updated in the README."
  end
end