Skip to content

Commit

Permalink
Merge pull request #18812 from Homebrew/bump-skip-pr-checking-when-up…
Browse files Browse the repository at this point in the history
…-to-date

bump: skip PR checking when up to date or livecheck fails
  • Loading branch information
MikeMcQuaid authored Nov 25, 2024
2 parents 56780f3 + 1cbcc44 commit 4a77cd1
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 43 deletions.
7 changes: 7 additions & 0 deletions Library/Homebrew/bump_version_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@ def parse_cask_version(version)
def blank?
@general.blank? && @arm.blank? && @intel.blank?
end

sig { params(other: T.untyped).returns(T::Boolean) }
def ==(other)
return false unless other.is_a?(BumpVersionParser)

(general == other.general) && (arm == other.arm) && (intel == other.intel)
end
end
end
65 changes: 42 additions & 23 deletions Library/Homebrew/dev-cmd/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ def retrieve_pull_requests(formula_or_cask, name, version: nil)
odebug "Error fetching pull requests for #{formula_or_cask} #{name}: #{e}"
nil
end
return if pull_requests.blank?

pull_requests&.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }&.join(", ")
pull_requests.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }.join(", ")
end

sig {
Expand Down Expand Up @@ -365,21 +366,27 @@ def retrieve_versions_by_arch(formula_or_cask:, repositories:, name:)
new_version = BumpVersionParser.new(general: "unable to get versions")
end

# We use the arm version for the pull request version. This is consistent
# with the behavior of bump-cask-pr.
pull_request_version = if multiple_versions && new_version.general != "unable to get versions"
new_version.arm.to_s
else
new_version.general.to_s
end
if !args.no_pull_requests? &&
(new_version.general != "unable to get versions") &&
(new_version != current_version)
# We use the ARM version for the pull request version. This is
# consistent with the behavior of bump-cask-pr.
pull_request_version = if multiple_versions
new_version.arm.to_s
else
new_version.general.to_s
end

duplicate_pull_requests = unless args.no_pull_requests?
retrieve_pull_requests(formula_or_cask, name, version: pull_request_version)
end.presence
duplicate_pull_requests = retrieve_pull_requests(
formula_or_cask,
name,
version: pull_request_version,
)

maybe_duplicate_pull_requests = if !args.no_pull_requests? && duplicate_pull_requests.blank?
retrieve_pull_requests(formula_or_cask, name)
end.presence
maybe_duplicate_pull_requests = if duplicate_pull_requests.nil?
retrieve_pull_requests(formula_or_cask, name)
end
end

VersionBumpInfo.new(
type:,
Expand Down Expand Up @@ -411,9 +418,7 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
repology_latest = version_info.repology_latest

# Check if all versions are equal
versions_equal = [:arm, :intel, :general].all? do |key|
current_version.send(key) == new_version.send(key)
end
versions_equal = (new_version == current_version)

title_name = ambiguous_cask ? "#{name} (cask)" : name
title = if (repology_latest == current_version.general || !repology_latest.is_a?(Version)) && versions_equal
Expand All @@ -439,8 +444,8 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
end

version_label = version_info.version_name
duplicate_pull_requests = version_info.duplicate_pull_requests.presence
maybe_duplicate_pull_requests = version_info.maybe_duplicate_pull_requests.presence
duplicate_pull_requests = version_info.duplicate_pull_requests
maybe_duplicate_pull_requests = version_info.maybe_duplicate_pull_requests

ohai title
puts <<~EOS
Expand All @@ -457,10 +462,24 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
#{outdated_synced_formulae.join(", ")}.
EOS
end
puts <<~EOS unless args.no_pull_requests?
Duplicate pull requests: #{duplicate_pull_requests || "none"}
Maybe duplicate pull requests: #{maybe_duplicate_pull_requests || "none"}
EOS
if !args.no_pull_requests? &&
(new_version.general != "unable to get versions") &&
!versions_equal
if duplicate_pull_requests
duplicate_pull_requests_text = duplicate_pull_requests
elsif maybe_duplicate_pull_requests
duplicate_pull_requests_text = "none"
maybe_duplicate_pull_requests_text = maybe_duplicate_pull_requests
else
duplicate_pull_requests_text = "none"
maybe_duplicate_pull_requests_text = "none"
end

puts "Duplicate pull requests: #{duplicate_pull_requests_text}"
if maybe_duplicate_pull_requests_text
puts "Maybe duplicate pull requests: #{maybe_duplicate_pull_requests_text}"
end
end

return unless args.open_pr?

Expand Down
95 changes: 75 additions & 20 deletions Library/Homebrew/test/bump_version_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,61 @@
it "raises a usage error" do
expect do
described_class.new
end.to raise_error(UsageError, "Invalid usage: `--version` must not be empty.")
end.to raise_error(UsageError,
"Invalid usage: `--version` must not be empty.")
end
end

context "when initializing with valid versions" do
context "when initializing with only an intel version" do
it "raises a UsageError" do
expect do
described_class.new(intel: intel_version)
end.to raise_error(UsageError,
"Invalid usage: `--version-arm` must not be empty.")
end
end

context "when initializing with only an arm version" do
it "raises a UsageError" do
expect do
described_class.new(arm: arm_version)
end.to raise_error(UsageError,
"Invalid usage: `--version-intel` must not be empty.")
end
end

context "when initializing with arm and intel versions" do
let(:new_version_arm_intel) { described_class.new(arm: arm_version, intel: intel_version) }

it "correctly parses arm and intel versions" do
expect(new_version_arm_intel.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
expect(new_version_arm_intel.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end
end

context "when initializing with all versions" do
let(:new_version) { described_class.new(general: general_version, arm: arm_version, intel: intel_version) }
let(:new_version_version) do
described_class.new(
general: Version.new(general_version),
arm: Version.new(arm_version),
intel: Version.new(intel_version),
)
end

it "correctly parses general version" do
expect(new_version.general).to eq(Cask::DSL::Version.new(general_version.to_s))
expect(new_version_version.general).to eq(Cask::DSL::Version.new(general_version.to_s))
end

it "correctly parses arm version" do
expect(new_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
expect(new_version_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
end

it "correctly parses intel version" do
expect(new_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end

context "when only the intel version is provided" do
it "raises a UsageError" do
expect do
described_class.new(intel: intel_version)
end.to raise_error(UsageError,
"Invalid usage: `--version-arm` must not be empty.")
end
end

context "when only the arm version is provided" do
it "raises a UsageError" do
expect do
described_class.new(arm: arm_version)
end.to raise_error(UsageError,
"Invalid usage: `--version-intel` must not be empty.")
end
expect(new_version_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end

context "when the version is latest" do
Expand All @@ -69,4 +89,39 @@
end
end
end

describe "#==" do
let(:new_version) { described_class.new(general: general_version, arm: arm_version, intel: intel_version) }

context "when other object is not a `BumpVersionParser`" do
it "returns false" do
expect(new_version == Version.new("1.2.3")).to be(false)
end
end

context "when comparing objects with equal versions" do
it "returns true" do
same_version = described_class.new(general: general_version, arm: arm_version, intel: intel_version)
expect(new_version == same_version).to be(true)
end
end

context "when comparing objects with different versions" do
it "returns false" do
different_general_version = described_class.new(general: "3.2.1", arm: arm_version, intel: intel_version)
different_arm_version = described_class.new(general: general_version, arm: "4.3.2", intel: intel_version)
different_intel_version = described_class.new(general: general_version, arm: arm_version, intel: "5.4.3")
different_general_arm_versions = described_class.new(general: "3.2.1", arm: "4.3.2", intel: intel_version)
different_arm_intel_versions = described_class.new(general: general_version, arm: "4.3.2", intel: "5.4.3")
different_general_intel_versions = described_class.new(general: "3.2.1", arm: arm_version, intel: "5.4.3")

expect(new_version == different_general_version).to be(false)
expect(new_version == different_arm_version).to be(false)
expect(new_version == different_intel_version).to be(false)
expect(new_version == different_general_arm_versions).to be(false)
expect(new_version == different_arm_intel_versions).to be(false)
expect(new_version == different_general_intel_versions).to be(false)
end
end
end
end

0 comments on commit 4a77cd1

Please sign in to comment.