Merge pull request #14813 from issyl0/contributions-approvals
This commit is contained in:
		
						commit
						a13556a1a6
					
				@ -108,7 +108,7 @@ module Homebrew
 | 
			
		||||
  sig { params(totals: Hash).returns(String) }
 | 
			
		||||
  def generate_maintainers_csv(totals)
 | 
			
		||||
    CSV.generate do |csv|
 | 
			
		||||
      csv << %w[user repo commits coauthorships signoffs total]
 | 
			
		||||
      csv << %w[user repo commits coauthorships signoffs reviews total]
 | 
			
		||||
 | 
			
		||||
      totals.sort_by { |_, v| -v.values.sum }.each do |user, total|
 | 
			
		||||
        csv << grand_total_row(user, total)
 | 
			
		||||
@ -119,7 +119,7 @@ module Homebrew
 | 
			
		||||
  sig { params(user: String, results: Hash, grand_total: Hash).returns(String) }
 | 
			
		||||
  def generate_csv(user, results, grand_total)
 | 
			
		||||
    CSV.generate do |csv|
 | 
			
		||||
      csv << %w[user repo commits coauthorships signoffs total]
 | 
			
		||||
      csv << %w[user repo commits coauthorships signoffs reviews total]
 | 
			
		||||
      results.each do |repo, counts|
 | 
			
		||||
        csv << [
 | 
			
		||||
          user,
 | 
			
		||||
@ -127,6 +127,7 @@ module Homebrew
 | 
			
		||||
          counts[:commits],
 | 
			
		||||
          counts[:coauthorships],
 | 
			
		||||
          counts[:signoffs],
 | 
			
		||||
          counts[:reviews],
 | 
			
		||||
          counts.values.sum,
 | 
			
		||||
        ]
 | 
			
		||||
      end
 | 
			
		||||
@ -142,6 +143,7 @@ module Homebrew
 | 
			
		||||
      grand_total[:commits],
 | 
			
		||||
      grand_total[:coauthorships],
 | 
			
		||||
      grand_total[:signoffs],
 | 
			
		||||
      grand_total[:reviews],
 | 
			
		||||
      grand_total.values.sum,
 | 
			
		||||
    ]
 | 
			
		||||
  end
 | 
			
		||||
@ -173,6 +175,7 @@ module Homebrew
 | 
			
		||||
        commits:       GitHub.repo_commit_count_for_user(repo_full_name, person, args),
 | 
			
		||||
        coauthorships: git_log_trailers_cmd(T.must(repo_path), person, "Co-authored-by", args),
 | 
			
		||||
        signoffs:      git_log_trailers_cmd(T.must(repo_path), person, "Signed-off-by", args),
 | 
			
		||||
        reviews:       GitHub.count_issues("", is: "pr", repo: repo_full_name, reviewed_by: person),
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -181,16 +184,19 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
  sig { params(results: Hash).returns(Hash) }
 | 
			
		||||
  def total(results)
 | 
			
		||||
    totals = { commits: 0, coauthorships: 0, signoffs: 0 }
 | 
			
		||||
    totals = { commits: 0, coauthorships: 0, signoffs: 0, reviews: 0 }
 | 
			
		||||
 | 
			
		||||
    # {"brew"=>{:commits=>9,:coauthorships=>6,:signoffs=>3},"core"=>{:commits=>15,:coauthorships=>10,:signoffs=>5}}
 | 
			
		||||
    # {
 | 
			
		||||
    #   "brew"=>{:commits=>9,:coauthorships=>6,:signoffs=>3,:reviews=>1},
 | 
			
		||||
    #   "core"=>{:commits=>15,:coauthorships=>10,:signoffs=>5,:reviews=>2}
 | 
			
		||||
    # }
 | 
			
		||||
    results.each_value do |counts|
 | 
			
		||||
      counts.each do |kind, count|
 | 
			
		||||
        totals[kind] += count
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    totals # {:commits=>24,:coauthorships=>16,signoffs=>8}
 | 
			
		||||
    totals # {:commits=>24,:coauthorships=>16,:signoffs=>8,:reviews=>3}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  sig { params(repo_path: Pathname, person: String, trailer: String, args: Homebrew::CLI::Args).returns(Integer) }
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,7 @@ describe Homebrew::Search do
 | 
			
		||||
        ],
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      allow(GitHub::API).to receive(:open_rest).and_yield(json_response)
 | 
			
		||||
      allow(GitHub::API).to receive(:open_rest).and_return(json_response)
 | 
			
		||||
 | 
			
		||||
      expect(described_class.search_taps("some-formula"))
 | 
			
		||||
        .to match(formulae: ["homebrew/foo/some-formula"], casks: ["homebrew/bar/some-cask"])
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,11 @@ module GitHub
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def search_issues(query, **qualifiers)
 | 
			
		||||
    search("issues", query, **qualifiers)
 | 
			
		||||
    search_results_items("issues", query, **qualifiers)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def count_issues(query, **qualifiers)
 | 
			
		||||
    search_results_count("issues", query, **qualifiers)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def create_gist(files, description, private:)
 | 
			
		||||
@ -57,7 +61,14 @@ module GitHub
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def search_code(repo: nil, user: "Homebrew", path: ["Formula", "Casks", "."], filename: nil, extension: "rb")
 | 
			
		||||
    matches = search("code", user: user, path: path, filename: filename, extension: extension, repo: repo)
 | 
			
		||||
    matches = search_results_items(
 | 
			
		||||
      "code",
 | 
			
		||||
      user:      user,
 | 
			
		||||
      path:      path,
 | 
			
		||||
      filename:  filename,
 | 
			
		||||
      extension: extension,
 | 
			
		||||
      repo:      repo,
 | 
			
		||||
    )
 | 
			
		||||
    return matches if matches.blank?
 | 
			
		||||
 | 
			
		||||
    matches.map do |match|
 | 
			
		||||
@ -163,7 +174,7 @@ module GitHub
 | 
			
		||||
    params = main_params
 | 
			
		||||
 | 
			
		||||
    params += qualifiers.flat_map do |key, value|
 | 
			
		||||
      Array(value).map { |v| "#{key}:#{v}" }
 | 
			
		||||
      Array(value).map { |v| "#{key.to_s.tr("_", "-")}:#{v}" }
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    "q=#{URI.encode_www_form_component(params.join(" "))}&per_page=100"
 | 
			
		||||
@ -176,7 +187,17 @@ module GitHub
 | 
			
		||||
  def search(entity, *queries, **qualifiers)
 | 
			
		||||
    uri = url_to "search", entity
 | 
			
		||||
    uri.query = search_query_string(*queries, **qualifiers)
 | 
			
		||||
    API.open_rest(uri) { |json| json.fetch("items", []) }
 | 
			
		||||
    API.open_rest(uri)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def search_results_items(entity, *queries, **qualifiers)
 | 
			
		||||
    json = search(entity, *queries, **qualifiers)
 | 
			
		||||
    json.fetch("items", [])
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def search_results_count(entity, *queries, **qualifiers)
 | 
			
		||||
    json = search(entity, *queries, **qualifiers)
 | 
			
		||||
    json.fetch("total_count", 0)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def approved_reviews(user, repo, pr, commit: nil)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user