pact_broker 2.38.1 → 2.39.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +2 -2
  3. data/CHANGELOG.md +45 -0
  4. data/DEVELOPER_DOCUMENTATION.md +9 -0
  5. data/Dockerfile +2 -0
  6. data/Gemfile +1 -1
  7. data/README.md +10 -3
  8. data/config/database.yml +10 -2
  9. data/docs/images/Pactflow logo - black small.png +0 -0
  10. data/lib/pact_broker/api.rb +5 -2
  11. data/lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb +41 -0
  12. data/lib/pact_broker/api/decorators/dashboard_decorator.rb +1 -1
  13. data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +1 -1
  14. data/lib/pact_broker/api/decorators/integration_decorator.rb +2 -0
  15. data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +34 -0
  16. data/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator.rb +27 -0
  17. data/lib/pact_broker/api/resources/badge.rb +4 -4
  18. data/lib/pact_broker/api/resources/can_i_deploy.rb +41 -0
  19. data/lib/pact_broker/api/resources/dashboard.rb +1 -1
  20. data/lib/pact_broker/api/resources/index.rb +15 -4
  21. data/lib/pact_broker/api/resources/latest_pact.rb +10 -4
  22. data/lib/pact_broker/api/resources/latest_verification_for_latest_pact.rb +19 -0
  23. data/lib/pact_broker/api/resources/pact.rb +5 -4
  24. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +54 -0
  25. data/lib/pact_broker/api/resources/verification.rb +6 -1
  26. data/lib/pact_broker/badges/service.rb +11 -11
  27. data/lib/pact_broker/db/clean.rb +72 -12
  28. data/lib/pact_broker/doc/controllers/app.rb +3 -1
  29. data/lib/pact_broker/doc/views/can-i-deploy.markdown +14 -0
  30. data/lib/pact_broker/doc/views/index/pacticipant-version-tag.markdown +8 -0
  31. data/lib/pact_broker/doc/views/integrations.markdown +1 -1
  32. data/lib/pact_broker/doc/views/matrix.markdown +7 -0
  33. data/lib/pact_broker/doc/views/metrics.markdown +5 -0
  34. data/lib/pact_broker/domain/index_item.rb +3 -3
  35. data/lib/pact_broker/domain/pact.rb +28 -1
  36. data/lib/pact_broker/index/service.rb +38 -20
  37. data/lib/pact_broker/integrations/integration.rb +16 -0
  38. data/lib/pact_broker/integrations/service.rb +15 -1
  39. data/lib/pact_broker/matrix/can_i_deploy_query_schema.rb +25 -0
  40. data/lib/pact_broker/matrix/parse_can_i_deploy_query.rb +29 -0
  41. data/lib/pact_broker/matrix/quick_row.rb +255 -0
  42. data/lib/pact_broker/matrix/repository.rb +5 -17
  43. data/lib/pact_broker/matrix/row.rb +0 -1
  44. data/lib/pact_broker/metrics/service.rb +36 -2
  45. data/lib/pact_broker/pacts/all_pact_publications.rb +3 -2
  46. data/lib/pact_broker/pacts/head_pact.rb +30 -0
  47. data/lib/pact_broker/pacts/latest_pact_publications.rb +8 -1
  48. data/lib/pact_broker/pacts/latest_tagged_pact_publications.rb +5 -1
  49. data/lib/pact_broker/pacts/pact_publication.rb +2 -1
  50. data/lib/pact_broker/pacts/pact_version.rb +20 -0
  51. data/lib/pact_broker/pacts/repository.rb +33 -4
  52. data/lib/pact_broker/pacts/service.rb +15 -2
  53. data/lib/pact_broker/pacts/squash_pacts_for_verification.rb +37 -0
  54. data/lib/pact_broker/pacts/verifiable_pact.rb +30 -0
  55. data/lib/pact_broker/pacts/verifiable_pact_messages.rb +75 -0
  56. data/lib/pact_broker/test/test_data_builder.rb +30 -2
  57. data/lib/pact_broker/ui/view_models/index_item.rb +4 -4
  58. data/lib/pact_broker/ui/view_models/matrix_line.rb +1 -1
  59. data/lib/pact_broker/ui/views/index/show-with-tags.haml +1 -1
  60. data/lib/pact_broker/ui/views/index/show.haml +1 -1
  61. data/lib/pact_broker/ui/views/matrix/show.haml +2 -2
  62. data/lib/pact_broker/verifications/{verification_status.rb → pseudo_branch_status.rb} +10 -4
  63. data/lib/pact_broker/version.rb +1 -1
  64. data/script/docker/mysql-db-start.sh +10 -0
  65. data/spec/features/can_i_deploy_spec.rb +31 -0
  66. data/spec/features/get_latest_verification_for_pact_spec.rb +17 -0
  67. data/spec/features/get_provider_pacts_for_verification_spec.rb +39 -0
  68. data/spec/features/metrics_spec.rb +1 -1
  69. data/spec/features/pending_pacts_spec.rb +109 -0
  70. data/spec/integration/ui/matrix_spec.rb +30 -0
  71. data/spec/lib/pact_broker/api/contracts/verifiable_pacts_query_schema_spec.rb +62 -0
  72. data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +1 -1
  73. data/spec/lib/pact_broker/api/decorators/integration_decorator_spec.rb +5 -1
  74. data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +30 -5
  75. data/spec/lib/pact_broker/api/decorators/verifiable_pacts_query_decorator_spec.rb +46 -0
  76. data/spec/lib/pact_broker/api/resources/badge_spec.rb +3 -3
  77. data/spec/lib/pact_broker/api/resources/provider_pacts_for_verification_spec.rb +35 -0
  78. data/spec/lib/pact_broker/api/resources/verification_spec.rb +18 -0
  79. data/spec/lib/pact_broker/badges/service_spec.rb +18 -18
  80. data/spec/lib/pact_broker/db/clean_spec.rb +69 -8
  81. data/spec/lib/pact_broker/doc/coverage_spec.rb +8 -2
  82. data/spec/lib/pact_broker/index/service_spec.rb +28 -14
  83. data/spec/lib/pact_broker/integrations/integration_spec.rb +60 -0
  84. data/spec/lib/pact_broker/integrations/service_spec.rb +27 -0
  85. data/spec/lib/pact_broker/matrix/quick_row_spec.rb +31 -0
  86. data/spec/lib/pact_broker/matrix/repository_spec.rb +8 -8
  87. data/spec/lib/pact_broker/matrix/service_spec.rb +4 -4
  88. data/spec/lib/pact_broker/metrics/service_spec.rb +56 -0
  89. data/spec/lib/pact_broker/pacts/pact_version_spec.rb +69 -0
  90. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +65 -0
  91. data/spec/lib/pact_broker/pacts/repository_find_wip_pact_versions_for_provider_spec.rb +54 -24
  92. data/spec/lib/pact_broker/pacts/service_find_for_verification_spec.rb +51 -0
  93. data/spec/lib/pact_broker/pacts/squash_pacts_for_verification_spec.rb +92 -0
  94. data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +93 -0
  95. data/spec/lib/pact_broker/pacts/verifiable_pact_spec.rb +0 -0
  96. data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +10 -10
  97. data/spec/lib/pact_broker/verifications/{verification_status_spec.rb → pseudo_branch_status_spec.rb} +4 -4
  98. data/spec/support/shared_examples_for_responses.rb +7 -1
  99. metadata +56 -13
  100. data/lib/pact_broker/api/resources/pending_provider_pacts.rb +0 -21
  101. data/spec/features/get_pacts_to_verify_spec.rb +0 -41
  102. data/spec/features/get_wip_provider_pacts_spec.rb +0 -26
  103. data/spec/lib/pact_broker/api/resources/pending_provider_pacts_spec.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ac1db03f84cc1808c8478d24d33e24ad0b4cb9a4d8d5de5f4f123e9ab7994f2d
