2022-07-24 22:06:00 +01:00
|
|
|
# typed: true
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cli/parser"
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
require "csv"
|
2022-07-24 22:06:00 +01:00
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module_function
|
|
|
|
|
2023-02-19 18:26:07 +00:00
|
|
|
PRIMARY_REPOS = %w[brew core cask].freeze
|
2022-07-29 21:20:16 +01:00
|
|
|
SUPPORTED_REPOS = [
|
2023-02-19 18:26:07 +00:00
|
|
|
PRIMARY_REPOS,
|
2022-07-29 21:20:16 +01:00
|
|
|
OFFICIAL_CMD_TAPS.keys.map { |t| t.delete_prefix("homebrew/") },
|
2022-08-03 16:48:40 +01:00
|
|
|
OFFICIAL_CASK_TAPS.reject { |t| t == "cask" },
|
2022-07-29 21:20:16 +01:00
|
|
|
].flatten.freeze
|
2022-07-24 22:06:00 +01:00
|
|
|
|
|
|
|
sig { returns(CLI::Parser) }
|
|
|
|
def contributions_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2023-02-20 00:14:53 +00:00
|
|
|
usage_banner "`contributions` [--user=<email|username>] [<--repositories>`=`] [<--csv>]"
|
2022-07-28 12:50:04 +01:00
|
|
|
description <<~EOS
|
2023-02-20 00:14:53 +00:00
|
|
|
Contributions to Homebrew repos.
|
2022-07-24 22:06:00 +01:00
|
|
|
EOS
|
|
|
|
|
2022-08-03 17:01:52 +01:00
|
|
|
comma_array "--repositories",
|
|
|
|
description: "Specify a comma-separated (no spaces) list of repositories to search. " \
|
2023-02-20 16:16:08 +00:00
|
|
|
"Supported repositories: #{SUPPORTED_REPOS.map { |t| "`#{t}`" }.to_sentence}. " \
|
|
|
|
"Omitting this flag, or specifying `--repositories=all`, searches all repositories. " \
|
2023-02-19 18:26:07 +00:00
|
|
|
"Use `--repositories=primary` to search only the main repositories: brew,core,cask."
|
2022-07-24 22:06:00 +01:00
|
|
|
flag "--from=",
|
|
|
|
description: "Date (ISO-8601 format) to start searching contributions."
|
|
|
|
|
|
|
|
flag "--to=",
|
|
|
|
description: "Date (ISO-8601 format) to stop searching contributions."
|
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
flag "--user=",
|
|
|
|
description: "A GitHub username or email address of a specific person to find contribution data for."
|
|
|
|
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
switch "--csv",
|
2023-02-23 23:27:38 +00:00
|
|
|
description: "Print a CSV of contributions across repositories over the time period."
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-03 10:19:03 +01:00
|
|
|
sig { void }
|
2022-07-24 22:06:00 +01:00
|
|
|
def contributions
|
|
|
|
args = contributions_args.parse
|
|
|
|
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
results = {}
|
2023-02-23 23:27:38 +00:00
|
|
|
grand_totals = {}
|
2022-07-24 22:06:00 +01:00
|
|
|
|
2022-08-03 17:01:52 +01:00
|
|
|
all_repos = args.repositories.nil? || args.repositories.include?("all")
|
2023-02-19 18:26:07 +00:00
|
|
|
repos = if all_repos
|
|
|
|
SUPPORTED_REPOS
|
|
|
|
elsif args.repositories.include?("primary")
|
|
|
|
PRIMARY_REPOS
|
|
|
|
else
|
|
|
|
args.repositories
|
|
|
|
end
|
2022-07-31 21:25:20 +01:00
|
|
|
|
2023-02-22 16:48:31 +00:00
|
|
|
if args.user
|
|
|
|
user = args.user
|
|
|
|
results[user] = scan_repositories(repos, user, args)
|
2023-02-23 23:27:38 +00:00
|
|
|
grand_totals[user] = total(results[user])
|
|
|
|
|
2023-03-19 23:17:15 -04:00
|
|
|
puts "#{user} contributed #{Utils.pluralize("time", grand_totals[user].values.sum,
|
2023-03-20 07:23:17 -04:00
|
|
|
include_count: true)} #{time_period(args)}."
|
2023-02-23 23:27:38 +00:00
|
|
|
puts generate_csv(T.must(user), results[user], grand_totals[user]) if args.csv?
|
2023-02-22 16:48:31 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
maintainers = GitHub.members_by_team("Homebrew", "maintainers")
|
|
|
|
maintainers.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
|
|
|
|
# committer details to match the ones on GitHub.
|
|
|
|
# TODO: Switch to using the GitHub APIs instead of `git log` if
|
|
|
|
# they ever support trailers.
|
|
|
|
results[username] = scan_repositories(repos, username, args)
|
2023-02-23 23:27:38 +00:00
|
|
|
grand_totals[username] = total(results[username])
|
|
|
|
|
2023-03-19 23:17:15 -04:00
|
|
|
puts "#{username} contributed #{Utils.pluralize("time", grand_totals[username].values.sum,
|
2023-03-20 07:23:17 -04:00
|
|
|
include_count: true)} #{time_period(args)}."
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|
2023-02-23 23:27:38 +00:00
|
|
|
|
|
|
|
puts generate_maintainers_csv(grand_totals) if args.csv?
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|
|
|
|
|
2022-07-24 23:41:00 +01:00
|
|
|
sig { params(repo: String).returns(Pathname) }
|
2022-07-24 22:06:00 +01:00
|
|
|
def find_repo_path_for_repo(repo)
|
2022-07-24 23:18:27 +01:00
|
|
|
return HOMEBREW_REPOSITORY if repo == "brew"
|
|
|
|
|
|
|
|
Tap.fetch("homebrew", repo).path
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|
|
|
|
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
sig { params(args: Homebrew::CLI::Args).returns(String) }
|
|
|
|
def time_period(args)
|
|
|
|
if args.from && args.to
|
|
|
|
"between #{args.from} and #{args.to}"
|
|
|
|
elsif args.from
|
|
|
|
"after #{args.from}"
|
|
|
|
elsif args.to
|
|
|
|
"before #{args.to}"
|
|
|
|
else
|
|
|
|
"in all time"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-23 23:27:38 +00:00
|
|
|
sig { params(totals: Hash).returns(String) }
|
|
|
|
def generate_maintainers_csv(totals)
|
|
|
|
CSV.generate do |csv|
|
2023-03-01 23:38:49 +00:00
|
|
|
csv << %w[user repo author committer coauthorships reviews total]
|
2023-02-25 00:29:37 +00:00
|
|
|
|
2023-02-25 18:04:01 +00:00
|
|
|
totals.sort_by { |_, v| -v.values.sum }.each do |user, total|
|
2023-02-25 00:29:37 +00:00
|
|
|
csv << grand_total_row(user, total)
|
2023-02-23 23:27:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-25 00:29:37 +00:00
|
|
|
sig { params(user: String, results: Hash, grand_total: Hash).returns(String) }
|
2023-02-23 23:27:38 +00:00
|
|
|
def generate_csv(user, results, grand_total)
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
CSV.generate do |csv|
|
2023-03-01 23:38:49 +00:00
|
|
|
csv << %w[user repo author committer coauthorships reviews total]
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
results.each do |repo, counts|
|
dev-cmd/contributions: Add a per-repo total column to the CSV
```
$ brew contributions issyl0 --csv
The user issyl0 has made 1202 contributions in all time.
user,repo,commits,coauthorships,signoffs,total
issyl0,brew,332,13,0,345
issyl0,core,473,24,326,823
issyl0,cask,4,0,0,4
issyl0,aliases,0,0,0,0
issyl0,autoupdate,1,0,0,1
issyl0,bundle,14,2,0,16
issyl0,command-not-found,1,0,0,1
issyl0,test-bot,3,0,0,3
issyl0,services,9,0,0,9
issyl0,cask-drivers,0,0,0,0
issyl0,cask-fonts,0,0,0,0
issyl0,cask-versions,0,0,0,0
```
2023-02-15 13:56:37 +00:00
|
|
|
csv << [
|
|
|
|
user,
|
|
|
|
repo,
|
2023-03-01 23:38:49 +00:00
|
|
|
counts[:author],
|
|
|
|
counts[:committer],
|
dev-cmd/contributions: Add a per-repo total column to the CSV
```
$ brew contributions issyl0 --csv
The user issyl0 has made 1202 contributions in all time.
user,repo,commits,coauthorships,signoffs,total
issyl0,brew,332,13,0,345
issyl0,core,473,24,326,823
issyl0,cask,4,0,0,4
issyl0,aliases,0,0,0,0
issyl0,autoupdate,1,0,0,1
issyl0,bundle,14,2,0,16
issyl0,command-not-found,1,0,0,1
issyl0,test-bot,3,0,0,3
issyl0,services,9,0,0,9
issyl0,cask-drivers,0,0,0,0
issyl0,cask-fonts,0,0,0,0
issyl0,cask-versions,0,0,0,0
```
2023-02-15 13:56:37 +00:00
|
|
|
counts[:coauthorships],
|
2023-02-25 19:10:17 +00:00
|
|
|
counts[:reviews],
|
2023-02-15 14:04:05 +00:00
|
|
|
counts.values.sum,
|
dev-cmd/contributions: Add a per-repo total column to the CSV
```
$ brew contributions issyl0 --csv
The user issyl0 has made 1202 contributions in all time.
user,repo,commits,coauthorships,signoffs,total
issyl0,brew,332,13,0,345
issyl0,core,473,24,326,823
issyl0,cask,4,0,0,4
issyl0,aliases,0,0,0,0
issyl0,autoupdate,1,0,0,1
issyl0,bundle,14,2,0,16
issyl0,command-not-found,1,0,0,1
issyl0,test-bot,3,0,0,3
issyl0,services,9,0,0,9
issyl0,cask-drivers,0,0,0,0
issyl0,cask-fonts,0,0,0,0
issyl0,cask-versions,0,0,0,0
```
2023-02-15 13:56:37 +00:00
|
|
|
]
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
end
|
2023-02-25 00:29:37 +00:00
|
|
|
csv << grand_total_row(user, grand_total)
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-25 00:29:37 +00:00
|
|
|
sig { params(user: String, grand_total: Hash).returns(Array) }
|
|
|
|
def grand_total_row(user, grand_total)
|
|
|
|
[
|
|
|
|
user,
|
|
|
|
"all",
|
2023-03-01 23:38:49 +00:00
|
|
|
grand_total[:author],
|
|
|
|
grand_total[:committer],
|
2023-02-25 00:29:37 +00:00
|
|
|
grand_total[:coauthorships],
|
2023-02-25 19:10:17 +00:00
|
|
|
grand_total[:reviews],
|
2023-02-25 00:29:37 +00:00
|
|
|
grand_total.values.sum,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
def scan_repositories(repos, person, args)
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
repos.each do |repo|
|
|
|
|
if SUPPORTED_REPOS.exclude?(repo)
|
|
|
|
return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
|
|
|
|
end
|
|
|
|
|
|
|
|
repo_path = find_repo_path_for_repo(repo)
|
|
|
|
tap = Tap.fetch("homebrew", repo)
|
|
|
|
unless repo_path.exist?
|
|
|
|
opoo "Repository #{repo} not yet tapped! Tapping it now..."
|
|
|
|
tap.install
|
|
|
|
end
|
|
|
|
|
|
|
|
repo_full_name = if repo == "brew"
|
|
|
|
"homebrew/brew"
|
|
|
|
else
|
|
|
|
tap.full_name
|
|
|
|
end
|
|
|
|
|
2023-02-22 16:48:31 +00:00
|
|
|
puts "Determining contributions for #{person} on #{repo_full_name}..." if args.verbose?
|
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
data[repo] = {
|
2023-03-05 14:13:48 +00:00
|
|
|
author: GitHub.count_repo_commits(repo_full_name, person, "author", args),
|
|
|
|
committer: GitHub.count_repo_commits(repo_full_name, person, "committer", args),
|
2023-02-22 17:24:10 +00:00
|
|
|
coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args),
|
2023-03-14 21:17:34 +00:00
|
|
|
reviews: count_reviews(repo_full_name, person, args),
|
2023-02-20 00:14:53 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
2023-02-25 00:29:37 +00:00
|
|
|
sig { params(results: Hash).returns(Hash) }
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
def total(results)
|
2023-03-01 23:38:49 +00:00
|
|
|
totals = { author: 0, committer: 0, coauthorships: 0, reviews: 0 }
|
2023-02-25 00:29:37 +00:00
|
|
|
|
|
|
|
results.each_value do |counts|
|
|
|
|
counts.each do |kind, count|
|
|
|
|
totals[kind] += count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-01 23:45:08 +00:00
|
|
|
totals
|
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
it, generate a CSV that's `pbcopy`able elsewhere, for more granular
breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.
Output:
```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.
$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:25:04 +00:00
|
|
|
end
|
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
sig { params(repo_path: Pathname, person: String, trailer: String, args: Homebrew::CLI::Args).returns(Integer) }
|
|
|
|
def git_log_trailers_cmd(repo_path, person, trailer, args)
|
2022-07-28 11:20:04 +01:00
|
|
|
cmd = ["git", "-C", repo_path, "log", "--oneline"]
|
2023-02-11 11:39:31 +00:00
|
|
|
cmd << "--format='%(trailers:key=#{trailer}:)'"
|
2022-07-30 00:36:31 +01:00
|
|
|
cmd << "--before=#{args.to}" if args.to
|
|
|
|
cmd << "--after=#{args.from}" if args.from
|
2022-07-24 22:06:00 +01:00
|
|
|
|
2023-02-20 00:14:53 +00:00
|
|
|
Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(person) }
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|
2023-03-14 21:17:34 +00:00
|
|
|
|
|
|
|
sig { params(repo_full_name: String, person: String, args: Homebrew::CLI::Args).returns(Integer) }
|
|
|
|
def count_reviews(repo_full_name, person, args)
|
|
|
|
GitHub.count_issues("", is: "pr", repo: repo_full_name, reviewed_by: person, review: "approved", args: args)
|
2023-03-15 12:59:21 +00:00
|
|
|
rescue GitHub::API::ValidationFailedError
|
2023-03-15 21:31:41 +00:00
|
|
|
if args.verbose?
|
|
|
|
onoe "Couldn't search GitHub for PRs by #{person}. Their profile might be private. Defaulting to 0."
|
|
|
|
end
|
2023-03-15 12:59:21 +00:00
|
|
|
0 # Users who have made their contributions private are not searchable to determine counts.
|
2023-03-14 21:17:34 +00:00
|
|
|
end
|
2022-07-24 22:06:00 +01:00
|
|
|
end
|