pact_broker-client 1.73.0 → 1.74.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release_gem.yml +1 -1
- data/.github/workflows/trigger_pact_docs_update.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/README.md +7 -7
- data/example/scripts/publish-pact-rake.sh +10 -0
- data/example/scripts/publish-pact.sh +25 -1
- data/example/scripts/publish-provider-contract.sh +2 -1
- data/lib/pact_broker/client/cli/pact_commands.rb +34 -13
- data/lib/pact_broker/client/git.rb +20 -3
- data/lib/pact_broker/client/merge_pacts.rb +5 -2
- data/lib/pact_broker/client/publish_pacts_the_old_way.rb +1 -1
- data/lib/pact_broker/client/tasks/publication_task.rb +40 -23
- data/lib/pact_broker/client/version.rb +1 -1
- data/spec/fixtures/MyConsumer-MyProvider (1).json +37 -0
- data/spec/fixtures/MyConsumer-MyProvider.json +37 -0
- data/spec/integration/can_i_deploy_spec.rb +0 -9
- data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +38 -21
- data/spec/lib/pact_broker/client/merge_pacts_spec.rb +26 -0
- data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +1 -3
- data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +54 -31
- data/tasks/pact.rake +79 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84c25ce85cb110411ce145b803e155a0cb8c30a356bb3a6dc8239ab14fbc97c4
|
4
|
+
data.tar.gz: 57a8dcaf85657dc9f99c233abf1cbd1fa0672e0c942ba8d0f009907afda87309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 732c56c1c831f3f154e9be33ef949208057db7705a7bca291d1a356923729acda5f762ff2e57ab51409afa71e425eec7bc775964816de74d215229a66583bedf
|
7
|
+
data.tar.gz: 97f2acafe53b570a5945d1e3c8750cf6f35f5a122ba58e5b8646ba2dc2b1702ad44489ab21ba53fa19220aca569bd8495c5ce6f694b9ec1784caf8a247cd6fed
|
@@ -61,7 +61,7 @@ jobs:
|
|
61
61
|
runs-on: ubuntu-latest
|
62
62
|
steps:
|
63
63
|
- name: Notify ${{ matrix.repository }} of gem release
|
64
|
-
uses: peter-evans/repository-dispatch@
|
64
|
+
uses: peter-evans/repository-dispatch@v2
|
65
65
|
with:
|
66
66
|
token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }}
|
67
67
|
repository: ${{ matrix.repository }}
|
@@ -16,7 +16,7 @@ jobs:
|
|
16
16
|
runs-on: ubuntu-latest
|
17
17
|
steps:
|
18
18
|
- name: Trigger docs.pact.io update workflow
|
19
|
-
uses: peter-evans/repository-dispatch@
|
19
|
+
uses: peter-evans/repository-dispatch@v2
|
20
20
|
with:
|
21
21
|
token: ${{ secrets.GHTOKENFORTRIGGERINGPACTDOCSUPDATE }}
|
22
22
|
repository: pact-foundation/docs.pact.io
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
<a name="v1.74.0"></a>
|
2
|
+
### v1.74.0 (2023-10-14)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* auto detect commit sha, add shorthand -r flag (#119) ([1dac9f8](/../../commit/1dac9f8))
|
7
|
+
|
8
|
+
#### Bug Fixes
|
9
|
+
|
10
|
+
* support merging v3 pacts ([d1e01d0](/../../commit/d1e01d0))
|
11
|
+
|
1
12
|
<a name="v1.73.0"></a>
|
2
13
|
### v1.73.0 (2023-10-13)
|
3
14
|
|
data/README.md
CHANGED
@@ -59,18 +59,18 @@ In the next major version, an error will be raised by default.
|
|
59
59
|
|
60
60
|
```
|
61
61
|
Usage:
|
62
|
-
pact-broker publish PACT_DIRS_OR_FILES ... -
|
62
|
+
pact-broker publish PACT_DIRS_OR_FILES ... -b, --broker-base-url=BROKER_BASE_URL
|
63
63
|
|
64
64
|
Options:
|
65
|
-
-a, --consumer-app-version=CONSUMER_APP_VERSION
|
65
|
+
-a, [--consumer-app-version=CONSUMER_APP_VERSION]
|
66
66
|
# The consumer application version
|
67
67
|
-h, [--branch=BRANCH]
|
68
68
|
# Repository branch of the consumer version
|
69
|
-
|
70
|
-
# Automatically detect the repository branch
|
71
|
-
environment variables or git CLI. Supports
|
72
|
-
CI, Travis CI, GitHub Actions, Jenkins,
|
73
|
-
GitLab, CodeShip, Bitbucket and Azure DevOps.
|
69
|
+
-r, [--auto-detect-version-properties], [--no-auto-detect-version-properties]
|
70
|
+
# Automatically detect the repository commit, branch and build
|
71
|
+
URL from known CI environment variables or git CLI. Supports
|
72
|
+
Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins,
|
73
|
+
Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps.
|
74
74
|
-t, [--tag=TAG]
|
75
75
|
# Tag name for consumer version. Can be specified multiple
|
76
76
|
times.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# assumes you've set PACT_BROKER_BASE_URL, PACT_BROKER_TOKEN already
|
3
|
+
|
4
|
+
bundle exec rake pact:publish:pactflow_auto_on_nil_commit_nil_branch
|
5
|
+
bundle exec rake pact:publish:pactflow_auto_on_user_commit_user_branch
|
6
|
+
bundle exec rake pact:publish:pactflow_auto_on_user_commit_nil_branch
|
7
|
+
bundle exec rake pact:publish:pactflow_auto_on_nil_commit_user_branch
|
8
|
+
bundle exec rake pact:publish:pactflow_auto_off_user_commit_nil_branch
|
9
|
+
bundle exec rake pact:publish:pactflow_auto_off_nil_commit_nil_branch
|
10
|
+
bundle exec rake pact:publish:pactflow_auto_off_empty_string_commit_nil_branch
|
@@ -1,3 +1,27 @@
|
|
1
1
|
# assumes you've set PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD already
|
2
|
+
# Must be executed from root directory of project.
|
2
3
|
|
3
|
-
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json
|
4
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json
|
5
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --auto-detect-version-properties
|
6
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --auto-detect-version-properties --tag-with-git-branch
|
7
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --branch branch-user-override
|
8
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --branch branch-user-override --auto-detect-version-properties
|
9
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --branch branch-user-override --auto-detect-version-properties --tag-with-git-branch
|
10
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override
|
11
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override --branch branch-user-override
|
12
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override --auto-detect-version-properties
|
13
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override --auto-detect-version-properties --tag-with-git-branch
|
14
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override --branch branch-user-override --auto-detect-version-properties
|
15
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json --consumer-app-version commit-user-override --branch branch-user-override --auto-detect-version-properties --tag-with-git-branch
|
16
|
+
|
17
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -r
|
18
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -r -g
|
19
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -h branch-user-override
|
20
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -h branch-user-override -r
|
21
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -h branch-user-override -r -g
|
22
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override
|
23
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override -r
|
24
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override -r -g
|
25
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override -h branch-user-override
|
26
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override -h branch-user-override -r
|
27
|
+
bundle exec bin/pact-broker publish $(dirname "$0")/pact.json -a commit-user-override -h branch-user-override -r -g
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# Assumes you've set PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD already
|
2
|
+
# Must be executed from root directory of project.
|
2
3
|
|
3
4
|
bundle exec bin/pactflow publish-provider-contract $(dirname "$0")/oas.yml \
|
4
5
|
--provider pactflow-cli-test-provider \
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "pact_broker/client/hash_refinements"
|
2
|
+
require 'pact_broker/client/string_refinements'
|
2
3
|
|
3
4
|
module PactBroker
|
4
5
|
module Client
|
@@ -8,13 +9,14 @@ module PactBroker
|
|
8
9
|
|
9
10
|
module PactCommands
|
10
11
|
using PactBroker::Client::HashRefinements
|
12
|
+
using PactBroker::Client::StringRefinements
|
11
13
|
|
12
14
|
def self.included(thor)
|
13
15
|
thor.class_eval do
|
14
16
|
desc 'publish PACT_DIRS_OR_FILES ...', "Publish pacts to a Pact Broker."
|
15
|
-
method_option :consumer_app_version,
|
17
|
+
method_option :consumer_app_version, aliases: "-a", desc: "The consumer application version"
|
16
18
|
method_option :branch, aliases: "-h", desc: "Repository branch of the consumer version"
|
17
|
-
method_option :auto_detect_version_properties, type: :boolean, default: false, desc: "Automatically detect the repository branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
|
19
|
+
method_option :auto_detect_version_properties, aliases: "-r", type: :boolean, default: false, desc: "Automatically detect the repository commit, branch and build URL from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps."
|
18
20
|
method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
|
19
21
|
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. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps. Default: false"
|
20
22
|
method_option :build_url, desc: "The build URL that created the pact"
|
@@ -23,8 +25,10 @@ module PactBroker
|
|
23
25
|
shared_authentication_options
|
24
26
|
|
25
27
|
def publish(*pact_files)
|
26
|
-
require
|
28
|
+
require "pact_broker/client/error"
|
29
|
+
require "pact_broker/client/git"
|
27
30
|
validate_credentials
|
31
|
+
validate_consumer_version
|
28
32
|
validate_pact_files(pact_files)
|
29
33
|
result = publish_pacts(pact_files)
|
30
34
|
$stdout.puts result.message
|
@@ -50,17 +54,21 @@ module PactBroker
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
def validate_consumer_version
|
58
|
+
if consumer_app_version.blank?
|
59
|
+
raise ::Thor::RequiredArgumentMissingError, "No value provided for required option --consumer-app-version"
|
60
|
+
end
|
61
|
+
end
|
53
62
|
|
54
63
|
def publish_pacts pact_files
|
55
64
|
require 'pact_broker/client/publish_pacts'
|
56
65
|
|
57
66
|
write_options = options[:merge] ? { write: :merge } : {}
|
58
67
|
consumer_version_params = {
|
59
|
-
number:
|
68
|
+
number: consumer_app_version,
|
60
69
|
branch: branch,
|
61
70
|
tags: tags,
|
62
|
-
build_url:
|
63
|
-
version_required: (!!options.branch || !!options.build_url || explict_auto_detect_version_properties)
|
71
|
+
build_url: build_url
|
64
72
|
}.compact
|
65
73
|
|
66
74
|
PactBroker::Client::PublishPacts.call(
|
@@ -99,25 +107,38 @@ module PactBroker
|
|
99
107
|
end
|
100
108
|
|
101
109
|
def tags
|
102
|
-
require 'pact_broker/client/git'
|
103
|
-
|
104
110
|
t = [*options.tag]
|
105
111
|
t << PactBroker::Client::Git.branch(raise_error: true) if options.tag_with_git_branch
|
106
112
|
t.compact.uniq
|
107
113
|
end
|
108
114
|
|
109
115
|
def branch
|
110
|
-
require 'pact_broker/client/git'
|
111
|
-
|
112
116
|
if options.branch.nil? && options.auto_detect_version_properties
|
113
|
-
PactBroker::Client::Git.branch(raise_error:
|
117
|
+
PactBroker::Client::Git.branch(raise_error: true)
|
114
118
|
else
|
115
119
|
options.branch
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
119
|
-
def
|
120
|
-
|
123
|
+
def consumer_app_version
|
124
|
+
if defined?(@consumer_app_version)
|
125
|
+
@consumer_app_version
|
126
|
+
else
|
127
|
+
@consumer_app_version = if options.consumer_app_version.blank? && options.auto_detect_version_properties
|
128
|
+
PactBroker::Client::Git.commit(raise_error: true)
|
129
|
+
else
|
130
|
+
options.consumer_app_version
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
def build_url
|
137
|
+
if options.build_url.blank? && options.auto_detect_version_properties
|
138
|
+
PactBroker::Client::Git.build_url
|
139
|
+
else
|
140
|
+
options.build_url
|
141
|
+
end
|
121
142
|
end
|
122
143
|
end
|
123
144
|
end
|
@@ -2,7 +2,6 @@ require 'pact_broker/client/error'
|
|
2
2
|
require 'pact_broker/client/hash_refinements'
|
3
3
|
|
4
4
|
=begin
|
5
|
-
|
6
5
|
BUILDKITE_BRANCH BUILDKITE_COMMIT https://buildkite.com/docs/pipelines/environment-variables
|
7
6
|
CIRCLE_BRANCH CIRCLE_SHA1 https://circleci.com/docs/2.0/env-vars/
|
8
7
|
TRAVIS_COMMIT TRAVIS_BRANCH - TRAVIS_PULL_REQUEST_BRANCH TRAVIS_PULL_REQUEST_SHA https://docs.travis-ci.com/user/environment-variables/
|
@@ -26,18 +25,21 @@ module PactBroker
|
|
26
25
|
using PactBroker::Client::HashRefinements
|
27
26
|
|
28
27
|
COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
|
28
|
+
COMMIT_COMMAND = 'git rev-parse HEAD'.freeze
|
29
29
|
BRANCH_ENV_VAR_NAMES = %w{GITHUB_HEAD_REF GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH BUILD_SOURCEBRANCHNAME CIRRUS_BRANCH}.freeze
|
30
30
|
COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT BUILD_SOURCEVERSION CIRRUS_CHANGE_IN_REPO}
|
31
31
|
BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
|
32
32
|
|
33
|
-
def self.commit
|
34
|
-
find_commit_from_env_vars
|
33
|
+
def self.commit(options)
|
34
|
+
find_commit_from_env_vars || commit_from_git_command(options[:raise_error])
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.branch(options)
|
38
38
|
find_branch_from_known_env_vars || find_branch_from_env_var_ending_with_branch || branch_from_git_command(options[:raise_error])
|
39
39
|
end
|
40
40
|
|
41
|
+
# This does not belong in the Git module.
|
42
|
+
# TODO move it.
|
41
43
|
def self.build_url
|
42
44
|
github_build_url || BUILD_URL_ENV_VAR_NAMES.collect{ | name | value_from_env_var(name) }.compact.first
|
43
45
|
end
|
@@ -79,6 +81,10 @@ module PactBroker
|
|
79
81
|
branch_names.size == 1 ? branch_names[0] : nil
|
80
82
|
end
|
81
83
|
|
84
|
+
def self.commit_from_git_command(raise_error)
|
85
|
+
execute_git_commit_command(raise_error)
|
86
|
+
end
|
87
|
+
|
82
88
|
def self.validate_branch_names(branch_names)
|
83
89
|
if branch_names.size == 0
|
84
90
|
raise PactBroker::Client::Error, "Command `#{COMMAND}` didn't return anything that could be identified as the current branch."
|
@@ -93,6 +99,17 @@ module PactBroker
|
|
93
99
|
`#{COMMAND}`
|
94
100
|
end
|
95
101
|
|
102
|
+
def self.execute_git_commit_command(raise_error)
|
103
|
+
`#{COMMIT_COMMAND}`
|
104
|
+
rescue StandardError => e
|
105
|
+
if raise_error
|
106
|
+
raise PactBroker::Client::Error,
|
107
|
+
"Could not determine current git commit using command `#{COMMIT_COMMAND}`. #{e.class} #{e.message}"
|
108
|
+
else
|
109
|
+
return nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
96
113
|
def self.execute_and_parse_command(raise_error)
|
97
114
|
execute_git_command
|
98
115
|
.split("\n")
|
@@ -53,14 +53,17 @@ module PactBroker
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def almost_duplicate_message(original, new_interaction)
|
56
|
-
"Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{new_interaction[:providerState].inspect}) but a different request or response. " +
|
56
|
+
"Two interactions have been found with same description (#{new_interaction[:description].inspect}) and provider state (#{(new_interaction[:providerState] || new_interaction[:providerStates]).inspect}) but a different request or response. " +
|
57
57
|
"Please use a different description or provider state, or hard-code any random data.\n\n" +
|
58
58
|
original.to_json + "\n\n" + new_interaction.to_json
|
59
59
|
end
|
60
60
|
|
61
61
|
def same_description_and_state? original, additional
|
62
62
|
original[:description] == additional[:description] &&
|
63
|
-
|
63
|
+
(
|
64
|
+
(original[:providerState] && original[:providerState] == additional[:providerState]) ||
|
65
|
+
(original[:providerStates] && original[:providerStates] == additional[:providerStates])
|
66
|
+
)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
@@ -42,7 +42,7 @@ module PactBroker
|
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options
|
45
|
+
attr_reader :pact_broker_base_url, :pact_file_paths, :consumer_version_number, :branch, :tags, :build_url, :pact_broker_client_options
|
46
46
|
|
47
47
|
def pact_broker_client
|
48
48
|
@pact_broker_client ||= PactBroker::Client::PactBrokerClient.new(base_url: pact_broker_base_url, client_options: pact_broker_client_options)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rake/tasklib'
|
2
2
|
require 'pact_broker/client/git'
|
3
3
|
require 'pact_broker/client/hash_refinements'
|
4
|
+
require 'pact_broker/client/string_refinements'
|
5
|
+
require "pact_broker/client/error"
|
4
6
|
|
5
7
|
=begin
|
6
8
|
require pact_broker/client/tasks
|
@@ -19,57 +21,52 @@ module PactBroker
|
|
19
21
|
module Client
|
20
22
|
class PublicationTask < ::Rake::TaskLib
|
21
23
|
using PactBroker::Client::HashRefinements
|
24
|
+
using PactBroker::Client::StringRefinements
|
22
25
|
|
23
|
-
attr_accessor :pattern, :pact_broker_base_url, :
|
24
|
-
attr_reader :auto_detect_version_properties, :
|
26
|
+
attr_accessor :pattern, :pact_broker_base_url, :tag, :build_url, :write_method, :tag_with_git_branch, :pact_broker_basic_auth, :pact_broker_token
|
27
|
+
attr_reader :auto_detect_version_properties, :build_url
|
28
|
+
attr_writer :consumer_version, :branch
|
25
29
|
alias_method :tags=, :tag=
|
26
30
|
alias_method :tags, :tag
|
27
31
|
|
28
32
|
def initialize name = nil, &block
|
29
33
|
@name = name
|
30
34
|
@auto_detect_version_properties = nil
|
31
|
-
@version_required = false
|
32
35
|
@pattern = 'spec/pacts/*.json'
|
33
36
|
@pact_broker_base_url = 'http://pact-broker'
|
34
37
|
rake_task &block
|
35
38
|
end
|
36
39
|
|
37
40
|
def auto_detect_version_properties= auto_detect_version_properties
|
38
|
-
@version_required = version_required || auto_detect_version_properties
|
39
41
|
@auto_detect_version_properties = auto_detect_version_properties
|
40
42
|
end
|
41
|
-
|
42
|
-
def branch= branch
|
43
|
-
@version_required = version_required || !!branch
|
44
|
-
@branch = branch
|
45
|
-
end
|
46
|
-
|
47
|
-
def build_url= build_url
|
48
|
-
@version_required = version_required || !!build_url
|
49
|
-
@build_url = build_url
|
50
|
-
end
|
51
|
-
|
43
|
+
|
52
44
|
private
|
53
45
|
|
54
|
-
attr_reader :version_required
|
55
|
-
|
56
46
|
def rake_task &block
|
57
47
|
namespace :pact do
|
58
48
|
desc "Publish pacts to pact broker"
|
59
49
|
task task_name do
|
60
50
|
block.call(self)
|
51
|
+
validate!
|
61
52
|
require 'pact_broker/client/publish_pacts'
|
62
53
|
pact_broker_client_options = { write: write_method, token: pact_broker_token }
|
63
54
|
pact_broker_client_options[:basic_auth] = pact_broker_basic_auth if pact_broker_basic_auth && pact_broker_basic_auth.any?
|
64
55
|
pact_broker_client_options.compact!
|
65
|
-
consumer_version_params = { number: consumer_version, branch:
|
56
|
+
consumer_version_params = { number: consumer_version, branch: branch, build_url: build_url, tags: all_tags }.compact
|
66
57
|
result = PactBroker::Client::PublishPacts.new(pact_broker_base_url, FileList[pattern], consumer_version_params, {}, pact_broker_client_options).call
|
67
58
|
$stdout.puts result.message
|
68
|
-
raise "One or more pacts failed to be published" unless result.success
|
59
|
+
raise PactBroker::Client::Error.new("One or more pacts failed to be published") unless result.success
|
69
60
|
end
|
70
61
|
end
|
71
62
|
end
|
72
63
|
|
64
|
+
def validate!
|
65
|
+
if consumer_version.blank?
|
66
|
+
raise PactBroker::Client::Error.new("A consumer version must be provided")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
73
70
|
def task_name
|
74
71
|
@name ? "publish:#{@name}" : "publish"
|
75
72
|
end
|
@@ -80,11 +77,31 @@ module PactBroker
|
|
80
77
|
t.compact.uniq
|
81
78
|
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
# Attempt to detect the branch automatically, but don't raise an error if the branch can't be found
|
81
|
+
# unless the user has explicitly enabled auto_detect_version_properties.
|
82
|
+
# This approach is an attempt to include the branch without the user having to explicitly
|
83
|
+
# set it, because people tend to not update things.
|
84
|
+
def branch
|
85
|
+
if @branch.nil? && auto_detect_version_properties != false
|
86
|
+
@branch = PactBroker::Client::Git.branch(raise_error: auto_detect_version_properties == true)
|
87
|
+
else
|
88
|
+
@branch
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def consumer_version
|
93
|
+
if @consumer_version.nil? && @auto_detect_version_properties
|
94
|
+
@consumer_version = PactBroker::Client::Git.commit(raise_error: true)
|
95
|
+
else
|
96
|
+
@consumer_version
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def build_url
|
101
|
+
if @build_url.nil? && @auto_detect_version_properties
|
102
|
+
@build_url = PactBroker::Client::Git.build_url
|
86
103
|
else
|
87
|
-
|
104
|
+
@build_url
|
88
105
|
end
|
89
106
|
end
|
90
107
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"consumer": {
|
3
|
+
"name": "MyConsumer"
|
4
|
+
},
|
5
|
+
"interactions": [
|
6
|
+
{
|
7
|
+
"description": "request",
|
8
|
+
"providerStates": [
|
9
|
+
{
|
10
|
+
"name": "state 2"
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"request": {
|
14
|
+
"method": "GET",
|
15
|
+
"path": "/2"
|
16
|
+
},
|
17
|
+
"response": {
|
18
|
+
"status": 200
|
19
|
+
}
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"metadata": {
|
23
|
+
"pact-js": {
|
24
|
+
"version": "11.0.2"
|
25
|
+
},
|
26
|
+
"pactRust": {
|
27
|
+
"ffi": "0.4.0",
|
28
|
+
"models": "1.0.4"
|
29
|
+
},
|
30
|
+
"pactSpecification": {
|
31
|
+
"version": "3.0.0"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"provider": {
|
35
|
+
"name": "MyProvider"
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
{
|
2
|
+
"consumer": {
|
3
|
+
"name": "MyConsumer"
|
4
|
+
},
|
5
|
+
"interactions": [
|
6
|
+
{
|
7
|
+
"description": "request",
|
8
|
+
"providerStates": [
|
9
|
+
{
|
10
|
+
"name": "state 1"
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"request": {
|
14
|
+
"method": "GET",
|
15
|
+
"path": "/1"
|
16
|
+
},
|
17
|
+
"response": {
|
18
|
+
"status": 200
|
19
|
+
}
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"metadata": {
|
23
|
+
"pact-js": {
|
24
|
+
"version": "11.0.2"
|
25
|
+
},
|
26
|
+
"pactRust": {
|
27
|
+
"ffi": "0.4.0",
|
28
|
+
"models": "1.0.4"
|
29
|
+
},
|
30
|
+
"pactSpecification": {
|
31
|
+
"version": "3.0.0"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"provider": {
|
35
|
+
"name": "MyProvider"
|
36
|
+
}
|
37
|
+
}
|
@@ -18,15 +18,6 @@ describe "pact-broker can-i-deploy", skip_windows: true do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context "when the pacticipants can't be deployed" do
|
22
|
-
subject { `bundle exec bin/pact-broker can-i-deploy --pacticipant Wiffle --version 1.2.3 --pacticipant Meep --version 4.5.6 --broker-base-url http://localhost:5000` }
|
23
|
-
|
24
|
-
it "returns an error exit code" do
|
25
|
-
subject
|
26
|
-
expect($?.exitstatus).to_not eq 0
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
21
|
after(:all) do
|
31
22
|
Process.kill 'KILL', @pipe.pid
|
32
23
|
end
|
@@ -4,10 +4,12 @@ require 'pact_broker/client/git'
|
|
4
4
|
|
5
5
|
module PactBroker::Client::CLI
|
6
6
|
describe Broker do
|
7
|
-
describe
|
7
|
+
describe '.broker' do
|
8
8
|
before do
|
9
9
|
allow(PactBroker::Client::PublishPacts).to receive(:call).and_return(result)
|
10
|
-
allow(PactBroker::Client::Git).to receive(:branch).and_return(
|
10
|
+
allow(PactBroker::Client::Git).to receive(:branch).and_return('bar')
|
11
|
+
allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
|
12
|
+
allow(PactBroker::Client::Git).to receive(:build_url).and_return('build_url')
|
11
13
|
subject.options = OpenStruct.new(minimum_valid_options)
|
12
14
|
allow($stdout).to receive(:puts)
|
13
15
|
end
|
@@ -30,7 +32,7 @@ module PactBroker::Client::CLI
|
|
30
32
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
31
33
|
"http://pact-broker",
|
32
34
|
["spec/support/cli_test_pacts/foo.json"],
|
33
|
-
{ number: "1.2.3", tags: []
|
35
|
+
{ number: "1.2.3", tags: [] },
|
34
36
|
{},
|
35
37
|
{ pact_broker_base_url: 'http://pact-broker' }
|
36
38
|
)
|
@@ -151,7 +153,7 @@ module PactBroker::Client::CLI
|
|
151
153
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
152
154
|
anything,
|
153
155
|
anything,
|
154
|
-
hash_including(branch: "main"
|
156
|
+
hash_including(branch: "main"),
|
155
157
|
anything,
|
156
158
|
anything
|
157
159
|
)
|
@@ -159,50 +161,55 @@ module PactBroker::Client::CLI
|
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
162
|
-
context "with --auto-detect-version-properties
|
164
|
+
context "with --auto-detect-version-properties specified" do
|
163
165
|
before do
|
164
166
|
subject.options = OpenStruct.new(
|
165
|
-
minimum_valid_options.merge(auto_detect_version_properties: true)
|
167
|
+
minimum_valid_options.merge(auto_detect_version_properties: true, consumer_app_version: nil)
|
166
168
|
)
|
167
|
-
allow(subject).to receive(:explict_auto_detect_version_properties).and_return(false)
|
168
169
|
end
|
169
170
|
|
170
171
|
it "determines the git branch name" do
|
171
|
-
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error:
|
172
|
+
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
172
173
|
invoke_broker
|
173
174
|
end
|
174
175
|
|
175
|
-
it "passes in the auto detected branch option
|
176
|
+
it "passes in the auto detected branch option" do
|
176
177
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
177
178
|
anything,
|
178
179
|
anything,
|
179
|
-
hash_including(branch: "bar"
|
180
|
+
hash_including(branch: "bar"),
|
180
181
|
anything,
|
181
182
|
anything
|
182
183
|
)
|
183
184
|
invoke_broker
|
184
185
|
end
|
185
|
-
end
|
186
186
|
|
187
|
+
it 'determines the commit sha' do
|
188
|
+
expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
|
189
|
+
invoke_broker
|
190
|
+
end
|
187
191
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
it 'passes in the auto detected commit sha option' do
|
193
|
+
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
194
|
+
anything,
|
195
|
+
anything,
|
196
|
+
hash_including(number: '6.6.6'),
|
197
|
+
anything,
|
198
|
+
anything
|
192
199
|
)
|
193
|
-
|
200
|
+
invoke_broker
|
194
201
|
end
|
195
202
|
|
196
|
-
it
|
197
|
-
expect(PactBroker::Client::Git).to receive(:
|
203
|
+
it 'determines the build URL' do
|
204
|
+
expect(PactBroker::Client::Git).to receive(:build_url)
|
198
205
|
invoke_broker
|
199
206
|
end
|
200
207
|
|
201
|
-
it
|
208
|
+
it 'passes in the auto detected build URL' do
|
202
209
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
203
210
|
anything,
|
204
211
|
anything,
|
205
|
-
hash_including(
|
212
|
+
hash_including(build_url: 'build_url'),
|
206
213
|
anything,
|
207
214
|
anything
|
208
215
|
)
|
@@ -220,7 +227,7 @@ module PactBroker::Client::CLI
|
|
220
227
|
expect(PactBroker::Client::PublishPacts).to receive(:call).with(
|
221
228
|
anything,
|
222
229
|
anything,
|
223
|
-
hash_including(branch: "specified-branch"
|
230
|
+
hash_including(branch: "specified-branch"),
|
224
231
|
anything,
|
225
232
|
anything
|
226
233
|
)
|
@@ -248,6 +255,16 @@ module PactBroker::Client::CLI
|
|
248
255
|
end
|
249
256
|
end
|
250
257
|
|
258
|
+
context "with no consumer_app_version" do
|
259
|
+
before do
|
260
|
+
subject.options.consumer_app_version = nil
|
261
|
+
end
|
262
|
+
|
263
|
+
it "raises an error" do
|
264
|
+
expect { invoke_broker }.to raise_error ::Thor::RequiredArgumentMissingError, /--consumer-app-version/
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
251
268
|
context "with basic auth options specified" do
|
252
269
|
before do
|
253
270
|
subject.options = OpenStruct.new(
|
@@ -166,6 +166,32 @@ module PactBroker
|
|
166
166
|
expect(subject).to eq expected_merge
|
167
167
|
end
|
168
168
|
end
|
169
|
+
|
170
|
+
describe "with v3 pacts" do
|
171
|
+
let(:pact_hash_1) { JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider.json"), symbolize_names: true) }
|
172
|
+
let(:pact_hash_2) { JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider (1).json"), symbolize_names: true) }
|
173
|
+
let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
|
174
|
+
|
175
|
+
subject { MergePacts.call(pact_hashes) }
|
176
|
+
|
177
|
+
context "when there are no conflicts and no duplicates" do
|
178
|
+
it "adds all the interactions to the merged file" do
|
179
|
+
expect(subject[:interactions].size).to eq 2
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "when there is a conflict" do
|
184
|
+
let(:pact_hash_2) do
|
185
|
+
hash = JSON.parse(File.read("spec/fixtures/MyConsumer-MyProvider.json"), symbolize_names: true)
|
186
|
+
hash[:interactions].first[:request][:path] = "/a-different-path"
|
187
|
+
hash
|
188
|
+
end
|
189
|
+
|
190
|
+
it "raises an error with a message that contains the provider states of the conflicting interactions" do
|
191
|
+
expect { subject }.to raise_error PactMergeError, /state 1/
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
169
195
|
end
|
170
196
|
end
|
171
197
|
end
|
@@ -37,7 +37,6 @@ module PactBroker
|
|
37
37
|
let(:tags) { nil }
|
38
38
|
let(:branch) { nil }
|
39
39
|
let(:build_url) { nil }
|
40
|
-
let(:version_required) { false }
|
41
40
|
let(:pact_hash) { { consumer: { name: 'Consumer'}, provider: { name: 'Provider' }, interactions: [] } }
|
42
41
|
let(:pact_hash_2) { {consumer: { name: 'Foo' }, provider: { name: 'Bar' }, interactions: [] } }
|
43
42
|
let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")}
|
@@ -48,8 +47,7 @@ module PactBroker
|
|
48
47
|
number: consumer_version,
|
49
48
|
branch: branch,
|
50
49
|
tags: tags,
|
51
|
-
build_url: build_url
|
52
|
-
version_required: version_required
|
50
|
+
build_url: build_url
|
53
51
|
}
|
54
52
|
end
|
55
53
|
let(:pact_broker_client_options) do
|
@@ -5,7 +5,6 @@ require 'pact_broker/client/command_result'
|
|
5
5
|
|
6
6
|
module PactBroker::Client
|
7
7
|
describe PublicationTask do
|
8
|
-
|
9
8
|
before do
|
10
9
|
@consumer_version = "1.2.3"
|
11
10
|
end
|
@@ -19,6 +18,8 @@ module PactBroker::Client
|
|
19
18
|
allow(PactBroker::Client::PublishPacts).to receive(:new).and_return(publish_pacts)
|
20
19
|
allow(FileList).to receive(:[]).with(pattern).and_return(pact_file_list)
|
21
20
|
allow(PactBroker::Client::Git).to receive(:branch).and_return('foo')
|
21
|
+
allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
|
22
|
+
allow(PactBroker::Client::Git).to receive(:build_url).and_return("build_url")
|
22
23
|
allow($stdout).to receive(:puts)
|
23
24
|
end
|
24
25
|
|
@@ -33,7 +34,7 @@ module PactBroker::Client
|
|
33
34
|
|
34
35
|
context "when pacts are succesfully published" do
|
35
36
|
it "invokes PublishPacts with the default values" do
|
36
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: []
|
37
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [] }, {}, {}).and_return(publish_pacts)
|
37
38
|
expect(publish_pacts).to receive(:call).and_return(result)
|
38
39
|
Rake::Task['pact:publish'].execute
|
39
40
|
end
|
@@ -57,7 +58,7 @@ module PactBroker::Client
|
|
57
58
|
end
|
58
59
|
|
59
60
|
it "invokes PublishPacts with the write method set" do
|
60
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: []
|
61
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [] }, {}, {write: :merge}).and_return(publish_pacts)
|
61
62
|
expect(publish_pacts).to receive(:call).and_return(result)
|
62
63
|
Rake::Task['pact:publish:merge'].execute
|
63
64
|
end
|
@@ -87,81 +88,92 @@ module PactBroker::Client
|
|
87
88
|
context "when auto_detect_version_properties is explicitly set to true" do
|
88
89
|
before :all do
|
89
90
|
PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task |
|
90
|
-
task.consumer_version = '1.2.3'
|
91
91
|
task.auto_detect_version_properties = true
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
# Don't usually put 3 expects into the one it block, but if I separate them,
|
96
|
+
# only the first it block passes for some reason that I can't work out.
|
97
|
+
it "gets the commit, build_url and branch" do
|
98
|
+
expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
|
99
|
+
expect(PactBroker::Client::Git).to receive(:build_url)
|
96
100
|
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
|
97
101
|
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
98
102
|
end
|
99
103
|
|
100
|
-
it "invokes PublishPacts with the branch name" do
|
101
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything, anything).and_return(publish_pacts)
|
104
|
+
it "invokes PublishPacts with the branch name and build URL" do
|
105
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "6.6.6", branch: "foo", build_url: "build_url"), anything, anything).and_return(publish_pacts)
|
102
106
|
Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
106
|
-
context "when auto_detect_version_properties is explicitly set to true and the
|
110
|
+
context "when auto_detect_version_properties is explicitly set to true and the auto detectable attributes are specified" do
|
107
111
|
before :all do
|
108
|
-
PactBroker::Client::PublicationTask.new(:
|
109
|
-
task.consumer_version = '1.2.3'
|
112
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_true_with_attributes_specified) do | task |
|
110
113
|
task.auto_detect_version_properties = true
|
111
|
-
task.
|
114
|
+
task.consumer_version = '1.2.3'
|
115
|
+
task.branch = "feat/foo"
|
116
|
+
task.consumer_version = "3"
|
117
|
+
task.build_url = "some_build"
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
115
|
-
it "does not get the branch
|
121
|
+
it "does not get the commit, branch or build URL from Git" do
|
122
|
+
expect(PactBroker::Client::Git).to_not receive(:commit)
|
123
|
+
expect(PactBroker::Client::Git).to_not receive(:build_url)
|
116
124
|
expect(PactBroker::Client::Git).to_not receive(:branch)
|
117
|
-
Rake::Task['pact:publish:
|
125
|
+
Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
|
118
126
|
end
|
119
127
|
|
120
|
-
it "invokes PublishPacts with the specified
|
121
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "
|
122
|
-
Rake::Task['pact:publish:
|
128
|
+
it "invokes PublishPacts with the specified attributes" do
|
129
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
|
130
|
+
Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
126
134
|
context "when auto_detect_version_properties is explicitly set to false" do
|
127
135
|
before :all do
|
128
|
-
PactBroker::Client::PublicationTask.new(:
|
129
|
-
task.consumer_version = '1.2.3'
|
136
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_false) do | task |
|
130
137
|
task.auto_detect_version_properties = false
|
138
|
+
task.consumer_version = '1.2.3'
|
139
|
+
task.branch = "feat/foo"
|
140
|
+
task.consumer_version = "3"
|
141
|
+
task.build_url = "some_build"
|
131
142
|
end
|
132
143
|
end
|
133
144
|
|
134
|
-
it "does not get the
|
145
|
+
it "does not get the commit, branch or build URL from Git" do
|
146
|
+
expect(PactBroker::Client::Git).to_not receive(:commit)
|
147
|
+
expect(PactBroker::Client::Git).to_not receive(:build_url)
|
135
148
|
expect(PactBroker::Client::Git).to_not receive(:branch)
|
136
|
-
Rake::Task['pact:publish:
|
149
|
+
Rake::Task['pact:publish:auto_detect_false'].execute
|
137
150
|
end
|
138
151
|
|
139
|
-
it "invokes PublishPacts
|
140
|
-
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything,
|
141
|
-
Rake::Task['pact:publish:
|
152
|
+
it "invokes PublishPacts with the specified attributes" do
|
153
|
+
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
|
154
|
+
Rake::Task['pact:publish:auto_detect_false'].execute
|
142
155
|
end
|
143
156
|
end
|
144
157
|
|
145
|
-
context "when auto_detect_version_properties is left as its default" do
|
158
|
+
context "when auto_detect_version_properties is left as its default and the branch is not specified" do
|
146
159
|
before :all do
|
147
|
-
PactBroker::Client::PublicationTask.new(:
|
160
|
+
PactBroker::Client::PublicationTask.new(:auto_detect_default) do | task |
|
148
161
|
task.consumer_version = '1.2.3'
|
149
162
|
end
|
150
163
|
end
|
151
164
|
|
152
|
-
it "gets the git branch name" do
|
165
|
+
it "gets the git branch name but won't raise an error if it can't be determined" do
|
153
166
|
expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false)
|
154
|
-
Rake::Task['pact:publish:
|
167
|
+
Rake::Task['pact:publish:auto_detect_default'].execute
|
155
168
|
end
|
156
169
|
|
157
|
-
it "invokes PublishPacts with the branch name" do
|
170
|
+
it "invokes PublishPacts with the branch name if found" do
|
158
171
|
expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"),anything, anything).and_return(publish_pacts)
|
159
|
-
Rake::Task['pact:publish:
|
172
|
+
Rake::Task['pact:publish:auto_detect_default'].execute
|
160
173
|
end
|
161
174
|
end
|
162
175
|
|
163
176
|
describe "custom task" do
|
164
|
-
|
165
177
|
before :all do
|
166
178
|
@pact_broker_base_url = "http://some-host"
|
167
179
|
@pattern = "pact/*.json"
|
@@ -184,7 +196,7 @@ module PactBroker::Client
|
|
184
196
|
expect(PactBroker::Client::PublishPacts).to receive(:new).with(
|
185
197
|
@pact_broker_base_url,
|
186
198
|
pact_file_list,
|
187
|
-
{ number: "1.2.3", tags: [@tag], branch: "foo"
|
199
|
+
{ number: "1.2.3", tags: [@tag], branch: "foo" },
|
188
200
|
{},
|
189
201
|
{ basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
|
190
202
|
)
|
@@ -193,6 +205,17 @@ module PactBroker::Client
|
|
193
205
|
end
|
194
206
|
end
|
195
207
|
|
208
|
+
describe "with no consumer version" do
|
209
|
+
before :all do
|
210
|
+
PactBroker::Client::PublicationTask.new(:no_consumer_version) do
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "raises an error" do
|
215
|
+
expect { Rake::Task['pact:publish:no_consumer_version'].execute }.to raise_error PactBroker::Client::Error, /consumer version/
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
196
219
|
describe "timing of block execution" do
|
197
220
|
before :all do
|
198
221
|
PactBroker::Client::PublicationTask.new(:exception) do | task |
|
data/tasks/pact.rake
CHANGED
@@ -59,3 +59,82 @@ PactBroker::Client::PublicationTask.new(:pactflow_pact_foundation) do | task |
|
|
59
59
|
task.pact_broker_token = ENV["PACT_BROKER_TOKEN_PACT_FOUNDATION"]
|
60
60
|
task.build_url = PactBroker::Client::Git.build_url
|
61
61
|
end
|
62
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_nil_commit_nil_branch) do | task |
|
63
|
+
require 'pact_broker/client/version'
|
64
|
+
# publish with auto detected commit and branch
|
65
|
+
task.auto_detect_version_properties = true
|
66
|
+
task.branch = nil
|
67
|
+
task.consumer_version = nil
|
68
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
69
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
70
|
+
task.build_url = PactBroker::Client::Git.build_url
|
71
|
+
end
|
72
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_user_commit_user_branch) do | task |
|
73
|
+
require 'pact_broker/client/version'
|
74
|
+
# always accept user provided commit and branch
|
75
|
+
# even when auto_detect_version_properties enabled
|
76
|
+
task.auto_detect_version_properties = true
|
77
|
+
task.branch = 'user-provided-branch'
|
78
|
+
task.consumer_version = 'user-provided-version'
|
79
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
80
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
81
|
+
task.build_url = PactBroker::Client::Git.build_url
|
82
|
+
end
|
83
|
+
|
84
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_user_commit_nil_branch) do | task |
|
85
|
+
require 'pact_broker/client/version'
|
86
|
+
# auto detect branch, always accept user provided commit
|
87
|
+
# even where set to auto_detect_version_properties
|
88
|
+
task.auto_detect_version_properties = true
|
89
|
+
task.branch = nil
|
90
|
+
task.consumer_version = 'user-provided-version'
|
91
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
92
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
93
|
+
task.build_url = PactBroker::Client::Git.build_url
|
94
|
+
end
|
95
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_on_nil_commit_user_branch) do | task |
|
96
|
+
require 'pact_broker/client/version'
|
97
|
+
# auto detect commit, always accept user provided branch
|
98
|
+
# even where set to auto_detect_version_properties
|
99
|
+
task.auto_detect_version_properties = true
|
100
|
+
task.branch = 'user-provided-branch'
|
101
|
+
task.consumer_version = nil
|
102
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
103
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
104
|
+
task.build_url = PactBroker::Client::Git.build_url
|
105
|
+
end
|
106
|
+
|
107
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_user_commit_nil_branch) do | task |
|
108
|
+
require 'pact_broker/client/version'
|
109
|
+
# accept publish without branch, but has user provided commit
|
110
|
+
# auto_detect_version_properties off
|
111
|
+
task.auto_detect_version_properties = false
|
112
|
+
task.branch = nil
|
113
|
+
task.consumer_version = 'user-provided-version'
|
114
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
115
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
116
|
+
task.build_url = PactBroker::Client::Git.build_url
|
117
|
+
end
|
118
|
+
|
119
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_nil_commit_nil_branch) do | task |
|
120
|
+
require 'pact_broker/client/version'
|
121
|
+
# reject publish without user provided commit
|
122
|
+
# auto_detect_version_properties off
|
123
|
+
task.auto_detect_version_properties = false
|
124
|
+
task.branch = nil
|
125
|
+
task.consumer_version = nil
|
126
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
127
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
128
|
+
task.build_url = PactBroker::Client::Git.build_url
|
129
|
+
end
|
130
|
+
PactBroker::Client::PublicationTask.new(:pactflow_auto_off_empty_string_commit_nil_branch) do | task |
|
131
|
+
require 'pact_broker/client/version'
|
132
|
+
# reject publish without user provided commit
|
133
|
+
# auto_detect_version_properties off
|
134
|
+
task.auto_detect_version_properties = false
|
135
|
+
task.branch = nil
|
136
|
+
task.consumer_version = ''
|
137
|
+
task.pact_broker_base_url = ENV['PACT_BROKER_BASE_URL']
|
138
|
+
task.pact_broker_token = ENV['PACT_BROKER_TOKEN']
|
139
|
+
task.build_url = PactBroker::Client::Git.build_url
|
140
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.74.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beth Skurrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- example/scripts/deploy-consumer.sh
|
146
146
|
- example/scripts/oas.yml
|
147
147
|
- example/scripts/pact.json
|
148
|
+
- example/scripts/publish-pact-rake.sh
|
148
149
|
- example/scripts/publish-pact.sh
|
149
150
|
- example/scripts/publish-provider-contract.sh
|
150
151
|
- example/scripts/publish-verification.sh
|
@@ -255,6 +256,8 @@ files:
|
|
255
256
|
- script/update-cli-usage-in-readme.rb
|
256
257
|
- script/verification-results.txt
|
257
258
|
- script/webhook-commands.sh
|
259
|
+
- spec/fixtures/MyConsumer-MyProvider (1).json
|
260
|
+
- spec/fixtures/MyConsumer-MyProvider.json
|
258
261
|
- spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt
|
259
262
|
- spec/fixtures/approvals/can_i_deploy_ignore.approved.txt
|
260
263
|
- spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt
|
@@ -379,6 +382,8 @@ signing_key:
|
|
379
382
|
specification_version: 4
|
380
383
|
summary: See description
|
381
384
|
test_files:
|
385
|
+
- spec/fixtures/MyConsumer-MyProvider (1).json
|
386
|
+
- spec/fixtures/MyConsumer-MyProvider.json
|
382
387
|
- spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt
|
383
388
|
- spec/fixtures/approvals/can_i_deploy_ignore.approved.txt
|
384
389
|
- spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt
|