brew/Library/Homebrew/dev-cmd/update-maintainers.rb
Mike McQuaid af6165aab7
Automate sponsors updates
- Add sponsors updating to the existing man/completion/maintainer update workflow
- Hide/deprecated --fail-if-not-changed arguments and make them default behaviour
- Rename man-completions workflow to sponsors-maintainers-man-completions for consistency
- Make output and exit codes more consistent between these updating commands
- Fix maintainers updates not always being committed correctly
2022-09-02 08:24:33 +01:00

70 lines
2.0 KiB
Ruby

# typed: false
# frozen_string_literal: true
require "cli/parser"
require "utils/github"
# TODO: move function to manpages.rb and require that instead
require "dev-cmd/generate-man-completions"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def update_maintainers_args
Homebrew::CLI::Parser.new do
description <<~EOS
Update the list of maintainers in the `Homebrew/brew` README.
EOS
named_args :none
end
end
def update_maintainers
update_maintainers_args.parse
# We assume that only public members wish to be included in the README
public_members = GitHub.public_member_usernames("Homebrew")
members = {
plc: GitHub.members_by_team("Homebrew", "plc"),
tsc: GitHub.members_by_team("Homebrew", "tsc"),
}
members[:other] = GitHub.members_by_team("Homebrew", "maintainers")
.except(*members.values.map(&:keys).flatten.uniq)
sentences = {}
members.each do |group, hash|
hash.slice!(*public_members)
hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" }
sentences[group] = hash.values.sort.to_sentence
end
readme = HOMEBREW_REPOSITORY/"README.md"
content = readme.read
content.gsub!(/(Homebrew's \[Project Leadership Committee.*) is .*\./,
"\\1 is #{sentences[:plc]}.")
content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./,
"\\1 is #{sentences[:tsc]}.")
content.gsub!(/(Homebrew's other current maintainers are).*\./,
"\\1 #{sentences[:other]}.")
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 maintainers."
else
# TODO: move function to manpages.rb and call that instead
Homebrew.regenerate_man_pages(quiet: true)
puts "List of maintainers updated in the README and the generated man pages."
end
end
end