dev-cmd/contributions: add --team flag.

This allows specifying an organisation team instead of an organisation
or individual users.
This commit is contained in:
Mike McQuaid 2025-09-11 11:36:48 +01:00
parent 610c67b715
commit 3d80dfadd1
No known key found for this signature in database
7 changed files with 43 additions and 7 deletions

View File

@ -42,6 +42,9 @@ module Homebrew
flag "--organisation=", "--organization=", "--org=", flag "--organisation=", "--organization=", "--org=",
description: "Specify the organisation to populate sources repositories from. " \ description: "Specify the organisation to populate sources repositories from. " \
"Omitting this flag searches the Homebrew primary repositories." "Omitting this flag searches the Homebrew primary repositories."
flag "--team=",
description: "Specify the team to populate users from. " \
"The first part of the team name will be used as the organisation."
flag "--from=", flag "--from=",
description: "Date (ISO 8601 format) to start searching contributions. " \ description: "Date (ISO 8601 format) to start searching contributions. " \
"Omitting this flag searches the past year." "Omitting this flag searches the past year."
@ -50,6 +53,8 @@ module Homebrew
switch "--csv", switch "--csv",
description: "Print a CSV of contributions across repositories over the time period." description: "Print a CSV of contributions across repositories over the time period."
conflicts "--organisation", "--repositories" conflicts "--organisation", "--repositories"
conflicts "--organisation", "--team"
conflicts "--user", "--team"
end end
sig { override.void } sig { override.void }
@ -58,15 +63,34 @@ module Homebrew
Homebrew.install_bundler_gems!(groups: ["contributions"]) if args.csv? Homebrew.install_bundler_gems!(groups: ["contributions"]) if args.csv?
require "utils/github"
results = {} results = {}
grand_totals = {} grand_totals = {}
from = args.from.presence || Date.today.prev_year.iso8601 from = args.from.presence || Date.today.prev_year.iso8601
to = args.to.presence || (Date.today + 1).iso8601 to = args.to.presence || (Date.today + 1).iso8601
organisation = nil organisation = nil
repositories = if (org = args.organisation.presence)
users = if (team = args.team.presence)
team_sections = team.split("/")
organisation = team_sections.first.presence
team_name = team_sections.last.presence
if team_sections.length != 2 || organisation.nil? || team_name.nil?
odie "Team must be in the format `organisation/team`!"
end
puts "Getting members for #{organisation}/#{team_name}..." if args.verbose?
GitHub.members_by_team(organisation, team_name).keys
elsif (users = args.user.presence)
users
else
puts "Getting members for Homebrew/maintainers..." if args.verbose?
GitHub.members_by_team("Homebrew", "maintainers").keys
end
repositories = if (org = organisation.presence) || (org = args.organisation.presence)
organisation = org organisation = org
puts "Getting repositories for #{organisation}..." if args.verbose?
GitHub.organisation_repositories(organisation, from, to, args.verbose?) GitHub.organisation_repositories(organisation, from, to, args.verbose?)
elsif (repos = args.repositories.presence) && repos.length == 1 && (first_repository = repos.first) elsif (repos = args.repositories.presence) && repos.length == 1 && (first_repository = repos.first)
case first_repository case first_repository
@ -87,8 +111,6 @@ module Homebrew
end end
organisation ||= T.must(repositories.fetch(0).split("/").first) organisation ||= T.must(repositories.fetch(0).split("/").first)
require "utils/github"
users = args.user.presence || GitHub.members_by_team("Homebrew", "maintainers").keys
users.each do |username| users.each do |username|
# TODO: Using the GitHub username to scan the `git log` undercounts some # TODO: Using the GitHub username to scan the `git log` undercounts some
# contributions as people might not always have configured their Git # contributions as people might not always have configured their Git

View File

@ -29,6 +29,9 @@ class Homebrew::DevCmd::Contributions::Args < Homebrew::CLI::Args
sig { returns(T.nilable(T::Array[String])) } sig { returns(T.nilable(T::Array[String])) }
def repositories; end def repositories; end
sig { returns(T.nilable(String)) }
def team; end
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
def to; end def to; end

View File

