pact_broker 2.58.2 → 2.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release_gem.yml +27 -7
  3. data/CHANGELOG.md +43 -0
  4. data/README.md +1 -1
  5. data/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema.rb +10 -3
  6. data/lib/pact_broker/api/decorators/version_decorator.rb +2 -0
  7. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +26 -8
  8. data/lib/pact_broker/api/resources/all_webhooks.rb +9 -0
  9. data/lib/pact_broker/api/resources/badge.rb +4 -0
  10. data/lib/pact_broker/api/resources/can_i_deploy.rb +8 -0
  11. data/lib/pact_broker/api/resources/dashboard.rb +4 -0
  12. data/lib/pact_broker/api/resources/error_handler.rb +2 -4
  13. data/lib/pact_broker/api/resources/group.rb +8 -0
  14. data/lib/pact_broker/api/resources/index.rb +15 -8
  15. data/lib/pact_broker/api/resources/integration.rb +12 -0
  16. data/lib/pact_broker/api/resources/integrations.rb +9 -1
  17. data/lib/pact_broker/api/resources/label.rb +12 -5
  18. data/lib/pact_broker/api/resources/latest_pact.rb +6 -2
  19. data/lib/pact_broker/api/resources/latest_pacts.rb +9 -1
  20. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +8 -0
  21. data/lib/pact_broker/api/resources/pact.rb +5 -1
  22. data/lib/pact_broker/api/resources/pacticipant.rb +4 -0
  23. data/lib/pact_broker/api/resources/pacticipants.rb +14 -0
  24. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +4 -1
  25. data/lib/pact_broker/api/resources/provider_pacts.rb +5 -1
  26. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +3 -8
  27. data/lib/pact_broker/badges/service.rb +3 -2
  28. data/lib/pact_broker/configuration.rb +16 -4
  29. data/lib/pact_broker/doc/views/layouts/main.haml +1 -1
  30. data/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown +78 -0
  31. data/lib/pact_broker/domain/pact.rb +9 -0
  32. data/lib/pact_broker/groups/service.rb +1 -1
  33. data/lib/pact_broker/index/service.rb +6 -0
  34. data/lib/pact_broker/matrix/deployment_status_summary.rb +1 -1
  35. data/lib/pact_broker/pacts/content.rb +30 -5
  36. data/lib/pact_broker/pacts/repository.rb +25 -31
  37. data/lib/pact_broker/pacts/selector.rb +8 -0
  38. data/lib/pact_broker/policies.rb +2 -2
  39. data/lib/pact_broker/test/test_data_builder.rb +4 -4
  40. data/lib/pact_broker/ui/controllers/clusters.rb +1 -1
  41. data/lib/pact_broker/ui/controllers/groups.rb +2 -2
  42. data/lib/pact_broker/ui/controllers/index.rb +1 -1
  43. data/lib/pact_broker/ui/controllers/matrix.rb +2 -2
  44. data/lib/pact_broker/ui/views/groups/show.html.erb +3 -3
  45. data/lib/pact_broker/ui/views/index/show-with-tags.haml +10 -10
  46. data/lib/pact_broker/ui/views/index/show.haml +6 -6
  47. data/lib/pact_broker/ui/views/layouts/main.haml +1 -1
  48. data/lib/pact_broker/ui/views/matrix/show.haml +4 -5
  49. data/lib/pact_broker/version.rb +1 -1
  50. data/lib/pact_broker/webhooks/job.rb +8 -2
  51. data/public/javascripts/pact.js +6 -2
  52. data/script/seed.rb +5 -7
  53. data/spec/features/get_provider_pacts_for_verification_spec.rb +0 -18
  54. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_json_query_schema_spec.rb +23 -4
  55. data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +4 -0
  56. data/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +24 -6
  57. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +18 -1
  58. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +8 -38
  59. data/spec/lib/pact_broker/badges/service_spec.rb +6 -6
  60. data/spec/lib/pact_broker/pacts/content_spec.rb +90 -0
  61. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +14 -0
  62. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +62 -0
  63. data/spec/lib/pact_broker/webhooks/job_spec.rb +19 -1
  64. data/spec/support/database_cleaner.rb +1 -5
  65. metadata +3 -5
  66. data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +0 -36
  67. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_query_schema_spec.rb +0 -97
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2dc3ce078c6b984d9e17ec748d50487434740c1b4cc828ffe93c222bb64709e
4
- data.tar.gz: 20b4316a8e3ecc24902b82e5c600c6d2bb9b3e861e6574317c2704ce952d7f26
3
+ metadata.gz: dbaaee53f1641458eb110582a96bf0be98d7078ef1fa681ffee934c6e8007347
4
+ data.tar.gz: 84a2f6e6785acc85cf7053b86a54574746cb06de917bd11a0dff23403046aff5
5
5
  SHA512:
