brew update-maintainers: dev-cmd to update maintainers in README

This commit is contained in:
nandahkrishna 2021-02-04 17:00:50 +05:30
parent 066ef6b43e
commit 6026c7c74d
No known key found for this signature in database
GPG Key ID: 067E5FCD58ADF3AA
3 changed files with 94 additions and 1 deletions

View File

@ -37,7 +37,7 @@ Metrics/PerceivedComplexity:
Metrics/MethodLength:
Max: 260
Metrics/ModuleLength:
Max: 600
Max: 650
Exclude:
- "test/**/*"

View File

@ -0,0 +1,64 @@
# typed: false
# frozen_string_literal: true
require "cli/parser"
require "utils/github"
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")
plc = GitHub.members_by_team("Homebrew", "plc")
tsc = GitHub.members_by_team("Homebrew", "tsc")
linux = GitHub.members_by_team("Homebrew", "linux")
other = GitHub.members_by_team("Homebrew", "maintainers")
other.except!(*[plc, tsc, linux].map(&:keys).flatten.uniq)
sentences = [plc, tsc, linux, other].map do |h|
h.slice!(*public_members)
h.each { |k, v| h[k] = "[#{v}](https://github.com/#{k})" }
h.values.sort.to_sentence
end
readme = HOMEBREW_REPOSITORY/"README.md"
content = readme.read
content.gsub!(/(Homebrew's \[Project Leadership Committee.*) is .*\./,
"\\1 is #{sentences[0]}.")
content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./,
"\\1 is #{sentences[1]}.")
content.gsub!(%r{(Homebrew/brew's Linux maintainers are).*\.},
"\\1 #{sentences[2]}.")
content.gsub!(/(Homebrew's other current maintainers are).*\./,
"\\1 #{sentences[3]}.")
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 maintainers."
else
puts "List of maintainers updated in README."
end
end
end

View File

@ -572,6 +572,35 @@ module GitHub
artifact.first["archive_download_url"]
end
def public_member_usernames(org, per_page: 100)
url = "#{API_URL}/orgs/#{org}/public_members?per_page=#{per_page}"
members = []
(1..API_MAX_PAGES).each do |page|
result = open_api(url + "&page=#{page}").map { |m| m["login"] }
members.concat(result)
return members if result.length < per_page
end
end
def members_by_team(org, team)
query = <<~EOS
{ organization(login: "#{org}") {
team(slug: "#{team}") {
members(first: 100) {
nodes {
... on User { login name }
}
}
}
}
}
EOS
result = open_graphql(query, scopes: ["read:org", "user"])
result["organization"]["team"]["members"]["nodes"].map { |m| [m["login"], m["name"]] }.to_h
end
def sponsors_by_tier(user)
query = <<~EOS
{ organization(login: "#{user}") {