From 344d47accc07a56484783d178a0467dc9eb2285b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 8 Sep 2022 12:19:12 +0100 Subject: [PATCH] sponsors-maintainers-man-completions: various fixes. - fix name - use correct command --- .../sponsors-maintainers-man-completions.yml | 6 +++--- Library/Homebrew/dev-cmd/update-sponsors.rb | 5 ++++- Library/Homebrew/utils/github.rb | 13 ++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sponsors-maintainers-man-completions.yml b/.github/workflows/sponsors-maintainers-man-completions.yml index 778cce8e7a..a1187a4832 100644 --- a/.github/workflows/sponsors-maintainers-man-completions.yml +++ b/.github/workflows/sponsors-maintainers-man-completions.yml @@ -45,7 +45,7 @@ jobs: key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} restore-keys: ${{ runner.os }}-rubygems- - - name: Update maintainers, manpage and completions + - name: Update sponsors, maintainers, manpage and completions id: update run: | git fetch origin @@ -69,7 +69,7 @@ jobs: git checkout --no-track -B "${BRANCH}" origin/master fi - if brew sponsors + if brew update-sponsors then git add "${GITHUB_WORKSPACE}/README.md" git commit -m "Update sponsors." \ @@ -109,7 +109,7 @@ jobs: fi env: GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} - HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_BREW_UPDATE_MAINTAINERS_TOKEN }} + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_BREW_UPDATE_SPONSORS_MAINTAINERS_TOKEN }} HOMEBREW_GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }} - name: Push commits diff --git a/Library/Homebrew/dev-cmd/update-sponsors.rb b/Library/Homebrew/dev-cmd/update-sponsors.rb index 52881fb944..dc5b62b277 100644 --- a/Library/Homebrew/dev-cmd/update-sponsors.rb +++ b/Library/Homebrew/dev-cmd/update-sponsors.rb @@ -40,9 +40,10 @@ module Homebrew named_sponsors = [] logo_sponsors = [] + largest_monthly_amount = 0 GitHub.sponsorships("Homebrew").each do |s| - largest_monthly_amount = [s[:monthly_amount], s[:closest_tier_monthly_amount]].compact.max + 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 next if largest_monthly_amount < URL_MONTHLY_AMOUNT @@ -50,6 +51,8 @@ module Homebrew logo_sponsors << "[![#{sponsor_name(s)}](#{sponsor_logo(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" diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index c97f92db2e..0d7472784b 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -444,7 +444,9 @@ module GitHub current_sponsorships = result["data"]["organization"]["sponsorshipsAsMaintainer"] # The organisations mentioned above will show up as nil nodes. - sponsorships += current_sponsorships["nodes"].compact + if (nodes = current_sponsorships["nodes"].compact.presence) + sponsorships += nodes + end if (page_info = current_sponsorships["pageInfo"].presence) && page_info["hasNextPage"].presence @@ -460,16 +462,17 @@ module GitHub end sponsorships.map do |sponsorship| - closest_tier_monthly_amount = sponsorship["tier"].fetch("closestLesserValueTier", nil) - &.fetch("monthlyPriceInDollars", nil) - monthly_amount = sponsorship["tier"]["monthlyPriceInDollars"] sponsor = sponsorship["sponsorEntity"] + tier = sponsorship["tier"].presence || {} + monthly_amount = tier["monthlyPriceInDollars"].presence || 0 + closest_tier = tier["closestLesserValueTier"].presence || {} + closest_tier_monthly_amount = closest_tier["monthlyPriceInDollars"].presence || 0 { name: sponsor["name"].presence || sponsor["login"], login: sponsor["login"], monthly_amount: monthly_amount, - closest_tier_monthly_amount: closest_tier_monthly_amount || 0, + closest_tier_monthly_amount: closest_tier_monthly_amount, } end end