6
- metadata.gz: bed27eae0215a6d2f499bfa99b9717c0085c825cf8e7b721a66c27d91d4d2ecac56aedeba2e42989399d50a5d45a938b1c4ac9cede35ce70956bbb0d3de0d6e3
7
- data.tar.gz: f5b82be7ede7645c77182541a99d9c69ff7047bd7d6c7ddb7e01870ed12ae859ee7a08f8b8a8cbbc66c6e407adef34ab136674258c0664c7b2fba0e899509814
6
+ metadata.gz: de93223c0a1d52af6563bf31b2ae733c41b6cec65afb4a61be741d78f47cf18484ee2fa292c9660b8db09cb3a1a66c549decb145a0b7a036477a9ac73b70f8c6
7
+ data.tar.gz: 04d3a59551f4fe9f46af8b65cd6c0dc3326ac86a594298eb22d529e33f6a98e39cdf6f9c682bd69bd9bbb85f4f290fe3e2f706d71cfa766b61def28c0dbd7bfc
@@ -6,20 +6,40 @@ on:
6
6
  - release-triggered
7
7
 
8
8
  jobs:
9
- build:
9
+ release:
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
13
  with:
14
14
  fetch-depth: 0
15
+ # - name: 'Wait for status checks'
16
+ # id: wait-for-status-checks
17
+ # uses: "WyriHaximus/github-action-wait-for-status@v2"
18
+ # with:
19
+ # checkInterval: 15
20
+ # env:
21
+ # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
15
22
  - uses: pact-foundation/release-gem@v0.0.11
16
23
  env:
17
24
  GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_API_KEY }}'
18
25
  GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
19
26
  INCREMENT: '${{ github.event.client_payload.increment }}'
20
- # - name: Trigger release of pact-cli Docker image
21
- # uses: peter-evans/repository-dispatch@v1
22
- # with:
23
- # token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }}
24
- # repository: pact-foundation/pact-ruby-cli
25
- # event-type: gem-released
27
+ notify-gem-released:
28
+ needs: release
29
+ strategy:
30
+ matrix:
31
+ repository: [pact-foundation/pact-broker-docker, DiUS/pact_broker-docker]
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - name: Notify ${{ matrix.repository }} of gem release
35
+ uses: peter-evans/repository-dispatch@v1
36
+ with:
37
+ token: ${{ secrets.GHTOKENNOTIFYPBRELEASED }}
38
+ repository: ${{ matrix.repository }}
39
+ event-type: gem-released
40
+ client-payload: |
41
+ {
42
+ "name": "${{ needs.release.outputs.gem_name }}",
43
+ "version": "${{ needs.release.outputs.version }}",
44
+ "increment": "${{ needs.release.outputs.increment }}"
45
+ }
@@ -1,3 +1,46 @@
1
+ <a name="v2.60.0"></a>
2
+ ### v2.60.0 (2020-09-08)
3
+
4
+ #### Features
5
+
6
+ * **pacts for verification**
7
+ * add deprecation title to beta:provider-pacts-for-verification relation ([47a61f69](/../../commit/47a61f69))
8
+ * do not require environment variable feature toggle to enable feature ([7d0fe1ea](/../../commit/7d0fe1ea))
9
+ * allow consumer to be specified with fallback tags, and overall latest to be specified with or without a consumer ([2d52d173](/../../commit/2d52d173))
10
+
11
+ #### Bug Fixes
12
+
13
+ * correctly handle new test results format when merging test results with pact contents ([b35ab71b](/../../commit/b35ab71b))
14
+
15
+ <a name="v2.59.2"></a>
16
+ ### v2.59.2 (2020-08-06)
17
+
18
+ #### Bug Fixes
19
+
20
+ * gracefully handle contracts without interactions or messages in deployment status warnings ([6c223e69](/../../commit/6c223e69))
21
+ * add missing info level log for business level errors ([80a895bf](/../../commit/80a895bf))
22
+
23
+ <a name="v2.59.1"></a>
24
+ ### v2.59.1 (2020-08-04)
25
+
26
+ #### Bug Fixes
27
+
28
+ * fix error rendering relationships diagram when the number of index items is greater than one page ([93a19982](/../../commit/93a19982))
29
+
30
+ <a name="v2.59.0"></a>
31
+ ### v2.59.0 (2020-07-30)
32
+
33
+ #### Features
34
+
35
+ * add timestamps to version resource ([818a0c2c](/../../commit/818a0c2c))
36
+
37
+ <a name="v2.58.3"></a>
38
+ ### v2.58.3 (2020-07-25)
39
+
40
+ #### Bug Fixes
41
+
42
+ * correctly encode user entered data in attributes, Javascript, and HTML ([523980e2](/../../commit/523980e2))
43
+
1
44
  <a name="v2.58.2"></a>
2
45
  ### v2.58.2 (2020-07-17)
3
46
 
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Code Climate](https://codeclimate.com/github/pact-foundation/pact_broker/badges/gpa.svg)](https://codeclimate.com/github/pact-foundation/pact_broker)
7
7
  [![Test Coverage](https://codeclimate.com/github/pact-foundation/pact_broker/badges/coverage.svg)](https://codeclimate.com/github/pact-foundation/pact_broker/coverage)
8
8
 
9
- The Pact Broker is an application for sharing for consumer driven contracts and verification results. It is optimised for use with "pacts" (contracts created by the [Pact][pact-docs] framework), but can be used for any type of contract that can be serialized to JSON.
9
+ The Pact Broker is an application for sharing of consumer driven contracts and verification results. It is optimised for use with "pacts" (contracts created by the [Pact][pact-docs] framework), but can be used for any type of contract that can be serialized to JSON.
10
10
 
11
11
  <br/>
12
12
  <a href="https:/pactflow.io/?utm_source=github&utm_campaign=pact_broker_intro"><img src="docs/images/Pactflow logo - black small.png"></a>
@@ -1,5 +1,6 @@
1
1
  require 'dry-validation'
2
2
  require 'pact_broker/hash_refinements'
3
+ require 'pact_broker/string_refinements'
3
4
  require 'pact_broker/api/contracts/dry_validation_workarounds'
4
5
  require 'pact_broker/api/contracts/dry_validation_predicates'
5
6
 
@@ -9,6 +10,7 @@ module PactBroker
9
10
  class VerifiablePactsJSONQuerySchema
10
11
  extend DryValidationWorkarounds
11
12
  using PactBroker::HashRefinements
13
+ using PactBroker::StringRefinements
12
14
 
13
15
  SCHEMA = Dry::Validation.Schema do
14
16
  configure do
@@ -24,7 +26,7 @@ module PactBroker
24
26
  # end
25
27
  # end
26
28
 
27
- required(:tag).filled(:str?)
29
+ optional(:tag).filled(:str?)
28
30
  optional(:latest).filled(included_in?: [true, false])
29
31
  optional(:fallbackTag).filled(:str?)
30
32
  optional(:consumer).filled(:str?, :not_blank?)
@@ -54,8 +56,9 @@ module PactBroker
54
56
  errors << "fallbackTag can only be set if latest is true (at index #{index})"
55
57
  end
56
58
 
57
- if selector[:consumer] && selector[:latest]
58
- errors << "specifying a consumer with latest == true is not yet supported (at index #{index})"
59
+
60
+ if not_provided?(selector[:tag]) && selector[:latest] != true
61
+ errors << "latest must be true, or a tag must be provided (at index #{index})"
59
62
  end
60
63
  end
61
64
  if errors.any?
@@ -64,6 +67,10 @@ module PactBroker
64
67
  end
65
68
  end
66
69
  end
70
+
71
+ def self.not_provided?(value)
72
+ value.nil? || value.blank?
73
+ end
67
74
  end
68
75
  end
69
76
  end
@@ -10,6 +10,8 @@ module PactBroker
10
10
 
11
11
  collection :tags, embedded: true, :extend => PactBroker::Api::Decorators::EmbeddedTagDecorator
12
12
 
13
+ include Timestamps
14
+
13
15
  link :self do | options |
14
16
  {
15
17
  title: 'Version',
@@ -4,6 +4,7 @@ require 'redcarpet'
4
4
  require 'pact/doc/markdown/consumer_contract_renderer'
5
5
  require 'pact_broker/api/pact_broker_urls'
6
6
  require 'pact_broker/logging'
7
+ require 'rack'
7
8
 
8
9
  module PactBroker
9
10
  module Api
@@ -58,8 +59,8 @@ module PactBroker
58
59
  #{badge_list_item}
59
60
  #{badge_markdown_item}
60
61
  <li>
61
- <span class='name'>#{@pact.consumer.name} version:</span>
62
- <span class='value'>#{@pact.consumer_version_number}#{tags}</span>
62
+ <span class='name'>#{consumer_name} version:</span>
63
+ <span class='value'>#{consumer_version_number}#{tags}</span>
63
64
  </li>
64
65
  <li>
65
66
  <span class='name' title='#{published_date}'>Date published:</span>
@@ -75,9 +76,9 @@ module PactBroker
75
76
  <a href=\"#{base_url}/\">Home</a>
76
77
  </li>
77
78
  <li>
78
- <span data-consumer-name=\"#{@pact.consumer.name}\"
79
- data-provider-name=\"#{@pact.provider.name}\"
80
- data-consumer-version-number=\"#{@pact.consumer_version_number}\"
79
+ <span data-consumer-name=\"#{consumer_name}\"
80
+ data-provider-name=\"#{provider_name}\"
81
+ data-consumer-version-number=\"#{consumer_version_number}\"
81
82
  data-pact-url=\"#{pact_url}\"
82
83
  class='more-options glyphicon glyphicon-option-horizontal'
83
84
  aria-hidden='true'></span>
@@ -88,7 +89,7 @@ module PactBroker
88
89
 
89
90
  def badge_list_item
90
91
  "<li class='pact-badge'>
91
- <img src='#{badge_url}'/>
92
+ <img src=\"#{badge_url}\"/>
92
93
  </li>
93
94
  "
94
95
  end
@@ -117,7 +118,19 @@ module PactBroker
117
118
  end
118
119
 
119
120
  def title
120
- "Pact between #{@pact.consumer.name} and #{@pact.provider.name}"
121
+ "Pact between #{consumer_name} and #{provider_name}"
122
+ end
123
+
124
+ def consumer_version_number
125
+ h(@pact.consumer_version_number)
126
+ end
127
+
128
+ def consumer_name
129
+ h(@pact.consumer.name)
130
+ end
131
+
132
+ def provider_name
133
+ h(@pact.provider.name)
121
134
  end
122
135
 
123
136
  def published_date
@@ -154,7 +167,8 @@ module PactBroker
154
167
 
155
168
  def tags
156
169
  if @pact.consumer_version_tag_names.any?
157
- " (#{@pact.consumer_version_tag_names.join(", ")})"
170
+ tag_names = @pact.consumer_version_tag_names.collect{ |t| h(t) }.join(", ")
171
+ " (#{tag_names})"
158
172
  else
159
173
  ""
160
174
  end
@@ -179,6 +193,10 @@ module PactBroker
179
193
  logger.info "Could not parse the following content to a Pact due to #{e.class} #{e.message}, showing raw content instead: #{@json_content}"
180
194
  raise NotAPactError
181
195
  end
196
+
197
+ def h string
198
+ Rack::Utils.escape_html(string)
199
+ end
182
200
  end
183
201
  end
184
202
  end
@@ -45,6 +45,15 @@ module PactBroker
45
45
  response.body = Decorators::WebhookDecorator.new(saved_webhook).to_json(decorator_options)
46
46
  end
47
47
 
48
+ def policy_name
49
+ :'webhooks::webooks'
50
+ end
51
+
52
+ def policy_record
53
+ # Note: consumer and provider not yet set on new webhook
54
+ request.post? ? webhook : webhooks
55
+ end
56
+
48
57
  private
49
58
 
50
59
  def validation_errors? webhook
@@ -42,6 +42,10 @@ module PactBroker
42
42
  badge_service.pact_verification_badge_url(pact, label, initials, pseudo_branch_verification_status, tags)
43
43
  end
44
44
 
45
+ def policy_name
46
+ :'badges::badge'
47
+ end
48
+
45
49
  private
46
50
 
47
51
  def pact
@@ -21,6 +21,14 @@ module PactBroker
21
21
  end
22
22
  end
23
23
 
24
+ def policy_name
25
+ :'matrix::can_i_deploy'
26
+ end
27
+
28
+ def policy_record
29
+ selectors
30
+ end
31
+
24
32
  private
25
33
 
26
34
  attr_reader :query_params, :selectors, :options
@@ -25,6 +25,10 @@ module PactBroker
25
25
  PactBroker::Api::Decorators::DashboardTextDecorator.new(index_items).to_text(user_options: decorator_context)
26
26
  end
27
27
 
28
+ def policy_name
29
+ :'dashboard::dashboard'
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def index_items
@@ -5,11 +5,8 @@ module PactBroker
5
5
  module Api
6
6
  module Resources
7
7
  class ErrorHandler
8
-
9
8
  include PactBroker::Logging
10
9
 
11
- WARNING_ERROR_CLASSES = [Sequel::ForeignKeyConstraintViolation]
12
-
13
10
  def self.call e, request, response
14
11
  error_reference = generate_error_reference
15
12
  if log_as_warning?(e)
@@ -17,6 +14,7 @@ module PactBroker
17
14
  elsif reportable?(e)
18
15
  log_error(e, "Error reference #{error_reference}")
19
16
  report(e, error_reference, request)
17
+ else
20
18
  logger.info("Error reference #{error_reference}", e)
21
19
  end
22
20
  response.body = response_body_hash(e, error_reference).to_json
@@ -31,7 +29,7 @@ module PactBroker
31
29
  end
32
30
 
33
31
  def self.log_as_warning?(e)
34
- WARNING_ERROR_CLASSES.any? { |clazz| e.is_a?(clazz) }
32
+ PactBroker.configuration.warning_error_classes.any? { |clazz| e.is_a?(clazz) }
35
33
  end
36
34
 
37
35
  def self.display_message(e, error_reference)
@@ -22,6 +22,14 @@ module PactBroker
22
22
  PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(group).to_csv
23
23
  end
24
24
 
25
+ def policy_name
26
+ :'groups::group'
27
+ end
28
+
29
+ def policy_record
30
+ pacticipant
31
+ end
32
+
25
33
  private
26
34
 
27
35
  def group
@@ -121,6 +121,17 @@ module PactBroker
121
121
  title: "Determine if an application can be safely deployed to an environment identified by the given tag",
122
122
  templated: true
123
123
  },
124
+ 'pb:provider-pacts-for-verification' => {
125
+ href: base_url + '/pacts/provider/{provider}/for-verification',
126
+ title: 'Pact versions to be verified for the specified provider',
127
+ templated: true
128
+ },
129
+ 'beta:provider-pacts-for-verification' => {
130
+ name: 'beta',
131
+ href: base_url + '/doc/{rel}?context=index',
132
+ title: 'DEPRECATED - please use pb:provider-pacts-for-verification',
133
+ templated: true
134
+ },
124
135
  'curies' =>
125
136
  [{
126
137
  name: 'pb',
@@ -133,16 +144,12 @@ module PactBroker
133
144
  }]
134
145
  }
135
146
 
136
- if PactBroker.feature_enabled?(:pacts_for_verification)
137
- links_hash['beta:provider-pacts-for-verification'] = {
138
- href: base_url + '/pacts/provider/{provider}/for-verification',
139
- title: 'Pact versions to be verified for the specified provider',
140
- templated: true
141
- }
142
- end
143
-
144
147
  links_hash
145
148
  end
149
+
150
+ def policy_name
151
+ :'index::index'
152
+ end
146
153
  end
147
154
  end
148
155
  end
@@ -16,6 +16,18 @@ module PactBroker
16
16
  integration_service.delete(consumer_name, provider_name)
17
17
  true
18
18
  end
19
+
20
+ def policy_name
21
+ :'integrations::integration'
22
+ end
23
+
24
+ def policy_resource
25
+ integration
26
+ end
27
+
28
+ def integration
29
+ @integration ||= OpenStruct.new(consumer: consumer, provider: provider)
30
+ end
19
31
  end
20
32
  end
21
33
  end
@@ -26,13 +26,21 @@ module PactBroker
26
26
  end
27
27
 
28
28
  def integrations
29
- integration_service.find_all
29
+ @integrations ||= integration_service.find_all
30
30
  end
31
31
 
32
32
  def delete_resource
33
33
  integration_service.delete_all
34
34
  true
35
35
  end
36
+
37
+ def policy_name
38
+ :'integrations::integrations'
39
+ end
40
+
41
+ def policy_resource
42
+ integrations
43
+ end
36
44
  end
37
45
  end
38
46
  end
@@ -19,7 +19,7 @@ module PactBroker
19
19
 
20
20
  def from_json
21
21
  unless label
22
- @label = label_service.create identifier_from_path
22
+ @label = label_service.create(identifier_from_path)
23
23
  # Make it return a 201 by setting the Location header
24
24
  response.headers["Location"] = label_url(label, base_url)
25
25
  end
@@ -27,26 +27,33 @@ module PactBroker
27
27
  end
28
28
 
29
29
  def resource_exists?
30
- !!resource_object
30
+ !!label
31
31
  end
32
32
 
33
33
  def resource_object
34
34
  label
35
35
  end
36
36
 
37
+ def policy_name
38
+ :'labels::label'
39
+ end
40
+
41
+ def policy_record
42
+ label
43
+ end
44
+
37
45
  def to_json
38
46
  PactBroker::Api::Decorators::LabelDecorator.new(label).to_json(decorator_options)
39
47
  end
40
48
 
41
49
  def label
42
- @label ||= label_service.find identifier_from_path
50
+ @label ||= label_service.find(identifier_from_path)
43
51
  end
44
52
 
45
53
  def delete_resource
46
- label_service.delete identifier_from_path
54
+ label_service.delete(identifier_from_path)
47
55
  true
48
56
  end
49
-
50
57
  end
51
58
  end
52
59