diff --git a/Library/Homebrew/dev-cmd/sponsors.rb b/Library/Homebrew/dev-cmd/sponsors.rb index 85e0daec19..934ba0744e 100644 --- a/Library/Homebrew/dev-cmd/sponsors.rb +++ b/Library/Homebrew/dev-cmd/sponsors.rb @@ -13,51 +13,61 @@ module Homebrew def sponsors_args Homebrew::CLI::Parser.new do description <<~EOS - Print a Markdown summary of Homebrew's GitHub Sponsors, suitable for pasting into a README. + Update the list of GitHub Sponsors in the `Homebrew/brew` README. EOS named_args :none end end + def sponsor_name(s) + s["name"] || s["login"] + end + + def sponsor_logo(s) + "https://github.com/#{s["login"]}.png?size=64" + end + + def sponsor_url(s) + "https://github.com/#{s["login"]}" + end + def sponsors sponsors_args.parse - sponsors = { - "named" => [], - "users" => 0, - "orgs" => 0, - } + named_sponsors = [] + logo_sponsors = [] 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" } + if tier["tier"] >= 100 + named_sponsors += tier["sponsors"].map do |s| + "[#{sponsor_name(s)}](#{sponsor_url(s)})" + end + end + + next unless tier["tier"] >= 1000 + + logo_sponsors += tier["sponsors"].map do |s| + "[![#{sponsor_name(s)}](#{sponsor_logo(s)})](#{sponsor_url(s)})" + end end - items = [] - items += sponsors["named"].map { |s| "[#{s["name"]}](https://github.com/#{s["login"]})" } + named_sponsors << "many other users and organisations via [GitHub Sponsors](https://github.com/sponsors/Homebrew)" - anon_users = sponsors["users"] - sponsors["named"].length - sponsors["orgs"] + 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 - items << if items.length > 1 - "#{anon_users} other users" + File.open(readme, "w+") { |f| f.write(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 - "#{anon_users} users" + puts "List of sponsors updated in the README." 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 diff --git a/README.md b/README.md index 0490277333..c44392b4bf 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,6 @@ Homebrew is a member of the [Software Freedom Conservancy](https://sfconservancy [![Software Freedom Conservancy](https://sfconservancy.org/img/conservancy_64x64.png)](https://sfconservancy.org) -Homebrew is generously supported by [Randy Reddig](https://github.com/ydnar) and 439 other users via [GitHub Sponsors](https://github.com/sponsors/Homebrew). +Homebrew is generously supported by [Substack](https://github.com/substackinc), [Randy Reddig](https://github.com/ydnar), [embark-studios](https://github.com/embark-studios) and many other users and organisations via [GitHub Sponsors](https://github.com/sponsors/Homebrew). + +[![Substack](https://github.com/substackinc.png?size=64)](https://github.com/substackinc) diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index a2c251d9b9..88c2de9ab4 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -1225,7 +1225,7 @@ __fish_brew_complete_arg 'sh' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'sh' -l verbose -d 'Make some output more verbose' -__fish_brew_complete_cmd 'sponsors' 'Print a Markdown summary of Homebrew\'s GitHub Sponsors, suitable for pasting into a README' +__fish_brew_complete_cmd 'sponsors' 'Update the list of GitHub Sponsors in the `Homebrew/brew` README' __fish_brew_complete_arg 'sponsors' -l debug -d 'Display any debugging information' __fish_brew_complete_arg 'sponsors' -l help -d 'Show this message' __fish_brew_complete_arg 'sponsors' -l quiet -d 'Make some output more quiet' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 22c4e2e749..821684dc31 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -196,7 +196,7 @@ __brew_internal_commands() { 'search:Perform a substring search of cask tokens and formula names for text' 'sh:Enter an interactive shell for Homebrew'\''s build environment' 'shellenv:Print export statements' - 'sponsors:Print a Markdown summary of Homebrew'\''s GitHub Sponsors, suitable for pasting into a README' + 'sponsors:Update the list of GitHub Sponsors in the `Homebrew/brew` README' 'style:Check formulae or files for conformance to Homebrew style guidelines' 'tap:Tap a formula repository' 'tap-info:Show detailed information about one or more taps' diff --git a/docs/Manpage.md b/docs/Manpage.md index 28fe70f689..8460fab863 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1259,7 +1259,7 @@ which build systems would not find otherwise. ### `sponsors` -Print a Markdown summary of Homebrew's GitHub Sponsors, suitable for pasting into a README. +Update the list of GitHub Sponsors in the `Homebrew/brew` README. ### `style` [*`options`*] [*`file`*|*`tap`*|*`formula`*|*`cask`* ...] diff --git a/manpages/brew.1 b/manpages/brew.1 index 9c290e7d91..756f71c1c2 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1737,7 +1737,7 @@ Use the standard \fBPATH\fR instead of superenv\'s when \fBstd\fR is passed\. Execute commands in a non\-interactive shell\. . .SS "\fBsponsors\fR" -Print a Markdown summary of Homebrew\'s GitHub Sponsors, suitable for pasting into a README\. +Update the list of GitHub Sponsors in the \fBHomebrew/brew\fR README\. . .SS "\fBstyle\fR [\fIoptions\fR] [\fIfile\fR|\fItap\fR|\fIformula\fR|\fIcask\fR \.\.\.]" Check formulae or files for conformance to Homebrew style guidelines\.