Class: Homebrew::DevCmd::Contributions

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/contributions.rb

Constant Summary collapse

PRIMARY_REPOS =
%w[brew core cask].freeze
SUPPORTED_REPOS =
[
  PRIMARY_REPOS,
  OFFICIAL_CMD_TAPS.keys.map { |t| t.delete_prefix("homebrew/") },
  OFFICIAL_CASK_TAPS.reject { |t| t == "cask" },
].flatten.freeze
MAX_REPO_COMMITS =
1000

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'dev-cmd/contributions.rb', line 46

def run
  results = {}
  grand_totals = {}

  repos = if args.repositories.blank? || T.must(args.repositories).include?("primary")
    PRIMARY_REPOS
  elsif T.must(args.repositories).include?("all")
    SUPPORTED_REPOS
  else
    args.repositories
  end

  from = args.from.presence || Date.today.prev_year.iso8601

  contribution_types = [:author, :committer, :coauthorship, :review]

  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
    # 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, from:)
    grand_totals[username] = total(results[username])

    contributions = contribution_types.filter_map do |type|
      type_count = grand_totals[username][type]
      next if type_count.to_i.zero?

      "#{Utils.pluralize("time", type_count, include_count: true)} (#{type})"
    end
    contributions <<
      "#{Utils.pluralize("time", grand_totals[username].values.sum, include_count: true)} (total)"

    puts [
      "#{username} contributed",
      *contributions.to_sentence,
      "#{time_period(from:, to: args.to)}.",
    ].join(" ")
  end

  return unless args.csv?

  puts
  puts generate_csv(grand_totals)
end