pact_broker-client 1.57.0 → 1.60.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -125,7 +125,7 @@ module PactBroker
125
125
  end
126
126
  url
127
127
  else
128
- raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version.")
128
+ raise PactBroker::Client::RelationNotFound.new("Could not find relation #{relation_name} in index resource. Try upgrading your Pact Broker as the feature you require may not exist in your version. If you are using Pactflow, you may not have the permissions required for this action.")
129
129
  end
130
130
  end
131
131
  end
@@ -24,9 +24,7 @@ module PactBroker
24
24
  method_option :provider_verification_published, type: :boolean, desc: "Trigger this webhook when a provider verification result is published"
25
25
  method_option :provider_verification_failed, type: :boolean, desc: "Trigger this webhook when a failed provider verification result is published"
26
26
  method_option :provider_verification_succeeded, type: :boolean, desc: "Trigger this webhook when a successful provider verification result is published"
27
- if ENV.fetch("PACT_BROKER_FEATURES", "").include?("contract_requiring_verification_published")
28
- method_option :contract_requiring_verification_published, type: :boolean, desc: "Trigger this webhook when a contract is published that requires verification"
29
- end
27
+ method_option :contract_requiring_verification_published, type: :boolean, desc: "Trigger this webhook when a contract is published that requires verification"
30
28
  method_option :team_uuid, banner: "UUID", desc: "UUID of the Pactflow team to which the webhook should be assigned (Pactflow only)"
31
29
  shared_authentication_options
32
30
  end
@@ -25,7 +25,7 @@ module PactBroker
25
25
  using PactBroker::Client::HashRefinements
26
26
 
27
27
  COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
28
- BRANCH_ENV_VAR_NAMES = %w{GITHUB_REF BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME BITBUCKET_BRANCH}.freeze
28
+ 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}.freeze
29
29
  COMMIT_ENV_VAR_NAMES = %w{GITHUB_SHA BUILDKITE_COMMIT CIRCLE_SHA1 TRAVIS_COMMIT GIT_COMMIT APPVEYOR_REPO_COMMIT CI_COMMIT_ID BITBUCKET_COMMIT}
30
30
  BUILD_URL_ENV_VAR_NAMES = %w{BUILDKITE_BUILD_URL CIRCLE_BUILD_URL TRAVIS_BUILD_WEB_URL BUILD_URL }
31
31
 
@@ -91,11 +91,11 @@ module PactBroker
91
91
  end
92
92
 
93
93
  def _link!(key)
94
- _link(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
94
+ _link(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href))
95
95
  end
96
96
 
97
97
  def _links!(key)
98
- _links(key) or raise RelationNotFoundError.new("Could not find relation '#{key}' in resource at #{@href}")
98
+ _links(key) or raise RelationNotFoundError.new(relation_not_found_error_message(key, @href))
99
99
  end
100
100
 
101
101
  def embedded_entity
@@ -161,6 +161,10 @@ module PactBroker
161
161
  def self_href(entity_hash)
162
162
  entity_hash["_links"] && entity_hash["_links"]["self"] && entity_hash["_links"]["self"]["href"]
163
163
  end
164
+
165
+ def relation_not_found_error_message(key, href)
166
+ "Could not find relation '#{key}' in resource at #{href}. The most likely reason for this is that you are on an old version of the Pact Broker and you need to upgrade, or you are using Pactflow and you don't have the permissions required for this action."
167
+ end
164
168
  end
165
169
 
166
170
  class ErrorEntity < Entity
@@ -18,29 +18,40 @@ module PactBroker
18
18
  def merge original, additional
19
19
  new_pact = JSON.parse(original.to_json, symbolize_names: true)
20
20
 
21
- additional[:interactions].each do |new_interaction|
21
+ merge_interactions_or_messages(new_pact, original, additional, :interactions)
22
+ merge_interactions_or_messages(new_pact, original, additional, :messages)
23
+
24
+ new_pact
25
+ end
26
+
27
+ private
28
+
29
+ def merge_interactions_or_messages(new_pact, original, additional, key)
30
+ return unless additional[key] || original[key]
31
+
32
+ additional_messages_or_interactions = additional[key] || []
33
+ original_messages_or_interactions = original[key] || []
34
+ new_pact[key] ||= []
35
+
36
+ additional_messages_or_interactions.each do |new_interaction|
22
37
  # check to see if this interaction matches an existing interaction
23
- overwrite_index = original[:interactions].find_index do |original_interaction|
38
+ overwrite_index = original_messages_or_interactions.find_index do |original_interaction|
24
39
  same_description_and_state?(original_interaction, new_interaction)
25
40
  end
26
41
 
27
42
  # overwrite existing interaction if a match is found, otherwise appends the new interaction
28
43
  if overwrite_index
29
- if new_interaction == original[:interactions][overwrite_index]
30
- new_pact[:interactions][overwrite_index] = new_interaction
44
+ if new_interaction == original_messages_or_interactions[overwrite_index]
45
+ new_pact[key][overwrite_index] = new_interaction
31
46
  else
32
- raise PactMergeError, almost_duplicate_message(original[:interactions][overwrite_index], new_interaction)
47
+ raise PactMergeError, almost_duplicate_message(original_messages_or_interactions[overwrite_index], new_interaction)
33
48
  end
34
49
  else
35
- new_pact[:interactions] << new_interaction
50
+ new_pact[key] << new_interaction
36
51
  end
37
52
  end
38
-
39
- new_pact
40
53
  end
41
54
 
42
- private
43
-
44
55
  def almost_duplicate_message(original, new_interaction)
45
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. " +
46
57
  "Please use a different description or provider state, or hard-code any random data.\n\n" +
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.57.0'
3
+ VERSION = '1.60.0'
4
4
  end
5
5
  end
@@ -50,7 +50,7 @@ module PactBroker
50
50
  return error_result(CREATING_WEBHOOK_WITH_UUID_NOT_SUPPORTED)
51
51
  end
52
52
  else
53
- webhook_entity = index_entity._link("pb:webhooks").post(request_body_with_optional_consumer_and_provider)
53
+ webhook_entity = index_entity._link!("pb:webhooks").post(request_body_with_optional_consumer_and_provider)
54
54
  end
55
55
 
56
56
  if webhook_entity.response.status == 405
@@ -8,10 +8,10 @@ Gem::Specification.new do |gem|
8
8
  gem.name = "pact_broker-client"
9
9
  gem.version = PactBroker::Client::VERSION
10
10
  gem.authors = ["Beth Skurrie"]
11
- gem.email = ["bskurrie@dius.com.au"]
12
- gem.description = %q{Client for the Pact Broker. Publish, retrieve and query pacts and verification results.}
11
+ gem.email = ["beth@bethesque.com"]
12
+ gem.description = %q{Client for the Pact Broker. Publish, retrieve and query pacts and verification results. Manage webhooks and environments.}
13
13
  gem.summary = %q{See description}
14
- gem.homepage = "https://github.com/bethesque/pact_broker-client.git"
14
+ gem.homepage = "https://github.com/pact-foundation/pact_broker-client.git"
15
15
 
16
16
  gem.required_ruby_version = '>= 2.0'
17
17
 
@@ -33,6 +33,6 @@ Gem::Specification.new do |gem|
33
33
  gem.add_development_dependency 'conventional-changelog', '~>1.3'
34
34
  gem.add_development_dependency 'pact', '~> 1.16'
35
35
  gem.add_development_dependency 'pact-support', '~> 1.16'
36
- gem.add_development_dependency 'approvals', '>=0.0.24', '<1.0.0'
36
+ gem.add_development_dependency 'approvals', '0.0.24'
37
37
  gem.add_development_dependency 'rspec-its', '~> 1.3'
38
38
  end
@@ -137,8 +137,12 @@ def reformat_docs(generated_thor_docs)
137
137
  else
138
138
  lines
139
139
  end
140
- # line
141
- end.flatten.join("\n").gsub("/go/", "/").gsub(File.basename(__FILE__), "pact-broker")
140
+ end
141
+ .flatten
142
+ .collect { | line | line.gsub(/\s+$/, "") }
143
+ .join("\n")
144
+ .gsub("/go/", "/")
145
+ .gsub(File.basename(__FILE__), "pact-broker")
142
146
  end
143
147
 
144
148
  def update_readme(usage_docs)
@@ -112,7 +112,7 @@ module PactBroker::Client
112
112
 
113
113
  context 'when the key does not exist' do
114
114
  it 'raises an error' do
115
- expect { subject._link!('foo') }.to raise_error RelationNotFoundError, "Could not find relation 'foo' in resource at http://pact"
115
+ expect { subject._link!('foo') }.to raise_error RelationNotFoundError, /Could not find relation 'foo' in resource at http:\/\/pact/
116
116
  end
