Skip to content

Commit

Permalink
feat: add branch-pact-versions & latest-branch-pact-version
Browse files Browse the repository at this point in the history
# Branch pact versions

Allowed methods: `GET`

Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}`

Lists all the pact versions with the specified consumer, provider and consumer version branch.

# Latest Branch pact versions

Allowed methods: `GET`

Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}/latest`

Returns the latest pact version with the specified consumer, provider and consumer version branch.
  • Loading branch information
YOU54F committed Oct 4, 2024
1 parent 87669c3 commit c10f858
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/pact_broker/api/resources/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def links
title: "All versions of a pact for a given consumer, provider and consumer version tag",
templated: false
},
"pb:latest-branch-pact-version" =>
{
href: base_url + "/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}/latest",
title: "Latest version of a pact for a given consumer, provider and consumer version branch",
templated: false
},
"pb:branch-pact-versions" =>
{
href: base_url + "/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}",
title: "All versions of a pact for a given consumer, provider and consumer version branch",
templated: false
},
"pb:pacticipants" =>
{
href: base_url + "/pacticipants",
Expand Down
12 changes: 10 additions & 2 deletions lib/pact_broker/api/resources/pact_versions_for_branch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "pact_broker/api/resources/base_resource"
require "pact_broker/configuration"
require "pact_broker/api/decorators/tagged_pact_versions_decorator"
require "pact_broker/api/resources/pact_resource_methods"
require "pact_broker/api/decorators/pact_versions_decorator"

module PactBroker
module Api
Expand All @@ -14,13 +14,21 @@ def content_types_provided
end

def allowed_methods
["DELETE", "OPTIONS"]
["GET", "DELETE", "OPTIONS"]
end

def resource_exists?
consumer && provider
end

def to_json
decorator_class(:pact_versions_decorator).new(pacts).to_json(**decorator_options(identifier_from_path))
end

def pacts
@pacts ||= pact_service.find_pact_versions_for_provider_and_consumer provider_name, consumer_name, branch_name: identifier_from_path[:branch_name]
end

def delete_resource
pact_service.delete_all_pact_publications_between consumer_name, and: provider_name, branch_name: identifier_from_path[:branch_name]
set_post_deletion_response
Expand Down
7 changes: 7 additions & 0 deletions lib/pact_broker/doc/views/index/branch-pact-versions.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Branch pact versions

Allowed methods: `GET`

Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}`

Lists all the pact versions with the specified consumer, provider and consumer version branch.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Latest Branch pact versions

Allowed methods: `GET`

Path: `/pacts/provider/{provider}/consumer/{consumer}/branch/{branch}/latest`

Returns the latest pact version with the specified consumer, provider and consumer version branch.
13 changes: 13 additions & 0 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def find_pact_versions_for_provider provider_name, tag = nil
query.all.collect(&:to_domain).sort
end

def find_pact_versions_for_provider_and_consumer provider_name, consumer_name, branch_name = nil
query = scope_for(PactPublication)
.eager_for_domain_with_content
.select_all_qualified
.for_consumer_name(consumer_name)
.for_provider_name(provider_name)
.remove_overridden_revisions
if branch_name
query = query.old_latest_for_consumer_branch(branch_name)
end
query.latest_by_consumer_version_order.all.collect(&:to_domain_with_content)
end

# Returns latest pact version for the consumer_version_number
def find_by_consumer_version consumer_name, consumer_version_number
scope_for(PactPublication)
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/pacts/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def find_pact_versions_for_provider provider_name, options = {}
pact_repository.find_pact_versions_for_provider provider_name, options[:tag]
end

def find_pact_versions_for_provider_and_consumer provider_name, consumer_name, options = {}
pact_repository.find_pact_versions_for_provider_and_consumer provider_name, consumer_name, options[:branch_name]
end

def find_previous_distinct_pact_version params
pact = find_pact params
return nil if pact.nil?
Expand Down

0 comments on commit c10f858

Please sign in to comment.