Skip to content

Commit d35d908

Browse files
committed
feat: add --verification-exit-code to publish-provider-contract command
1 parent 0179e06 commit d35d908

File tree

2 files changed

+63
-41
lines changed

2 files changed

+63
-41
lines changed

lib/pactflow/client/cli/provider_contract_commands.rb

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def self.included(thor)
2020
#method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
2121
method_option :specification, default: "oas", desc: "The contract specification"
2222
method_option :content_type, desc: "The content type. eg. application/yml"
23-
method_option :verification_success, type: :boolean
23+
method_option :verification_success, type: :boolean, desc: "Whether or not the self verification passed successfully."
24+
method_option :verification_exit_code, type: :numeric, desc: "The exit code of the verification process. Can be used instead of --verificaiton-success|--no-verification-success for a simpler build script."
2425
method_option :verification_results, desc: "The path to the file containing the output from the verification process"
2526
method_option :verification_results_content_type, desc: "The content type of the verification output eg. text/plain, application/yaml"
2627
method_option :verification_results_format, desc: "The format of the verification output eg. junit, text"
@@ -34,31 +35,51 @@ def self.included(thor)
3435
def publish_provider_contract(provider_contract_path)
3536
require "pactflow/client/provider_contracts/publish"
3637

37-
params = params = {
38-
provider_name: options.provider.strip,
39-
provider_version_number: options.provider_app_version.strip,
40-
branch_name: options.branch && options.branch.strip,
41-
tags: (options.tag && options.tag.collect(&:strip)) || [],
42-
contract: {
43-
content: File.read(provider_contract_path),
44-
content_type: options.content_type,
45-
specification: options.specification
46-
},
47-
verification_results: {
48-
success: options.verification_success,
49-
content: options.verification_results ? File.read(options.verification_results) : nil,
50-
content_type: options.verification_results_content_type,
51-
format: options.verification_results_format,
52-
verifier: options.verifier,
53-
verifier_version: options.verifier_version
54-
}
55-
}
56-
57-
command_options = { verbose: options.verbose, output: options.output }
58-
result = ::Pactflow::Client::ProviderContracts::Publish.call(params, command_options, pact_broker_client_options)
38+
validate_publish_provider_contract_options(provider_contract_path)
39+
result = ::Pactflow::Client::ProviderContracts::Publish.call(
40+
publish_provider_contract_command_params(provider_contract_path),
41+
command_options,
42+
pact_broker_client_options
43+
)
5944
$stdout.puts result.message
6045
exit(1) unless result.success
6146
end
47+
48+
no_commands do
49+
def command_options
50+
{ verbose: options.verbose, output: options.output }
51+
end
52+
53+
def validate_publish_provider_contract_options(provider_contract_path)
54+
if !options.verification_success.nil? && options.verification_exit_code
55+
raise Thor::Error, "Cannot use both --verification-success|--no-verification-success and --verification-exit-code"
56+
end
57+
end
58+
59+
def publish_provider_contract_command_params(provider_contract_path)
60+
success = !options.verification_success.nil? ? options.verification_success : ( options.verification_exit_code && options.verification_exit_code == 0 )
61+
62+
{
63+
provider_name: options.provider.strip,
64+
provider_version_number: options.provider_app_version.strip,
65+
branch_name: options.branch && options.branch.strip,
66+
tags: (options.tag && options.tag.collect(&:strip)) || [],
67+
contract: {
68+
content: File.read(provider_contract_path),
69+
content_type: options.content_type,
70+
specification: options.specification
71+
},
72+
verification_results: {
73+
success: success,
74+
content: options.verification_results ? File.read(options.verification_results) : nil,
75+
content_type: options.verification_results_content_type,
76+
format: options.verification_results_format,
77+
verifier: options.verifier,
78+
verifier_version: options.verifier_version
79+
}
80+
}
81+
end
82+
end
6283
end
6384
end
6485
end

script/publish-provider-contract.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
export PACT_BROKER_BASE_URL="http://localhost:9292"
1+
export PACT_BROKER_BASE_URL=${PACT_BROKER_BASE_URL:-"http://localhost:9292"}
22
export PACTFLOW_FEATURES=publish-provider-contract
3+
bundle exec bin/pactflow publish-provider-contract \
4+
script/oas.yml \
5+
--provider Foo \
6+
--provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
7+
--branch main \
8+
--tag dev \
9+
--specification oas \
10+
--content-type application/yml \
11+
--verification-exit-code 0 \
12+
--verification-results script/verification-results.txt \
13+
--verification-results-content-type text/plain \
14+
--verification-results-format text \
15+
--verifier my-custom-tool \
16+
--verifier-version "1.0" \
17+
--verbose
18+
19+
320
# bundle exec bin/pactflow publish-provider-contract \
421
# script/oas.yml \
522
# --provider Foo \
623
# --provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
724
# --branch main \
825
# --tag dev \
926
# --specification oas \
10-
# --content-type application/yml \
11-
# --no-verification-success \
12-
# --verification-results script/verification-results.txt \
13-
# --verification-results-content-type text/plain \
14-
# --verification-results-format text \
15-
# --verifier my-custom-tool \
16-
# --verifier-version "1.0" \
17-
# --verbose
18-
27+
# --content-type application/yml
1928

20-
bundle exec bin/pactflow publish-provider-contract \
21-
script/oas.yml \
22-
--provider Foo \
23-
--provider-app-version 1013b5650d61214e19f10558f97fb5a3bb082d44 \
24-
--branch main \
25-
--tag dev \
26-
--specification oas \
27-
--content-type application/yml

0 commit comments

Comments
 (0)