diff --git a/Library/Homebrew/dev-cmd/contributions.rb b/Library/Homebrew/dev-cmd/contributions.rb index f8e142a047..8e426ae284 100644 --- a/Library/Homebrew/dev-cmd/contributions.rb +++ b/Library/Homebrew/dev-cmd/contributions.rb @@ -42,6 +42,9 @@ module Homebrew flag "--organisation=", "--organization=", "--org=", description: "Specify the organisation to populate sources repositories from. " \ "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=", description: "Date (ISO 8601 format) to start searching contributions. " \ "Omitting this flag searches the past year." @@ -50,6 +53,8 @@ module Homebrew switch "--csv", description: "Print a CSV of contributions across repositories over the time period." conflicts "--organisation", "--repositories" + conflicts "--organisation", "--team" + conflicts "--user", "--team" end sig { override.void } @@ -58,15 +63,34 @@ module Homebrew Homebrew.install_bundler_gems!(groups: ["contributions"]) if args.csv? + require "utils/github" + results = {} grand_totals = {} - from = args.from.presence || Date.today.prev_year.iso8601 to = args.to.presence || (Date.today + 1).iso8601 - 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 + puts "Getting repositories for #{organisation}..." if args.verbose? GitHub.organisation_repositories(organisation, from, to, args.verbose?) elsif (repos = args.repositories.presence) && repos.length == 1 && (first_repository = repos.first) case first_repository @@ -87,8 +111,6 @@ module Homebrew end 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| # TODO: Using the GitHub username to scan the `git log` undercounts some # contributions as people might not always have configured their Git diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/contributions.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/contributions.rbi index e6eb70105c..0d029246d9 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/contributions.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/contributions.rbi @@ -29,6 +29,9 @@ class Homebrew::DevCmd::Contributions::Args < Homebrew::CLI::Args sig { returns(T.nilable(T::Array[String])) } def repositories; end + sig { returns(T.nilable(String)) } + def team; end + sig { returns(T.nilable(String)) } def to; end diff --git a/completions/bash/brew b/completions/bash/brew index 99aeca8611..66ddbcce32 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -821,6 +821,7 @@ _brew_contributions() { --organisation --quiet --repositories + --team --to --user --verbose diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 242886064d..41b9985c44 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -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 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 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 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' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index d87643f269..a1b2fbb6d1 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -769,11 +769,12 @@ _brew_contributions() { '--debug[Display any debugging information]' \ '--from[Date (ISO 8601 format) to start searching contributions. Omitting this flag searches the past year]' \ '--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]' \ '(--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]' \ - '--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]' } diff --git a/docs/Manpage.md b/docs/Manpage.md index 0817324d04..2ccde61c8e 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -2426,6 +2426,11 @@ Summarise contributions to Homebrew repositories. : Specify the organisation to populate sources repositories from. Omitting this 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` : Date (ISO 8601 format) to start searching contributions. Omitting this flag diff --git a/manpages/brew.1 b/manpages/brew.1 index 31ccbadb6c..eeccf08110 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1520,6 +1520,9 @@ Specify a comma\-separated list of repositories to search\. All repositories mus \fB\-\-organisation\fP Specify the organisation to populate sources repositories from\. Omitting this flag searches the Homebrew primary repositories\. .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 Date (ISO 8601 format) to start searching contributions\. Omitting this flag searches the past year\. .TP