Merge pull request #10615 from jonchang/enhance-sponsors

Update Github sponsor text and logos
This commit is contained in:
Jonathan Chang 2021-02-16 14:06:11 +11:00 committed by GitHub
commit a946cde4e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 34 deletions

View File

@ -13,51 +13,61 @@ module Homebrew
def sponsors_args def sponsors_args
Homebrew::CLI::Parser.new do Homebrew::CLI::Parser.new do
description <<~EOS 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 EOS
named_args :none named_args :none
end end
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 def sponsors
sponsors_args.parse sponsors_args.parse
sponsors = { named_sponsors = []
"named" => [], logo_sponsors = []
"users" => 0,
"orgs" => 0,
}
GitHub.sponsors_by_tier("Homebrew").each do |tier| GitHub.sponsors_by_tier("Homebrew").each do |tier|
sponsors["named"] += tier["sponsors"] if tier["tier"] >= 100 if tier["tier"] >= 100
sponsors["users"] += tier["count"] named_sponsors += tier["sponsors"].map do |s|
sponsors["orgs"] += tier["sponsors"].count { |s| s["type"] == "organization" } "[#{sponsor_name(s)}](#{sponsor_url(s)})"
end
end end
items = [] next unless tier["tier"] >= 1000
items += sponsors["named"].map { |s| "[#{s["name"]}](https://github.com/#{s["login"]})" }
anon_users = sponsors["users"] - sponsors["named"].length - sponsors["orgs"] logo_sponsors += tier["sponsors"].map do |s|
"[![#{sponsor_name(s)}](#{sponsor_logo(s)})](#{sponsor_url(s)})"
end
end
items << if items.length > 1 named_sponsors << "many other users and organisations via [GitHub Sponsors](https://github.com/sponsors/Homebrew)"
"#{anon_users} other users"
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.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 else
"#{anon_users} users" puts "List of sponsors updated in the README."
end 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
end end

View File

@ -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) [![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)

View File

@ -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_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 debug -d 'Display any debugging information'
__fish_brew_complete_arg 'sponsors' -l help -d 'Show this message' __fish_brew_complete_arg 'sponsors' -l help -d 'Show this message'
__fish_brew_complete_arg 'sponsors' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'sponsors' -l quiet -d 'Make some output more quiet'

View File

@ -196,7 +196,7 @@ __brew_internal_commands() {
'search:Perform a substring search of cask tokens and formula names for text' 'search:Perform a substring search of cask tokens and formula names for text'
'sh:Enter an interactive shell for Homebrew'\''s build environment' 'sh:Enter an interactive shell for Homebrew'\''s build environment'
'shellenv:Print export statements' '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' 'style:Check formulae or files for conformance to Homebrew style guidelines'
'tap:Tap a formula repository' 'tap:Tap a formula repository'
'tap-info:Show detailed information about one or more taps' 'tap-info:Show detailed information about one or more taps'

View File

@ -1259,7 +1259,7 @@ which build systems would not find otherwise.
### `sponsors` ### `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`* ...] ### `style` [*`options`*] [*`file`*|*`tap`*|*`formula`*|*`cask`* ...]

View File

@ -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\. Execute commands in a non\-interactive shell\.
. .
.SS "\fBsponsors\fR" .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 \.\.\.]" .SS "\fBstyle\fR [\fIoptions\fR] [\fIfile\fR|\fItap\fR|\fIformula\fR|\fIcask\fR \.\.\.]"
Check formulae or files for conformance to Homebrew style guidelines\. Check formulae or files for conformance to Homebrew style guidelines\.