pact_broker 2.33.0 → 2.34.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97134f270141a482c9af9641cffd34827002be42
4
- data.tar.gz: '058cf5c4bdddd00ffd77b8a366cfdfbf539e40ff'
3
+ metadata.gz: fe2b3ac695d8a843322fa534dfeab9fe17956c99
4
+ data.tar.gz: 7f0fccfb8bc7b2713feb0effa685e2773ad2a90b
5
5
  SHA512:
6
- metadata.gz: cf993532a2a921c255d35c52918f5aba61f310109f2d0beaacac3abddd16b8a55bcd12b4f21b7ecbade8a9c7e2104dc3198a2efbb1d3cfa3ec45c738e5357385
7
- data.tar.gz: d5544a81be59d19d52b906f8a3c320bc25620e9020c9bc7e4d02217c7d3c549719564fa226f2df3ddd15bb8bb0776f8208d502105d0e8088cac3f018beb43804
6
+ metadata.gz: 1c339fb970aa844ebfb4efb48055a7807641076cbcad153f93a7f03df9631a86e6d36a3ad36f804d0e72f63f621805cad0fb872a609ed25399b59107f38ecaa4
7
+ data.tar.gz: 2b55bccea03acdd7304abf226109abb0a21a86b0aa43f18f4c92743b4b2e6bc5ab24e5f81cc9c10b761b86eba55038a47a94392d194cde790d841dd75df26751
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.5.3
@@ -1,3 +1,22 @@
1
+ <a name="v2.34.0"></a>
2
+ ### v2.34.0 (2019-06-14)
3
+
4
+
5
+ #### Features
6
+
7
+ * **webhooks**
8
+ * provide mapping to bitbucket build status names (#277) ([7bdf0c47](/../../commit/7bdf0c47))
9
+
10
+ * change log level for webhook triggering logs from debug to info ([2dca79c1](/../../commit/2dca79c1))
11
+
12
+
13
+ #### Bug Fixes
14
+
15
+ * gracefully handle two requests coming in at the same time to create the same pacticipant ([78d92ada](/../../commit/78d92ada))
16
+ * gracefully handle pact webhook status when there is no pact yet ([ba1f6bc7](/../../commit/ba1f6bc7))
17
+ * do not overwrite existing pactbroker.database_connector in rack env ([0da5d070](/../../commit/0da5d070))
18
+
19
+
1
20
  <a name="v2.33.0"></a>
2
21
  ### v2.33.0 (2019-06-07)
3
22
 
@@ -1,6 +1,6 @@
1
1
  # Developer setup
2
2
 
3
- * You will need to install Ruby 2.4, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
3
+ * You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
4
4
  * Install bundler (the Ruby gem dependency manager) `gem install bundler`
5
5
  * Check out the pact_broker repository and cd into it.
6
6
  * Run `bundle install`. If you have not got mysql or postgres installed locally, comment out the `mysql2` and `pg` development dependency lines in `pact_broker.gemspec`, as these are only really required on Travis.
@@ -13,5 +13,23 @@
13
13
 
14
14
  * The application will be available on `http://localhost:9292`
15
15
 
16
+ ## Running the tests
17
+
18
+ To run everything (specs, pact verifications, vulnerability scan...):
19
+
20
+ `bundle exec rake`
21
+
22
+ To run a smaller subset of the tests:
23
+
24
+ `bundle exec rake spec`
25
+
26
+ To run the "quick tests" (skip the lengthy migration specs)
27
+
28
+ `bundle exec rake spec:quick`
29
+
30
+ To run a single spec:
31
+
32
+ `bundle exec rspec path_to_your_spec.rb`
33
+
16
34
  [chruby]: https://github.com/postmodern/chruby
17
35
  [ruby-install]: https://github.com/postmodern/ruby-install
@@ -34,7 +34,7 @@ module PactBroker
34
34
  if pacticipant
35
35
  @pacticipant = pacticipant_service.update params_with_string_keys.merge('name' => pacticipant_name)
36
36
  else
37
- @pacticipant = pacticipant_service.create params_with_string_keys.merge('name' => pacticipant_name)
37
+ @pacticipant = pacticipant_service.create params.merge(:name => pacticipant_name)
38
38
  response.headers["Location"] = pacticipant_url(base_url, pacticipant)
39
39
  end
40
40
  response.body = to_json
@@ -32,7 +32,7 @@ module PactBroker
32
32
  end
33
33
 
34
34
  def from_json
35
- created_model = pacticipant_service.create params_with_string_keys
35
+ created_model = pacticipant_service.create(params)
36
36
  response.body = decorator_for(created_model).to_json(user_options: decorator_context)
37
37
  end
38
38
 
@@ -78,7 +78,7 @@ To specify an XML body, you will need to use a correctly escaped string (or use
78
78
 
79
79
  `contract_published:` triggered every time a contract is published. It is not recommended to trigger your provider verification build every time a contract is published - see `contract_content_changed` below.
80
80
 
81
- `contract_content_changed:` triggered when the content of the contract has changed since the previous publication. If `base_equality_only_on_content_that_affects_verification_results` is set to `true` in the configuration (the default), any changes to whitespace, ordering of keys, or the ordering of the `interactions` or `messages` will be ignored, and will not trigger this event. It is recommended to trigger a provider verification build for this event.
81
+ `contract_content_changed:` triggered when the content of the contract, or tags applied to the contract have changed since the previous publication. If `base_equality_only_on_content_that_affects_verification_results` is set to `true` in the configuration (the default), any changes to whitespace, ordering of keys, or the ordering of the `interactions` or `messages` will be ignored, and will not trigger this event. It is recommended to trigger a provider verification build for this event.
82
82
 
83
83
  `provider_verification_published:` triggered whenever a provider publishes a verification.
84
84
 
@@ -95,6 +95,7 @@ The following variables may be used in the request path, parameters or body, and
95
95
  * `${pactbroker.consumerLabels}`: the list of labels for the consumer associated with the pact content, separated by ", ".
96
96
  * `${pactbroker.providerLabels}`: the list of labels for the provider associated with the pact content, separated by ", ".
97
97
  * `${pactbroker.githubVerificationStatus}`: the verification status using the correct keywords for posting to the the [Github commit status API](https://developer.github.com/v3/repos/statuses).
98
+ * `${pactbroker.bitbucketVerificationStatus}`: the verification status using the correct keywords for posting to the the [Bitbucket commit status API](https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/).
98
99
  * `${pactbroker.pactUrl}`: the "permalink" URL to the newly published pact (the URL specifying the consumer version URL, rather than the "/latest" format.)
99
100
  * `${pactbroker.verificationResultUrl}`: the URL to the relevant verification result.
100
101
 
@@ -41,6 +41,9 @@ module PactBroker
41
41
  end
42
42
  end
43
43
 
44
+ # Need to be able to handle two calls that make the pacticipant at the same time.
45
+ # TODO raise error if attributes apart from name are different, because this indicates that
46
+ # the second request is not at the same time.
44
47
  def create args
45
48
  PactBroker::Domain::Pacticipant.dataset.insert_ignore.insert(
46
49
  name: args[:name],
@@ -58,6 +58,7 @@ module PactBroker
58
58
  end
59
59
 
60
60
  def self.update params
61
+ # TODO move this to the repository!
61
62
  pacticipant = pacticipant_repository.find_by_name(params.fetch('name'))
62
63
  PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
63
64
  pacticipant.save
@@ -65,10 +66,7 @@ module PactBroker
65
66
  end
66
67
 
67
68
  def self.create params
68
- pacticipant = PactBroker::Domain::Pacticipant.new
69
- PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
70
- pacticipant.save
71
- pacticipant
69
+ pacticipant_repository.create(params)
72
70
  end
73
71
 
74
72
  def self.delete name
@@ -1,3 +1,3 @@
1
1
  module PactBroker
2
- VERSION = '2.33.0'
2
+ VERSION = '2.34.0'
3
3
  end
@@ -88,7 +88,7 @@ module PactBroker
88
88
  end
89
89
 
90
90
  def reschedule_job
91
- logger.debug "Re-enqeuing job for webhook #{triggered_webhook.webhook_uuid} to run in #{backoff_time} seconds"
91
+ logger.info "Re-enqeuing job for webhook #{triggered_webhook.webhook_uuid} to run in #{backoff_time} seconds"
92
92
  Job.perform_in(backoff_time, @data.merge(error_count: error_count+1))
93
93
  end
94
94
 
@@ -20,6 +20,7 @@ module PactBroker
20
20
  '${pactbroker.consumerName}' => pact ? pact.consumer_name : "",
21
21
  '${pactbroker.providerName}' => pact ? pact.provider_name : "",
22
22
  '${pactbroker.githubVerificationStatus}' => github_verification_status,
23
+ '${pactbroker.bitbucketVerificationStatus}' => bitbucket_verification_status,
23
24
  '${pactbroker.consumerLabels}' => pacticipant_labels(pact && pact.consumer),
24
25
  '${pactbroker.providerLabels}' => pacticipant_labels(pact && pact.provider)
25
26
  }
@@ -29,6 +30,13 @@ module PactBroker
29
30
 
30
31
  attr_reader :pact, :verification, :webhook_context, :base_url
31
32
 
33
+ def bitbucket_verification_status
34
+ if verification
35
+ verification.success ? "SUCCESSFUL" : "FAILED"
36
+ else
37
+ "INPROGRESS"
38
+ end
39
+ end
32
40
 
33
41
  def github_verification_status
34
42
  if verification
@@ -164,7 +164,11 @@ module PactBroker
164
164
  end
165
165
 
166
166
  def find_latest_triggered_webhooks_for_pact pact
167
- find_latest_triggered_webhooks(pact.consumer, pact.provider)
167
+ if pact
168
+ find_latest_triggered_webhooks(pact.consumer, pact.provider)
169
+ else
170
+ []
171
+ end
168
172
  end
169
173
 
170
174
  def find_latest_triggered_webhooks consumer, provider
@@ -122,7 +122,7 @@ module PactBroker
122
122
  if webhooks.any?
123
123
  run_later(webhooks, pact, verification, event_name, options)
124
124
  else
125
- logger.debug "No enabled webhooks found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\" and event #{event_name}"
125
+ logger.info "No enabled webhooks found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\" and event #{event_name}"
126
126
  end
127
127
  end
128
128
 
@@ -131,7 +131,7 @@ module PactBroker
131
131
  webhooks.each do | webhook |
132
132
  begin
133
133
  triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION)
134
- logger.info "Scheduling job for #{webhook.description} with uuid #{webhook.uuid}"
134
+ logger.info "Scheduling job for webhook with uuid #{webhook.uuid}"
135
135
  job_data = {
136
136
  triggered_webhook: triggered_webhook,
137
137
  webhook_context: options.fetch(:webhook_context),
@@ -14,7 +14,7 @@ module PactBroker
14
14
  if pact_is_new_or_newly_tagged_or_pact_has_changed_since_previous_version?(pact)
15
15
  webhook_service.trigger_webhooks pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
16
16
  else
17
- logger.debug "Pact content has not changed since previous version, not triggering webhooks for changed content"
17
+ logger.info "Pact content has not changed since previous version, not triggering webhooks for changed content"
18
18
  end
19
19
  end
20
20
 
@@ -22,10 +22,10 @@ module PactBroker
22
22
  webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_PUBLISHED, webhook_options
23
23
  # TODO this should use the sha!
24
24
  if existing_pact.pact_version_sha != updated_pact.pact_version_sha
25
- logger.debug "Existing pact for version #{existing_pact.consumer_version_number} has been updated with new content, triggering webhooks for changed content"
25
+ logger.info "Existing pact for version #{existing_pact.consumer_version_number} has been updated with new content, triggering webhooks for changed content"
26
26
  webhook_service.trigger_webhooks updated_pact, nil, PactBroker::Webhooks::WebhookEvent::CONTRACT_CONTENT_CHANGED, webhook_options
27
27
  else
28
- logger.debug "Pact content has not changed since previous revision, not triggering webhooks for changed content"
28
+ logger.info "Pact content has not changed since previous revision, not triggering webhooks for changed content"
29
29
  end
30
30
  end
31
31
 
@@ -60,7 +60,7 @@ module PactBroker
60
60
  end
61
61
  end
62
62
  end
63
- logger.debug("Webhook triggered for the following reasons: #{messages.join(',')}" )
63
+ logger.info("Webhook triggered for the following reasons: #{messages.join(',')}" )
64
64
  end
65
65
  end
66
66
  end
@@ -20,18 +20,16 @@ module Rack
20
20
  end
21
21
 
22
22
  def call env
23
- set_database_connector
24
23
  if use_transaction? env
25
24
  call_with_transaction(add_database_connector(env))
26
25
  else
27
26
  call_without_transaction(add_database_connector(env))
28
27
  end
29
- ensure
30
- clear_database_connector
31
28
  end
32
29
 
33
30
  def add_database_connector(env)
34
- env.merge("pactbroker.database_connector" => @default_database_connector)
31
+ # maintain any existing one set by previous middleware
32
+ { "pactbroker.database_connector" => @default_database_connector }.merge(env)
35
33
  end
36
34
 
37
35
  def use_transaction? env
@@ -56,19 +54,6 @@ module Rack
56
54
  def do_not_rollback? response
57
55
  response[1].delete(::PactBroker::DO_NOT_ROLLBACK)
58
56
  end
59
-
60
- def set_database_connector
61
- Thread.current[:pact_broker_thread_data] ||= OpenStruct.new
62
- Thread.current[:pact_broker_thread_data].database_connector ||= @default_database_connector
63
- end
64
-
65
- def clear_database_connector
66
- if thread_data = Thread.current[:pact_broker_thread_data]
67
- if thread_data.database_connector == @default_database_connector
68
- thread_data.database_connector = nil
69
- end
70
- end
71
- end
72
57
  end
73
58
  end
74
59
  end
@@ -47,7 +47,7 @@ module PactBroker
47
47
 
48
48
  context "with valid JSON" do
49
49
  it "creates the pacticipant" do
50
- expect(PactBroker::Pacticipants::Service).to receive(:create).with('name' => 'New Consumer')
50
+ expect(PactBroker::Pacticipants::Service).to receive(:create).with(:name => 'New Consumer')
51
51
  subject
52
52
  end
53
53
 
@@ -112,6 +112,12 @@ module PactBroker
112
112
  ["${pactbroker.githubVerificationStatus}", "pending", :pact_with_no_verification, :nil_verification],
113
113
  ["${pactbroker.githubVerificationStatus}", "success", :pact_with_successful_verification, :nil_verification],
114
114
  ["${pactbroker.githubVerificationStatus}", "failure", :pact_with_failed_verification, :nil_verification],
115
+ ["${pactbroker.bitbucketVerificationStatus}", "SUCCESSFUL", :pact, :verification],
116
+ ["${pactbroker.bitbucketVerificationStatus}", "FAILED", :pact, :failed_verification],
117
+ ["${pactbroker.bitbucketVerificationStatus}", "INPROGRESS", :nil_pact, :nil_verification],
118
+ ["${pactbroker.bitbucketVerificationStatus}", "INPROGRESS", :pact_with_no_verification, :nil_verification],
119
+ ["${pactbroker.bitbucketVerificationStatus}", "SUCCESSFUL", :pact_with_successful_verification, :nil_verification],
120
+ ["${pactbroker.bitbucketVerificationStatus}", "FAILED", :pact_with_failed_verification, :nil_verification],
115
121
  ["${pactbroker.verificationResultUrl}", "", :pact_with_no_verification, :nil_verification],
116
122
  ["${pactbroker.verificationResultUrl}", "http://verification", :pact_with_successful_verification, :nil_verification],
117
123
  ["${pactbroker.verificationResultUrl}", "http://verification", :pact_with_successful_verification, :verification],
@@ -186,7 +186,7 @@ module PactBroker
186
186
  end
187
187
 
188
188
  it "logs that no webhook was found" do
189
- expect(logger).to receive(:debug).with(/No enabled webhooks found/)
189
+ expect(logger).to receive(:info).with(/No enabled webhooks found/)
190
190
  subject
191
191
  end
192
192
  end
@@ -50,7 +50,7 @@ module PactBroker
50
50
  include_examples "triggering a contract_content_changed event"
51
51
 
52
52
  it "logs the reason why it triggered the contract_content_changed event" do
53
- expect(logger).to receive(:debug).with(/first time untagged pact published/)
53
+ expect(logger).to receive(:info).with(/first time untagged pact published/)
54
54
  subject
55
55
  end
56
56
  end
@@ -64,7 +64,7 @@ module PactBroker
64
64
  include_examples "triggering a contract_content_changed event"
65
65
 
66
66
  it "logs the reason why it triggered the contract_content_changed event" do
67
- expect(logger).to receive(:debug).with(/pact content has changed since previous untagged version/)
67
+ expect(logger).to receive(:info).with(/pact content has changed since previous untagged version/)
68
68
  subject
69
69
  end
70
70
  end
@@ -86,7 +86,7 @@ module PactBroker
86
86
  include_examples "triggering a contract_content_changed event"
87
87
 
88
88
  it "logs the reason why it triggered the contract_content_changed event" do
89
- expect(logger).to receive(:debug).with(/first time pact published with consumer version tagged dev/)
89
+ expect(logger).to receive(:info).with(/first time pact published with consumer version tagged dev/)
90
90
  subject
91
91
  end
92
92
  end
@@ -126,7 +126,7 @@ module PactBroker
126
126
  include_examples "triggering a contract_content_changed event"
127
127
 
128
128
  it "logs the reason why it triggered the contract_content_changed event" do
129
- expect(logger).to receive(:debug).with(/version 1.2.3 has been updated with new content/)
129
+ expect(logger).to receive(:info).with(/version 1.2.3 has been updated with new content/)
130
130
  subject
131
131
  end
132
132
  end
@@ -23,7 +23,9 @@ module Rack
23
23
  ::Rack::PactBroker::DatabaseTransaction.new(api, ::PactBroker::DB.connection)
24
24
  end
25
25
 
26
- subject { self.send(http_method, "/") }
26
+ let(:rack_headers) { {} }
27
+
28
+ subject { self.send(http_method, "/", rack_headers) }
27
29
 
28
30
  it "sets the pactbroker.database_connector on the env" do
29
31
  actual_env = nil
@@ -35,6 +37,21 @@ module Rack
35
37
  expect(actual_env).to have_key("pactbroker.database_connector")
36
38
  end
37
39
 
40
+ context "when the pactbroker.database_connector already exists" do
41
+ let(:rack_headers) { { "pactbroker.database_connector" => double('existing database connector') } }
42
+ let(:existing_database_connector) { double('existing database connector') }
43
+
44
+ it "does not overwrite it", pending: "key is not showing up in rack env for some reason" do
45
+ actual_env = nil
46
+ allow(api).to receive(:call) do | env |
47
+ actual_env = env
48
+ [200, {}, {}]
49
+ end
50
+ subject
51
+ expect(actual_env["pactbroker.database_connector"]).to be existing_database_connector
52
+ end
53
+ end
54
+
38
55
  context "for get requests" do
39
56
  let(:http_method) { :get }
40
57
 
@@ -60,46 +77,6 @@ module Rack
60
77
  expect { subject }.to change { ::PactBroker::Domain::Pacticipant.count }.by(1)
61
78
  end
62
79
  end
63
-
64
- describe "setting the database connector" do
65
- let(:api) { double('api', call: [200, {}, []]) }
66
-
67
- it "sets a database connector for use in jobs scheduled by this request" do
68
- expect(api).to receive(:call) do | env |
69
- expect(Thread.current[:pact_broker_thread_data].database_connector).to_not be nil
70
- [200, {}, []]
71
- end
72
-
73
- subject
74
- end
75
-
76
- it "clears it after the request" do
77
- subject
78
- expect(Thread.current[:pact_broker_thread_data].database_connector).to be nil
79
- end
80
-
81
- context "when other middleware sets the database connector" do
82
- before do
83
- Thread.current[:pact_broker_thread_data] = OpenStruct.new(database_connector: other_database_connector)
84
- end
85
-
86
- let(:other_database_connector) { ->(&block) { block.call } }
87
-
88
- it "does not override it" do
89
- expect(api).to receive(:call) do | env |
90
- expect(Thread.current[:pact_broker_thread_data].database_connector).to eq other_database_connector
91
- [200, {}, []]
92
- end
93
-
94
- subject
95
- end
96
-
97
- it "does not clear it after the request" do
98
- subject
99
- expect(Thread.current[:pact_broker_thread_data].database_connector).to_not be nil
100
- end
101
- end
102
- end
103
80
  end
104
81
  end
105
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.33.0
4
+ version: 2.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bethany Skurrie
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-07 00:00:00.000000000 Z
13
+ date: 2019-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty