forked from pact-foundation/pact_broker-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add record-release (feature toggled off)
- Loading branch information
Showing
8 changed files
with
466 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
require 'pact_broker/client/base_command' | ||
|
||
module PactBroker | ||
module Client | ||
module Deployments | ||
class RecordRelease < PactBroker::Client::BaseCommand | ||
def initialize(params, options, pact_broker_client_options) | ||
super | ||
@pacticipant_name = params.fetch(:pacticipant_name) | ||
@version_number = params.fetch(:version_number) | ||
@environment_name = params.fetch(:environment_name) | ||
end | ||
|
||
private | ||
|
||
attr_reader :pacticipant_name, :version_number, :environment_name | ||
attr_reader :deployed_version_resource | ||
|
||
def do_call | ||
record_action | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def action | ||
"release" | ||
end | ||
|
||
def action_relation_name | ||
"pb:record-release" | ||
end | ||
|
||
def not_supported_message | ||
"This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later." | ||
end | ||
|
||
def environment_exists? | ||
index_resource | ||
._link!("pb:environments") | ||
.get! | ||
._links("pb:environments") | ||
.find(environment_name) | ||
end | ||
|
||
def record_action | ||
@deployed_version_resource = | ||
get_record_action_relation | ||
.post(record_action_request_body) | ||
.assert_success! | ||
end | ||
|
||
def record_action_links | ||
get_pacticipant_version._links(action_relation_name) or raise PactBroker::Client::Error.new(not_supported_message) | ||
end | ||
|
||
def get_record_action_relation | ||
record_action_links.find(environment_name) or record_action_links.find!(environment_name, environment_relation_not_found_error_message) | ||
end | ||
|
||
def environment_relation_not_found_error_message | ||
if environment_exists? | ||
"Environment '#{environment_name}' is not an available option for recording a deployment of #{pacticipant_name}." | ||
else | ||
"No environment found with name '#{environment_name}'." | ||
end | ||
end | ||
|
||
def get_pacticipant_version | ||
index_resource | ||
._link!("pb:pacticipant-version") | ||
.expand(pacticipant: pacticipant_name, version: version_number) | ||
.get | ||
.assert_success!(404 => "#{pacticipant_name} version #{version_number} not found") | ||
end | ||
|
||
def record_action_request_body | ||
{} | ||
end | ||
|
||
def result_message | ||
if json_output? | ||
deployed_version_resource.response.raw_body | ||
else | ||
green("#{result_text_message} in #{pact_broker_name}.") | ||
end | ||
end | ||
|
||
def result_text_message | ||
"Recorded #{action} of #{pacticipant_name} version #{version_number} to #{environment_name} environment" | ||
end | ||
|
||
def check_if_command_supported | ||
unless index_resource.can?("pb:environments") | ||
raise PactBroker::Client::Error.new(not_supported_message) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export PACT_BROKER_FEATURES=deployments | ||
|
||
bundle exec bin/pact-broker create-or-update-pacticipant --name Foo | ||
bundle exec bin/pact-broker create-version-tag --pacticipant Foo --version 2 --tag main --auto-create-version | ||
bundle exec bin/pact-broker describe-version --pacticipant Foo --version 2 | ||
bundle exec bin/pact-broker create-environment --name test | ||
bundle exec bin/pact-broker can-i-deploy --pacticipant Foo --version 2 --to-environment test | ||
bundle exec bin/pact-broker record-deployment --pacticipant Foo --version 2 --environment test --target foo | ||
bundle exec bin/pact-broker record-undeployment --pacticipant Foo --version 2 --environment test --target foo | ||
bundle exec bin/pact-broker record-release --pacticipant Foo --version 2 --environment test |
Oops, something went wrong.