@ -821,6 +821,7 @@ _brew_contributions() {
--organisation --organisation
--quiet --quiet
--repositories --repositories
--team
--to --to
--user --user
--verbose --verbose

View File

@ -605,6 +605,7 @@ __fish_brew_complete_arg 'contributions' -l help -d 'Show this message'
__fish_brew_complete_arg 'contributions' -l organisation -d 'Specify the organisation to populate sources repositories from. Omitting this flag searches the Homebrew primary repositories' __fish_brew_complete_arg 'contributions' -l organisation -d 'Specify the organisation to populate sources repositories from. Omitting this flag searches the Homebrew primary repositories'
__fish_brew_complete_arg 'contributions' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'contributions' -l quiet -d 'Make some output more quiet'
__fish_brew_complete_arg 'contributions' -l repositories -d 'Specify a comma-separated list of repositories to search. All repositories must be under the same user or organisation. Omitting this flag, or specifying `--repositories=primary`, searches only the main repositories: `Homebrew/brew`, `Homebrew/homebrew-core`, `Homebrew/homebrew-cask`. Specifying `--repositories=all` searches all non-deprecated Homebrew repositories. ' __fish_brew_complete_arg 'contributions' -l repositories -d 'Specify a comma-separated list of repositories to search. All repositories must be under the same user or organisation. Omitting this flag, or specifying `--repositories=primary`, searches only the main repositories: `Homebrew/brew`, `Homebrew/homebrew-core`, `Homebrew/homebrew-cask`. Specifying `--repositories=all` searches all non-deprecated Homebrew repositories. '
__fish_brew_complete_arg 'contributions' -l team -d 'Specify the team to populate users from. The first part of the team name will be used as the organisation'
__fish_brew_complete_arg 'contributions' -l to -d 'Date (ISO 8601 format) to stop searching contributions' __fish_brew_complete_arg 'contributions' -l to -d 'Date (ISO 8601 format) to stop searching contributions'
__fish_brew_complete_arg 'contributions' -l user -d 'Specify a comma-separated list of GitHub usernames or email addresses to find contributions from. Omitting this flag searches Homebrew maintainers' __fish_brew_complete_arg 'contributions' -l user -d 'Specify a comma-separated list of GitHub usernames or email addresses to find contributions from. Omitting this flag searches Homebrew maintainers'
__fish_brew_complete_arg 'contributions' -l verbose -d 'Make some output more verbose' __fish_brew_complete_arg 'contributions' -l verbose -d 'Make some output more verbose'

View File

@ -769,11 +769,12 @@ _brew_contributions() {
'--debug[Display any debugging information]' \ '--debug[Display any debugging information]' \
'--from[Date (ISO 8601 format) to start searching contributions. Omitting this flag searches the past year]' \ '--from[Date (ISO 8601 format) to start searching contributions. Omitting this flag searches the past year]' \
'--help[Show this message]' \ '--help[Show this message]' \
'(--repositories)--organisation[Specify the organisation to populate sources repositories from. Omitting this flag searches the Homebrew primary repositories]' \ '(--repositories --team)--organisation[Specify the organisation to populate sources repositories from. Omitting this flag searches the Homebrew primary repositories]' \
'--quiet[Make some output more quiet]' \ '--quiet[Make some output more quiet]' \
'(--organisation)--repositories[Specify a comma-separated list of repositories to search. All repositories must be under the same user or organisation. Omitting this flag, or specifying `--repositories=primary`, searches only the main repositories: `Homebrew/brew`, `Homebrew/homebrew-core`, `Homebrew/homebrew-cask`. Specifying `--repositories=all` searches all non-deprecated Homebrew repositories. ]' \ '(--organisation)--repositories[Specify a comma-separated list of repositories to search. All repositories must be under the same user or organisation. Omitting this flag, or specifying `--repositories=primary`, searches only the main repositories: `Homebrew/brew`, `Homebrew/homebrew-core`, `Homebrew/homebrew-cask`. Specifying `--repositories=all` searches all non-deprecated Homebrew repositories. ]' \
'(--organisation --user)--team[Specify the team to populate users from. The first part of the team name will be used as the organisation]' \
'--to[Date (ISO 8601 format) to stop searching contributions]' \ '--to[Date (ISO 8601 format) to stop searching contributions]' \
'--user[Specify a comma-separated list of GitHub usernames or email addresses to find contributions from. Omitting this flag searches Homebrew maintainers]' \ '(--team)--user[Specify a comma-separated list of GitHub usernames or email addresses to find contributions from. Omitting this flag searches Homebrew maintainers]' \
'--verbose[Make some output more verbose]' '--verbose[Make some output more verbose]'
} }

View File

@ -2426,6 +2426,11 @@ Summarise contributions to Homebrew repositories.
: Specify the organisation to populate sources repositories from. Omitting this : Specify the organisation to populate sources repositories from. Omitting this
flag searches the Homebrew primary repositories. flag searches the Homebrew primary repositories.
`--team`
: Specify the team to populate users from. The first part of the team name will
be used as the organisation.
`--from` `--from`
: Date (ISO 8601 format) to start searching contributions. Omitting this flag : Date (ISO 8601 format) to start searching contributions. Omitting this flag

View File

@ -1520,6 +1520,9 @@ Specify a comma\-separated list of repositories to search\. All repositories mus
\fB\-\-organisation\fP \fB\-\-organisation\fP
Specify the organisation to populate sources repositories from\. Omitting this flag searches the Homebrew primary repositories\. Specify the organisation to populate sources repositories from\. Omitting this flag searches the Homebrew primary repositories\.
.TP .TP
\fB\-\-team\fP
Specify the team to populate users from\. The first part of the team name will be used as the organisation\.
.TP
\fB\-\-from\fP \fB\-\-from\fP
Date (ISO 8601 format) to start searching contributions\. Omitting this flag searches the past year\. Date (ISO 8601 format) to start searching contributions\. Omitting this flag searches the past year\.
.TP .TP