Skip to content
Snippets Groups Projects
Unverified Commit 62210409 authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #8316 from SeekingMeaning/github/duplicate-prs

utils/github: add check_for_duplicate_pull_requests
parents 593b60fa 671179d4
No related branches found
No related tags found
No related merge requests found
......@@ -491,20 +491,8 @@ module Homebrew
end
end
def fetch_pull_requests(query, tap_full_name, state: nil)
GitHub.issues_for_formula(query, tap_full_name: tap_full_name, state: state).select do |pr|
pr["html_url"].include?("/pull/") &&
/(^|\s)#{Regexp.quote(query)}(:|\s|$)/i =~ pr["title"]
end
rescue GitHub::RateLimitExceededError => e
opoo e.message
[]
end
def check_open_pull_requests(formula, tap_full_name, args:)
# check for open requests
pull_requests = fetch_pull_requests(formula.name, tap_full_name, state: "open")
check_for_duplicate_pull_requests(pull_requests, args: args)
GitHub.check_for_duplicate_pull_requests(formula.name, tap_full_name, state: "open", args: args)
end
def check_closed_pull_requests(formula, tap_full_name, version: nil, url: nil, tag: nil, args:)
......@@ -514,28 +502,7 @@ module Homebrew
version = Version.detect(url, specs)
end
# if we haven't already found open requests, try for an exact match across closed requests
pull_requests = fetch_pull_requests("#{formula.name} #{version}", tap_full_name, state: "closed")
check_for_duplicate_pull_requests(pull_requests, args: args)
end
def check_for_duplicate_pull_requests(pull_requests, args:)
return if pull_requests.blank?
duplicates_message = <<~EOS
These pull requests may be duplicates:
#{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")}
EOS
error_message = "Duplicate PRs should not be opened. Use --force to override this error."
if args.force? && !args.quiet?
opoo duplicates_message
elsif !args.force? && args.quiet?
odie error_message
elsif !args.force?
odie <<~EOS
#{duplicates_message.chomp}
#{error_message}
EOS
end
GitHub.check_for_duplicate_pull_requests("#{formula.name} #{version}", tap_full_name, state: "closed", args: args)
end
def alias_update_pair(formula, new_formula_version)
......
......@@ -572,4 +572,35 @@ module GitHub
[GitHub::AuthenticationFailedError, GitHub::HTTPNotFoundError,
GitHub::RateLimitExceededError, GitHub::Error, JSON::ParserError].freeze
end
def fetch_pull_requests(query, tap_full_name, state: nil)
GitHub.issues_for_formula(query, tap_full_name: tap_full_name, state: state).select do |pr|
pr["html_url"].include?("/pull/") &&
/(^|\s)#{Regexp.quote(query)}(:|\s|$)/i =~ pr["title"]
end
rescue GitHub::RateLimitExceededError => e
opoo e.message
[]
end
def check_for_duplicate_pull_requests(query, tap_full_name, state:, args:)
pull_requests = fetch_pull_requests(query, tap_full_name, state: state)
return if pull_requests.blank?
duplicates_message = <<~EOS
These pull requests may be duplicates:
#{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")}
EOS
error_message = "Duplicate PRs should not be opened. Use --force to override this error."
if args.force? && !args.quiet?
opoo duplicates_message
elsif !args.force? && args.quiet?
odie error_message
elsif !args.force?
odie <<~EOS
#{duplicates_message.chomp}
#{error_message}
EOS
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment