From f0e37a4794e72d0a469298ff592d69f1304c9022 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 16 Dec 2021 16:21:33 +1100 Subject: [PATCH] fix: pass through includePendingStatus to the 'pacts for verification' API when it is false --- lib/pact/hash_refinements.rb | 17 +++++++++++++++++ .../fetch_pact_uris_for_verification.rb | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 lib/pact/hash_refinements.rb diff --git a/lib/pact/hash_refinements.rb b/lib/pact/hash_refinements.rb new file mode 100644 index 00000000..3e738521 --- /dev/null +++ b/lib/pact/hash_refinements.rb @@ -0,0 +1,17 @@ +module Pact + module HashRefinements + refine Hash do + def compact + h = {} + each do |key, value| + h[key] = value unless value == nil + end + h + end unless Hash.method_defined? :compact + + def compact! + reject! {|_key, value| value == nil} + end unless Hash.method_defined? :compact! + end + end +end diff --git a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb index a726cc7b..631562d3 100644 --- a/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb +++ b/lib/pact/pact_broker/fetch_pact_uris_for_verification.rb @@ -5,10 +5,13 @@ require 'pact/pact_broker/fetch_pacts' require 'pact/pact_broker/notices' require 'pact/pact_broker/pact_selection_description' +require "pact/hash_refinements" module Pact module PactBroker class FetchPactURIsForVerification + using Pact::HashRefinements + include PactSelectionDescription attr_reader :provider, :consumer_version_selectors, :provider_version_branch, :provider_version_tags, :broker_base_url, :http_client_options, :http_client, :options @@ -74,12 +77,12 @@ def pacts_for_verification_entity def query q = {} - q["includePendingStatus"] = true if options[:include_pending_status] + q["includePendingStatus"] = options[:include_pending_status] q["consumerVersionSelectors"] = consumer_version_selectors if consumer_version_selectors.any? q["providerVersionTags"] = provider_version_tags if provider_version_tags.any? - q["providerVersionBranch"] = provider_version_branch if provider_version_branch - q["includeWipPactsSince"] = options[:include_wip_pacts_since] if options[:include_wip_pacts_since] - q + q["providerVersionBranch"] = provider_version_branch + q["includeWipPactsSince"] = options[:include_wip_pacts_since] + q.compact end def extract_notices(pact)