117
117
  end
118
118
  end
@@ -4,63 +4,166 @@ module PactBroker
4
4
  module Client
5
5
  describe MergePacts do
6
6
  describe ".call" do
7
- let(:pact_hash_1) do
8
- {
9
- other: 'info',
10
- interactions: [
11
- {providerState: 1, description: 1, foo: 'bar' }
12
- ]
13
- }
14
- end
7
+ describe "with a pact with interactions" do
8
+ let(:pact_hash_1) do
9
+ {
10
+ other: 'info',
11
+ interactions: [
12
+ { providerState: 1, description: 1, foo: 'bar' }
13
+ ]
14
+ }
15
+ end
15
16
 
16
- let(:pact_hash_2) do
17
- {
18
- interactions: [
19
- {providerState: 2, description: 2, foo: 'wiffle' }
20
- ]
21
- }
22
- end
17
+ let(:pact_hash_2) do
18
+ {
19
+ interactions: [
20
+ { providerState: 2, description: 2, foo: 'wiffle' }
21
+ ]
22
+ }
23
+ end
23
24
 
24
- let(:pact_hash_3) do
25
- {
26
- interactions: [
27
- {providerState: 3, description: 3, foo: 'meep' },
28
- {providerState: 1, description: 1, foo: 'bar' }
29
- ]
30
- }
31
- end
25
+ let(:pact_hash_3) do
26
+ {
27
+ interactions: [
28
+ { providerState: 3, description: 3, foo: 'meep' },
29
+ { providerState: 1, description: 1, foo: 'bar' }
30
+ ]
31
+ }
32
+ end
32
33
 
33
- let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
34
-
35
- let(:expected_merge) do
36
- {
37
- other: 'info',
38
- interactions: [
39
- {providerState: 1, description: 1, foo: 'bar' },
40
- {providerState: 2, description: 2, foo: 'wiffle' },
41
- {providerState: 3, description: 3, foo: 'meep' }
42
- ]
43
- }
44
- end
34
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
35
+
36
+ let(:expected_merge) do
37
+ {
38
+ other: 'info',
39
+ interactions: [
40
+ { providerState: 1, description: 1, foo: 'bar' },
41
+ { providerState: 2, description: 2, foo: 'wiffle' },
42
+ { providerState: 3, description: 3, foo: 'meep' }
43
+ ]
44
+ }
45
+ end
46
+
47
+ subject { MergePacts.call(pact_hashes) }
45
48
 
46
- subject { MergePacts.call(pact_hashes) }
49
+ it "merges the interactions by consumer/provider" do
50
+ expect(subject).to eq expected_merge
51
+ end
52
+
53
+ context "when an interaction is found with the same state and description but has a difference elsewhere" do
54
+ let(:pact_hash_3) do
55
+ {
56
+ interactions: [
57
+ { providerState: 3, description: 3, foo: 'meep' },
58
+ { providerState: 1, description: 1, foo: 'different' }
59
+ ]
60
+ }
61
+ end
47
62
 
48
- it "merges the interactions by consumer/provider" do
49
- expect(subject).to eq expected_merge
63
+ it "raises an error" do
64
+ expect { subject }.to raise_error PactMergeError, /foo.*different/
65
+ end
66
+ end
50
67
  end
51
68
 
52
- context "when an interaction is found with the same state and description but has a difference elsewhere" do
69
+ describe "with a pact with messages" do
70
+ let(:pact_hash_1) do
71
+ {
72
+ other: 'info',
73
+ messages: [
74
+ { providerState: 1, description: 1, foo: 'bar' }
75
+ ]
76
+ }
77
+ end
78
+
79
+ let(:pact_hash_2) do
80
+ {
81
+ messages: [
82
+ { providerState: 2, description: 2, foo: 'wiffle' }
83
+ ]
84
+ }
85
+ end
86
+
53
87
  let(:pact_hash_3) do
