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 update-environment command
- Loading branch information
Showing
6 changed files
with
91 additions
and
14 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
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,48 @@ | ||
require 'pact_broker/client/environments/create_environment' | ||
require 'pact_broker/client/backports' | ||
|
||
module PactBroker | ||
module Client | ||
module Environments | ||
class UpdateEnvironment < PactBroker::Client::Environments::CreateEnvironment | ||
def call | ||
check_if_command_supported | ||
update_environment | ||
rescue PactBroker::Client::Error => e | ||
PactBroker::Client::CommandResult.new(false, ::Term::ANSIColor.red(e.message)) | ||
end | ||
|
||
private | ||
|
||
def update_environment | ||
index_resource | ||
._link!("pb:environment") | ||
.expand(uuid: params[:uuid]) | ||
.put!(request_body) | ||
PactBroker::Client::CommandResult.new(true, result_message) | ||
end | ||
|
||
def request_body | ||
@request_body ||= begin | ||
incoming_params = super | ||
existing_environment_params.merge(incoming_params) | ||
end | ||
end | ||
|
||
def existing_environment_params | ||
@existing_environment_params ||= index_resource | ||
._link!("pb:environment") | ||
.expand(uuid: params[:uuid]) | ||
.get! | ||
.response | ||
.body | ||
.except("_links", "createdAt", "updatedAt") | ||
end | ||
|
||
def result_message | ||
::Term::ANSIColor.green("Updated environment #{request_body["name"]} in #{pact_broker_name}") | ||
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