4
- data.tar.gz: 5a96dc5e3fa3378a34b648f421091442a3b616fd123de2b42b96dee9389916b0
2
+ SHA1:
3
+ metadata.gz: 7e280e7c13bd55791cab9e6133c2a63c62e18c89
4
+ data.tar.gz: 34f9831b62572f892ccd85a4a71f8f05e0660210
5
5
  SHA512:
6
- metadata.gz: 5c3b636c4768b80bd046abdeec33c75cf53e3c0793590521e6b0cec337e1591ee9f71dd9130de9b9c7a10159a732de7d851864c9898276aa19e357fd3b7f8279
7
- data.tar.gz: 7e41605da8904ed4b0a80cca5737f0adc7766c4dd330fe89e012934359772e449b8b26bdc46fd5acb9d76a837460f26048d08863c9654aaf84ed5bf2f913bb4d
6
+ metadata.gz: 358dff2b700249596936bf1cd380568a01220941a0f63e4d70ed3366f5e69b1a8fa2855976011779439dfd01e43cae4e2c79b370a9f1920bcb98a199da92f132
7
+ data.tar.gz: f5a45fde10fde4d65afef8cc1ce3202da9dd46163c5f0096f6c421a305dc87a1f0528502bfcc0a15d4771b7a95e0e42864a6de1f218e56a1daadee73e5b69225
@@ -25,8 +25,8 @@ TBC
25
25
 