88
+ {
89
+ messages: [
90
+ { providerState: 3, description: 3, foo: 'meep' },
91
+ { providerState: 1, description: 1, foo: 'bar' }
92
+ ]
93
+ }
94
+ end
95
+
96
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2, pact_hash_3] }
97
+
98
+ let(:expected_merge) do
99
+ {
100
+ other: 'info',
101
+ messages: [
102
+ { providerState: 1, description: 1, foo: 'bar' },
103
+ { providerState: 2, description: 2, foo: 'wiffle' },
104
+ { providerState: 3, description: 3, foo: 'meep' }
105
+ ]
106
+ }
107
+ end
108
+
109
+ subject { MergePacts.call(pact_hashes) }
110
+
111
+ it "merges the messages by consumer/provider" do
112
+ expect(subject).to eq expected_merge
113
+ end
114
+
115
+ context "when an interaction is found with the same state and description but has a difference elsewhere" do
116
+ let(:pact_hash_3) do
117
+ {
118
+ messages: [
119
+ { providerState: 3, description: 3, foo: 'meep' },
120
+ { providerState: 1, description: 1, foo: 'different' }
121
+ ]
122
+ }
123
+ end
124
+
125
+ it "raises an error" do
126
+ expect { subject }.to raise_error PactMergeError, /foo.*different/
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "with a pact with messages and a pact with interactions" do
132
+ let(:pact_hash_1) do
133
+ {
134
+ other: 'info',
135
+ messages: [
136
+ { providerState: 1, description: 1, foo: 'bar' }
137
+ ]
138
+ }
139
+ end
140
+
141
+ let(:pact_hash_2) do
54
142
  {
55
143
  interactions: [
56
- {providerState: 3, description: 3, foo: 'meep' },
57
- {providerState: 1, description: 1, foo: 'different' }
144
+ { providerState: 2, description: 2, foo: 'wiffle' }
58
145
  ]
59
146
  }
60
147
  end
61
148
 
62
- it "raises an error" do
63
- expect { subject }.to raise_error PactMergeError, /foo.*different/
149
+ let(:pact_hashes) { [pact_hash_1, pact_hash_2] }
150
+
151
+ let(:expected_merge) do
152
+ {
153
+ other: 'info',
154
+ messages: [
155
+ { providerState: 1, description: 1, foo: 'bar' }
156
+ ],
157
+ interactions: [
158
+ { providerState: 2, description: 2, foo: 'wiffle' }
159
+ ]
160
+ }
161
+ end
162
+
163
+ subject { MergePacts.call(pact_hashes) }
164
+
165
+ it "merges the messages by consumer/provider" do
166
+ expect(subject).to eq expected_merge
64
167
  end
65
168
  end
66
169
  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.57.0
4
+ version: 1.60.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-05 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -174,22 +174,16 @@ dependencies:
174
174
  name: approvals
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - ">="
177
+ - - '='
178
178
  - !ruby/object:Gem::Version
179
179
  version: 0.0.24
180
- - - "<"
181
- - !ruby/object:Gem::Version
182
- version: 1.0.0
183
180
  type: :development
184
181
  prerelease: false
185
182
  version_requirements: !ruby/object:Gem::Requirement
186
183
  requirements:
187
- - - ">="
184
+ - - '='
188
185
  - !ruby/object:Gem::Version
189
186
  version: 0.0.24
190
- - - "<"
191
- - !ruby/object:Gem::Version
192
- version: 1.0.0
193
187
  - !ruby/object:Gem::Dependency
194
188
  name: rspec-its
195
189
  requirement: !ruby/object:Gem::Requirement
@@ -205,9 +199,9 @@ dependencies:
205
199
  - !ruby/object:Gem::Version
206
200
  version: '1.3'
207
201
  description: Client for the Pact Broker. Publish, retrieve and query pacts and verification
208
- results.
202
+ results. Manage webhooks and environments.
209
203
  email:
210
- - bskurrie@dius.com.au
204
+ - beth@bethesque.com
211
205
  executables:
212
206
  - pact-broker
213
207
  extensions: []
@@ -412,11 +406,11 @@ files:
412
406
  - spec/support/pacts_latest_list.json
413
407
  - spec/support/shared_context.rb
414
408
  - tasks/pact.rake
415
- homepage: https://github.com/bethesque/pact_broker-client.git
409
+ homepage: https://github.com/pact-foundation/pact_broker-client.git
416
410
  licenses:
417
411
  - MIT
418
412
  metadata: {}
419
- post_install_message:
413
+ post_install_message:
420
414
  rdoc_options: []
421
415
  require_paths:
422
416
  - lib
@@ -431,8 +425,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
431
425
  - !ruby/object:Gem::Version
432
426
  version: '0'
433
427
  requirements: []
434
- rubygems_version: 3.2.30
435
- signing_key:
428
+ rubygems_version: 3.3.12
429
+ signing_key:
436
430
  specification_version: 4
437
431
  summary: See description
438
432
  test_files: