Class: Homebrew::DevCmd::UpdateSponsors Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::UpdateSponsors
- Includes:
- SystemCommand::Mixin
- Defined in:
- dev-cmd/update-sponsors.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/update_sponsors.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Defined Under Namespace
Classes: Args
Instance Method Summary collapse
- #args ⇒ Homebrew::DevCmd::UpdateSponsors::Args private
- #run ⇒ void private
Methods included from SystemCommand::Mixin
#command_sandbox, #system_command, #system_command!
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::DevCmd::UpdateSponsors::Args
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/update_sponsors.rbi', line 10 def args; end |
#run ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'dev-cmd/update-sponsors.rb', line 28 def run tiers = GitHub.sponsorship_tiers("Homebrew") odie "No sponsorship tiers found!" if tiers.empty? sponsorships = GitHub.sponsorships("Homebrew").map do |s| { name: s[:name], type: s[:type], monthly_amount: s[:monthly_amount], tier_descriptions: [s[:tier_description]] + Sponsors.legacy_tier_descriptions(s[:monthly_amount], s[:started_at]), url: "https://github.com/#{s[:login]}", logo: "https://github.com/#{s[:login]}.png?size=64" } end sponsorships.concat(Sponsors.github_one_time) sponsorships_by_platform = { "[many others](https://github.com/sponsors/Homebrew#sponsors) via " \ "[GitHub Sponsors](https://github.com/sponsors/Homebrew)" => sponsorships, "[many others](https://opencollective.com/homebrew/transactions?kind=ADDED_FUNDS&kind=CONTRIBUTION) via " \ "[Open Collective](https://opencollective.com/homebrew)" => Sponsors.open_collective, "[many others](https://www.patreon.com/homebrew) via " \ "[Patreon](https://www.patreon.com/homebrew)" => Sponsors.patreon, } unless sponsorships_by_platform.values.flatten.any? { |s| s[:monthly_amount].positive? } odie "No sponsorship amounts found! Ensure you have sufficient permissions!" end named_sponsors = [] logo_sponsors = [] sponsorships_by_platform.each do |other_sponsors, sponsors| names = {} linked_names = {} sponsors.sort_by { |s| [-s[:monthly_amount], s[:name].downcase, s[:name], s[:url]] }.each do |s| applicable_tiers = [ *tiers, *s[:tier_descriptions].map { |description| { description:, monthly_amount: s[:monthly_amount] } }, ].select do |tier| next false if s[:monthly_amount] < tier[:monthly_amount] description = tier[:description] description.match?(/\bREADME\b/i) && (s[:type] != "Organization" || !description.match?(/\bindividuals only\b/i)) end next if applicable_tiers.empty? escaped_name = s[:name].gsub(/[[:cntrl:]]+/, " ").strip .gsub(/[\\`*_\[\]<>&~]/) { |character| "\\#{character}" } names[escaped_name] ||= escaped_name next unless applicable_tiers.any? { |tier| tier[:description].match?(/\blogo\b/i) } unless [s[:logo], s[:url]].all? do |url| uri = URI.parse(url) uri.is_a?(URI::HTTPS) && uri.host.present? && !url.match?(/[[:space:]()<>\\]/) rescue URI::InvalidURIError false end opoo "Invalid logo or profile URL for #{escaped_name}." next end linked_names[escaped_name] = "[#{escaped_name}](#{s[:url]})" logo_sponsors << "[](#{s[:url]})" end names = linked_names.merge(names.except(*linked_names.keys)) named_sponsors << "- #{Utils::Text.to_sentence([*names.values, other_sponsors])}." end readme = HOMEBREW_REPOSITORY/"README.md" content = readme.read content.gsub!(/(Homebrew is generously supported by)[: ].*\Z/m) do "#{Regexp.last_match(1)}:\n\n#{named_sponsors.join("\n")}\n" end content << "\n<!-- release-sponsors -->\n" content << "#{logo_sponsors.uniq.join("\n")}\n" if logo_sponsors.present? content << "<!-- /release-sponsors -->\n" File.write(readme, content) diff = system_command "git", args: [ "-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", "README.md" ] if diff.status.success? puts "No changes to list of sponsors." else puts "List of sponsors updated in the README." end end |