Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add branch-pact-versions & latest-branch-pact-version #727

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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