26
26
  ## Steps to reproduce
27
27
 
28
- Provide a repository, gist or reproducable code snippet so that we can test the problem.
28
+ Provide a repository, gist or reproducible code snippet so that we can test the problem.
29
29
 
30
- ## Relevent log files
30
+ ## Relevant log files
31
31
 
32
32
  Please ensure you set logging to `DEBUG` and attach any relevant log files here (or link from a gist).
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ <a name="v2.39.0"></a>
2
+ ### v2.39.0 (2019-10-21)
3
+
4
+
5
+ #### Features
6
+
7
+ * **matrix**
8
+ * optimise query for can-i-deploy, again ([78b8a5d5](/../../commit/78b8a5d5))
9
+ * handle overwritten revisions in database rather than code ([1459b46a](/../../commit/1459b46a))
10
+
11
+ * **clean**
12
+ * allow date to be specified for data to clean and return counts of deleted and kept rows ([29dcbacd](/../../commit/29dcbacd))
13
+
14
+ * update db clean to remove webhooks triggered by verifications ([f38eeaea](/../../commit/f38eeaea))
15
+ * add revisions per consumer version and verifications per pact version to metrics ([f764fbca](/../../commit/f764fbca))
16
+ * show more helpful error message when someone tries to get /all verifications for a pact ([bea59518](/../../commit/bea59518))
17
+ * add missing HAL docs for various relations and correct test that should have identified their absence ([a057427c](/../../commit/a057427c))
18
+ * add can-i-deploy endpoint to expose a simplified interface to the /matrix resource that accepts the same parameters as the can-i-deploy CLI. ([02443f39](/../../commit/02443f39))
19
+ * add 'pacts for verification' endpoint (#308) ([31fb8aa7](/../../commit/31fb8aa7))
20
+
21
+ * **metrics**
22
+ * add revision count ([4369f227](/../../commit/4369f227))
23
+ * add matrix and head matrix row counts ([5fb705ec](/../../commit/5fb705ec))
24
+
25
+ * **dashboard api**
26
+ * eager load the pact_version ([b6b5c900](/../../commit/b6b5c900))
27
+
28
+ * **integrations**
29
+ * sort by integration with most recent activity first ([35bdbb92](/../../commit/35bdbb92))
30
+ * add verification status to integrations endpoint ([437ba769](/../../commit/437ba769))
31
+
32
+
33
+ #### Bug Fixes
34
+
35
+ * typos on ISSUE_TEMPLATE (#311) ([a10b4792](/../../commit/a10b4792))
36
+ * add endpoints to get latest verification for latest pact ([73413727](/../../commit/73413727))
37
+ * support application/vnd.pactbrokerextended.v1+json for latest pact resource ([476ff595](/../../commit/476ff595))
38
+
39
+ * **matrix**
40
+ * undefined method ([b365c64b](/../../commit/b365c64b))
41
+
42
+ * **dashboard api**
43
+ * remove expensive queries for unused data ([07206559](/../../commit/07206559))
44
+
45
+
1
46
  <a name="v2.38.1"></a>
2
47
  ### v2.38.1 (2019-09-23)
3
48
 
@@ -31,6 +31,15 @@
31
31
 
32
32
  Domain classes are found in `lib/pact_broker/domain`. Many of these classes are Sequel models, as the difference between the Sequel model and the functionality required for the domain logic is similar enough to share the class. Some classes separate the domain and database logic, as the concerns are too different. Where there is a separate database model, this will be kept in a module with the pluralized name of the model eg. `PactBroker::Webhooks`. Unfortunately, this sometimes makes it difficult to tell in the calling code whether you have a domain or a database model. I haven't worked out a clean way to handle this yet.
33
33
 
34
+ ### Domain terminology
35
+
36
+ * `pacticipant` - an application that participates in a pact. A very bad pun which I deeply regret.
37
+ * `pact` - this term is confusing and overloaded. It generally means a `pact publication` in the code.
38
+ * `pact publication` - the resource that gets created when a PUT request is sent to the Pact Broker to /pacts/provider/PROVIDER/consumer/CONSUMER/version/VERSION.
39
+ * `pact version` - the JSON contents of the pact publication. One pact version may belong to many pact publications. That is, if a pact publication with exactly the same contents is published twice, then a new
40
+ pact publication resource will be created, but it will reuse the existing pact version.
41
+ * `pseudo branch` - A time ordered list of pacts that are related to a particular tag. The most recent pact for each pseudo branch is a "head" pact.
42
+
34
43
  ### Tables
35
44
  * `pact_versions` - the JSON content of each UNIQUE pact document is stored in this table. The same content is likely to be published over and over again by the CI builds, so deduplicating the content saves us a lot of disk space. Once created, a row is never modified. Uniqueness is just done on string equality - no special pact logic. This means that pacts with randomly generated values or orders (most of pact-jvm pacts!) will get a new version record every time they publish.
36
45
 
data/Dockerfile CHANGED
@@ -1,5 +1,6 @@
1
1
  FROM ruby:2.5.3-alpine
2
2
 
3
+ ENV INSTALL_MYSQL=true
3
4
  RUN apk update \
4
5
  && apk --no-cache add \
5
6
  "build-base>=0.5" \
@@ -10,6 +11,7 @@ RUN apk update \
10
11
  "sqlite-dev>=3.28" \
11
12
  "sqlite>=3.28" \
12
13
  "tzdata>=2019" \
14
+ "mariadb-dev>=10.3" \
13
15
  && rm -rf /var/cache/apk/*
14
16
 
15
17
  WORKDIR /app
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
  gem 'simplecov', :require => false, :group => :test
6
6
 
7
7
  if ENV['INSTALL_MYSQL'] == "true"
8
- gem 'mysql2', '~>0.3.15'
8
+ gem 'mysql2', '~>0.5'
9
9
  end
data/README.md CHANGED
@@ -8,7 +8,13 @@
8
8
 
9
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.
10
10
 
11
- **Why do I need one?**
11
+ <br/>
12
+ <a href="https:/pactflow.io/?utm_source=github&utm_campaign=pact_broker_intro"><img src="docs/images/Pactflow logo - black small.png"></a>
13
+ <br/>
14
+
15
+ You can try out a Pact Broker for free at <a href="https:/pactflow.io/?utm_source=github&utm_campaign=pact_broker_intro"/>pactflow.io</a>. Built by a group of core Pact maintainers, Pactflow is a fork of the OSS Pact Broker with extra goodies like an improved UI, field level verification results and federated login.
16
+
17
+ **Why do I need a Pact Broker?**
12
18
 
13
19
  Contract testing is an alternative approach to traditional integration testing that gives you tests that are quicker to execute, and that are more maintainable at scale. One down side of the approach is that the important information that would be available all in one place at the end of an integration test suite execution (that is, the version numbers of all the applications that were tested together, and whether the tests passed or failed) is now spread out across many different builds. The Pact Broker is a tool that brings all this information back together again, and allows you to deploy with safety.
14
20
 
@@ -38,6 +44,7 @@ Features:
38
44
  * [Docker Pact Broker][docker]
39
45
  * A [CLI][cli] for encorporating the Pact workflow into your continuous integration process.
40
46
 
47
+
41
48
  ### How would I use the Pact Broker?
42
49
 
43
50
  #### Step 1. Consumer CI build
@@ -128,7 +135,7 @@ Use the HAL browser to view documentation as you browse.
128
135
 
129
136
  #### Hosted
130
137
 
131
- In a hurry? Hate having to run your own infrastructure? Check out the [Hosted Pact Broker][hosted] - it's fast, it's secure and it's free!
138
+ In a hurry? Hate having to run your own infrastructure? Check out [pactflow.io][pactflow] - it's fast, it's secure and it's free to trial!
132
139
 
133
140
  #### Container solutions
134
141
 
@@ -161,7 +168,7 @@ Please read the [UPGRADING.md](UPGRADING.md) documentation before upgrading your
161
168
  [different-teams]: https://github.com/pact-foundation/pact-ruby/wiki/Using-pact-where-the-consumer-team-is-different-from-the-provider-team
162
169
  [docker]: https://hub.docker.com/r/dius/pact-broker
163
170
  [terraform]: https://github.com/nadnerb/terraform-pact-broker
164
- [hosted]: https://pact.dius.com.au/?utm_source=github&utm_campaign=GITHUB_BROKER&utm_medium=github
171
+ [pactflow]: https:/pactflow.io/?utm_source=github&utm_campaign=pact_broker_usage
165
172
  [wiki]: https://github.com/pact-foundation/pact_broker/wiki
166
173
  [reverse-proxy-docs]: https://github.com/pact-foundation/pact_broker/wiki/Configuration#running-the-broker-behind-a-reverse-proxy
167
174
  [stackoverflow]: http://stackoverflow.com/questions/tagged/pact-broker
data/config/database.yml CHANGED
@@ -16,11 +16,15 @@ test:
16
16
  database: postgres
17
17
  username: postgres
18
18
  password: postgres
19
- host: "localhost"
19
+ host: localhost
20
20
  port: "5433"
21
21
  mysql:
22
22
  <<: *default
23
23
  adapter: mysql2
24
+ docker_mysql:
25
+ <<: *default
26
+ adapter: mysql2
27
+ host: "192.168.0.9"
24
28
 
25
29
  development:
26
30
  default:
@@ -34,11 +38,15 @@ development:
34
38
  database: postgres
35
39
  username: postgres
36
40
  password: postgres
37
- host: "localhost"
41
+ host: localhost
38
42
  port: "5432"
39
43
  mysql:
40
44
  <<: *default
41
45
  adapter: mysql2
46
+ docker_mysql:
47
+ <<: *default
48
+ adapter: mysql2
49
+ host: localhost
42
50
 
43
51
  production:
44
52
  default:
@@ -30,6 +30,8 @@ module PactBroker
30
30
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', 'latest'], Api::Resources::LatestVerificationForPact, {resource_name: "latest_verification_results_for_pact_version"}
31
31
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number], Api::Resources::Verification, {resource_name: "verification_result"}
32
32
  add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number, 'triggered-webhooks'], Api::Resources::VerificationTriggeredWebhooks, {resource_name: "verification_result_triggered_webhooks"}
33
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', 'verification-results','latest'], Api::Resources::LatestVerificationForLatestPact, {resource_name: "latest_verification_results_for_latest_pact_publication"}
34
+ add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag, 'verification-results','latest'], Api::Resources::LatestVerificationForLatestPact, {resource_name: "latest_verification_results_for_latest_tagged_pact_publication"}
33
35
  add ['verification-results', 'consumer', :consumer_name, 'version', :consumer_version_number,'latest'], Api::Resources::LatestVerificationsForConsumerVersion, {resource_name: "verification_results_for_consumer_version"}
34
36
 
35
37
  # Badges
@@ -47,8 +49,8 @@ module PactBroker
47
49
  add ['pacts', 'provider', :provider_name, 'latest', :tag], Api::Resources::LatestProviderPacts, {resource_name: "latest_tagged_provider_pact_publications"}
48
50
  add ['pacts', 'latest'], Api::Resources::LatestPacts, {resource_name: "latest_pacts"}
49
51
 
50
- # Pending pacts
51
- add ['pacts', 'provider', :provider_name, 'pending'], Api::Resources::PendingProviderPacts, {resource_name: "pending_provider_pact_publications"}
52
+ # Pacts for verification
53
+ add ['pacts', 'provider', :provider_name, 'for-verification'], Api::Resources::ProviderPactsForVerification, {resource_name: "pacts_for_verification"}
52
54
 
53
55
  # Deprecated pact
54
56
  add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publications", deprecated: "true"} # Deprecate, singular /pact
@@ -86,6 +88,7 @@ module PactBroker
86
88
  add ['matrix', 'provider', :provider_name, 'consumer', :consumer_name], Api::Resources::MatrixForConsumerAndProvider, {resource_name: "matrix_consumer_provider"}
87
89
  add ['matrix', 'provider', :provider_name, 'latest', :provider_tag, 'consumer', :consumer_name, 'latest', :tag, 'badge'], Api::Resources::MatrixBadge, {resource_name: "matrix_tag_badge"}
88
90
  add ['matrix'], Api::Resources::Matrix, {resource_name: "matrix"}
91
+ add ['can-i-deploy'], Api::Resources::CanIDeploy, {resource_name: "can-i-deploy"}
89
92
 
90
93
  add ['dashboard'], Api::Resources::Dashboard, {resource_name: "dashboard"}
91
94
  add ['dashboard', 'provider', :provider_name, 'consumer', :consumer_name ], Api::Resources::Dashboard, {resource_name: "integration_dashboard"}
@@ -0,0 +1,41 @@
1
+ require 'dry-validation'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Contracts
6
+ class VerifiablePactsQuerySchema
7
+ SCHEMA = Dry::Validation.Schema do
8
+ optional(:provider_version_tags).maybe(:array?)
9
+ # optional(:exclude_other_pending).filled(included_in?: ["true", "false"])
10
+ optional(:consumer_version_selectors).each do
11
+ schema do
12
+ required(:tag).filled(:str?)
13
+ optional(:latest).filled(included_in?: ["true", "false"])
14
+ end
15
+ end
16
+ end
17
+
18
+ def self.call(params)
19
+ select_first_message(flatten_index_messages(SCHEMA.call(params).messages(full: true)))
20
+ end
21
+
22
+ def self.select_first_message(messages)
23
+ messages.each_with_object({}) do | (key, value), new_messages |
24
+ new_messages[key] = [value.first]
25
+ end
26
+ end
27
+
28
+ def self.flatten_index_messages(messages)
29
+ if messages[:consumer_version_selectors]
30
+ new_messages = messages[:consumer_version_selectors].collect do | index, value |
31
+ value.values.flatten.collect { | text | "#{text} at index #{index}"}
32
+ end.flatten
33
+ messages.merge(consumer_version_selectors: new_messages)
34
+ else
35
+ messages
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -45,7 +45,7 @@ module PactBroker
45
45
  pactTags: pact_tags(index_item, base_url),
46
46
  latestVerificationResult: verification_hash(index_item, base_url),
47
47
  latestVerificationResultTags: verification_tags(index_item, base_url),
48
- verificationStatus: index_item.verification_status.to_s,
48
+ verificationStatus: index_item.pseudo_branch_verification_status.to_s,
49
49
  webhookStatus: index_item.webhook_status.to_s,
50
50
  latestWebhookExecution: latest_webhook_execution(index_item, base_url),
51
51
  _links: links(index_item, base_url)
@@ -41,7 +41,7 @@ module PactBroker
41
41
  index_item.provider_name,
42
42
  index_item.provider_version_number,
43
43
  index_item.latest_verification_latest_tags.collect(&:name).sort.join(", "),
44
- index_item.verification_status.to_s
44
+ index_item.pseudo_branch_verification_status.to_s
45
45
  )
46
46
  end
47
47
  end
@@ -15,6 +15,8 @@ module PactBroker
15
15
  property :name
16
16
  end
17
17
 
18
+ property :verificationStatus, getter: ->(represented:, **) { represented.verification_status_for_latest_pact.to_s }
19
+
18
20
  link "pb:dashboard" do | options |
19
21
  {
20
22
  title: "BETA: Pacts to show on the dashboard",
@@ -1,11 +1,45 @@
1
1
  require_relative 'base_decorator'
2
2
  require 'pact_broker/api/pact_broker_urls'
3
+ require 'delegate'
4
+ require 'pact_broker/pacts/verifiable_pact_messages'
3
5
 
4
6
  module PactBroker
5
7
  module Api
6
8
  module Decorators
7
9
  class VerifiablePactDecorator < BaseDecorator
8
10
 
11
+ # Allows a "flat" VerifiablePact to look like it has
12
+ # a nested verification_properties object for Reform
13
+ class Reshaper < SimpleDelegator
14
+ def verification_properties
15
+ __getobj__()
16
+ end
17
+ end
18
+
19
+ def initialize(verifiable_pact)
20
+ super(Reshaper.new(verifiable_pact))
21
+ end
22
+
23
+ property :verification_properties, as: :verificationProperties do
24
+ property :pending
25
+ property :pending_reason, as: :pendingReason, exec_context: :decorator
26
+ property :inclusion_reason, as: :inclusionReason, exec_context: :decorator
27
+
28
+ def inclusion_reason
29
+ PactBroker::Pacts::VerifiablePactMessages.new(represented).inclusion_reason
30
+ end
31
+
32
+ def pending_reason
33
+ PactBroker::Pacts::VerifiablePactMessages.new(represented).pending_reason
34
+ end
35
+ end
36
+
37
+ link :self do | context |
38
+ {
39
+ href: pact_version_url(represented, context[:base_url]),
40
+ name: represented.name
41
+ }
42
+ end
9
43
  end
10
44
  end
11
45
  end
@@ -0,0 +1,27 @@
1
+ require_relative 'base_decorator'
2
+ require_relative 'verifiable_pact_decorator'
3
+ require 'pact_broker/api/pact_broker_urls'
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Decorators
8
+ class VerifiablePactsQueryDecorator < BaseDecorator
9
+ collection :provider_version_tags
10
+
11
+ collection :consumer_version_selectors, class: OpenStruct do
12
+ property :tag
13
+ property :latest, setter: ->(fragment:, represented:, **) { represented.latest = (fragment == 'true') }
14
+ end
15
+
16
+
17
+ def from_hash(*args)
18
+ # Should remember how to do this via Representable...
19
+ result = super
20
+ result.consumer_version_selectors = [] if result.consumer_version_selectors.nil?
21
+ result.provider_version_tags = [] if result.provider_version_tags.nil?
22
+ result
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
- require 'pact_broker/verifications/verification_status'
2
+ require 'pact_broker/verifications/pseudo_branch_status'
3
3
  require 'pact_broker/configuration'
4
4
 
5
5
  module PactBroker
@@ -32,7 +32,7 @@ module PactBroker
32
32
 
33
33
  def to_svg
34
34
  response.headers['Cache-Control'] = 'no-cache'
35
- comment + badge_service.pact_verification_badge(pact, label, initials, verification_status)
35
+ comment + badge_service.pact_verification_badge(pact, label, initials, pseudo_branch_verification_status)
36
36
  end
37
37
 
38
38
  def pact
@@ -44,8 +44,8 @@ module PactBroker
44
44
  @verification ||= verification_service.find_latest_verification_for(pact.consumer, pact.provider, identifier_from_path[:tag])
45
45
  end
46
46
 
47
- def verification_status
48
- @verification_status ||= PactBroker::Verifications::Status.new(pact, latest_verification).to_sym
47
+ def pseudo_branch_verification_status
48
+ @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(pact, latest_verification).to_sym
49
49
  end
50
50
 
51
51
  def label
@@ -0,0 +1,41 @@
1
+ require 'pact_broker/api/resources/matrix'
2
+ require 'pact_broker/matrix/can_i_deploy_query_schema'
3
+ require 'pact_broker/matrix/parse_can_i_deploy_query'
4
+
5
+ module PactBroker
6
+ module Api
7
+ module Resources
8
+ class CanIDeploy < Matrix
9
+ def initialize
10
+ @query_params = JSON.parse(Rack::Utils.parse_nested_query(request.uri.query).to_json, symbolize_names: true)
11
+ @selectors, @options = PactBroker::Matrix::ParseCanIDeployQuery.call(query_params)
12
+ end
13
+
14
+ def malformed_request?
15
+ if (errors = query_schema.call(query_params)).any?
16
+ set_json_validation_error_messages(errors)
17
+ true
18
+ else
19
+ false
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :query_params
26
+
27
+ def query_schema
28
+ PactBroker::Api::Contracts::CanIDeployQuerySchema
29
+ end
30
+
31
+ def selectors
32
+ @selectors
33
+ end
34
+
35
+ def options
36
+ @options
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -28,7 +28,7 @@ module PactBroker
28
28
  private
29
29
 
30
30
  def index_items
31
- index_service.find_index_items(identifier_from_path.merge(tags: true, dashboard: true))
31
+ index_service.find_index_items_for_api(identifier_from_path)
32
32
  end
33
33
  end
34
34
  end