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
@@ -1,4 +1,5 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
+ require 'pact_broker/feature_toggle'
2
3
  require 'json'
3
4
 
4
5
  module PactBroker
@@ -18,7 +19,7 @@ module PactBroker
18
19
  end
19
20
 
20
21
  def links
21
- {
22
+ links_hash = {
22
23
  'self' =>
23
24
  {
24
25
  href: base_url,
@@ -109,10 +110,10 @@ module PactBroker
109
110
  href: base_url + '/metrics',
110
111
  title: "Get Pact Broker metrics",
111
112
  },
112
- 'beta:pending-provider-pacts' =>
113
+ 'pb:can-i-deploy-pacticipant-version-to-tag' =>
113
114
  {
114
- href: base_url + '/pacts/provider/{provider}/pending',
115
- title: 'Pending pact versions for the specified provider',
115
+ href: base_url + '/can-i-deploy?pacticipant={pacticipant}&version={version}&to={tag}',
116
+ title: "Determine if an application can be safely deployed to an environment identified by the given tag",
116
117
  templated: true
117
118
  },
118
119
  'curies' =>
@@ -126,6 +127,16 @@ module PactBroker
126
127
  templated: true
127
128
  }]
128
129
  }
130
+
131
+ if PactBroker.feature_enabled?(:pacts_for_verification)
132
+ links_hash['beta:provider-pacts-for-verification'] = {
133
+ href: base_url + '/pacts/provider/{provider}/for-verification',
134
+ title: 'Pact versions to be verified for the specified provider',
135
+ templated: true
136
+ }
137
+ end
138
+
139
+ links_hash
129
140
  end
130
141
  end
131
142
  end
@@ -1,16 +1,18 @@
1
1
  require 'pact_broker/api/resources/base_resource'
2
2
  require 'pact_broker/configuration'
3
+ require 'pact_broker/api/decorators/extended_pact_decorator'
3
4
 
4
5
  module PactBroker
5
6
  module Api
6
7
  module Resources
7
-
8
8
  class LatestPact < BaseResource
9
-
10
9
  def content_types_provided
11
- [ ["application/hal+json", :to_json],
10
+ [
11
+ ["application/hal+json", :to_json],
12
12
  ["application/json", :to_json],
13
- ["text/html", :to_html]]
13
+ ["text/html", :to_html],
14
+ ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
15
+ ]
14
16
  end
15
17
 
16
18
  def allowed_methods
@@ -26,6 +28,10 @@ module PactBroker
26
28
  PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: { base_url: base_url })
27
29
  end
28
30
 
31
+ def to_extended_json
32
+ PactBroker::Api::Decorators::ExtendedPactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
33
+ end
34
+
29
35
  def to_html
30
36
  PactBroker.configuration.html_pact_renderer.call(
31
37
  pact, {
@@ -0,0 +1,19 @@
1
+ require 'pact_broker/api/resources/verification'
2
+
3
+ module PactBroker
4
+ module Api
5
+ module Resources
6
+ class LatestVerificationForLatestPact < Verification
7
+ private
8
+
9
+ def pact
10
+ @pact ||= pact_service.find_latest_pact(pact_params)
11
+ end
12
+
13
+ def verification
14
+ @verification ||= pact && verification_service.find_latest_for_pact(pact)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -25,10 +25,11 @@ module PactBroker
25
25
  include WebhookExecutionMethods
26
26
 
27
27
  def content_types_provided
28
- [["application/hal+json", :to_json],
29
- ["application/json", :to_json],
30
- ["text/html", :to_html],
31
- ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
28
+ [
29
+ ["application/hal+json", :to_json],
30
+ ["application/json", :to_json],
31
+ ["text/html", :to_html],
32
+ ["application/vnd.pactbrokerextended.v1+json", :to_extended_json]
32
33
  ]
33
34
  end
34
35
 
@@ -0,0 +1,54 @@
1
+ require 'pact_broker/api/resources/provider_pacts'
2
+ require 'pact_broker/api/decorators/verifiable_pacts_decorator'
3
+ require 'pact_broker/api/contracts/verifiable_pacts_query_schema'
4
+ require 'pact_broker/api/decorators/verifiable_pacts_query_decorator'
5
+
6
+ module PactBroker
7
+ module Api
8
+ module Resources
9
+ class ProviderPactsForVerification < ProviderPacts
10
+ def initialize
11
+ @query = Rack::Utils.parse_nested_query(request.uri.query)
12
+ end
13
+
14
+ def malformed_request?
15
+ if (errors = query_schema.call(query)).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
26
+
27
+ def pacts
28
+ pact_service.find_for_verification(
29
+ provider_name,
30
+ parsed_query_params.provider_version_tags,
31
+ parsed_query_params.consumer_version_selectors
32
+ )
33
+ end
34
+
35
+ def resource_title
36
+ "Pacts to be verified by provider #{provider_name}"
37
+ end
38
+
39
+ def to_json
40
+ PactBroker::Api::Decorators::VerifiablePactsDecorator.new(pacts).to_json(to_json_options)
41
+ end
42
+
43
+
44
+ def query_schema
45
+ PactBroker::Api::Contracts::VerifiablePactsQuerySchema
46
+ end
47
+
48
+ def parsed_query_params
49
+ @parsed_query_params ||= PactBroker::Api::Decorators::VerifiablePactsQueryDecorator.new(OpenStruct.new).from_hash(query)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -24,7 +24,12 @@ module PactBroker
24
24
  end
25
25
 
26
26
  def resource_exists?
27
- !!verification
27
+ if identifier_from_path[:verification_number] == "all"
28
+ set_json_error_message("To see all the verifications for a pact, use the Matrix page")
29
+ false
30
+ else
31
+ !!verification
32
+ end
28
33
  end
29
34
 
30
35
  def to_json
@@ -15,14 +15,14 @@ module PactBroker
15
15
  SPACE_DASH_UNDERSCORE = /[\s_\-]/
16
16
  CACHE = {}
17
17
 
18
- def pact_verification_badge pact, label, initials, verification_status
19
- return static_svg(pact, verification_status) unless pact
18
+ def pact_verification_badge pact, label, initials, pseudo_branch_verification_status
19
+ return static_svg(pact, pseudo_branch_verification_status) unless pact
20
20
 
21
21
  title = badge_title pact, label, initials
22
- status = badge_status verification_status
23
- color = badge_color verification_status
22
+ status = badge_status pseudo_branch_verification_status
23
+ color = badge_color pseudo_branch_verification_status
24
24
 
25
- dynamic_svg(title, status, color) || static_svg(pact, verification_status)
25
+ dynamic_svg(title, status, color) || static_svg(pact, pseudo_branch_verification_status)
26
26
  end
27
27
 
28
28
  def clear_cache
@@ -60,8 +60,8 @@ module PactBroker
60
60
  .split('_')
61
61
  end
62
62
 
63
- def badge_status verification_status
64
- case verification_status
63
+ def badge_status pseudo_branch_verification_status
64
+ case pseudo_branch_verification_status
65
65
  when :success then "verified"
66
66
  when :failed then "failed"
67
67
  when :stale then "changed"
@@ -69,8 +69,8 @@ module PactBroker
69
69
  end
70
70
  end
71
71
 
72
- def badge_color verification_status
73
- case verification_status
72
+ def badge_color pseudo_branch_verification_status
73
+ case pseudo_branch_verification_status
74
74
  when :success then "brightgreen"
75
75
  when :failed then "red"
76
76
  when :stale then "orange"
@@ -122,8 +122,8 @@ module PactBroker
122
122
  response
123
123
  end
124
124
 
125
- def static_svg pact, verification_status
126
- file_name = case verification_status
125
+ def static_svg pact, pseudo_branch_verification_status
126
+ file_name = case pseudo_branch_verification_status
127
127
  when :success then "pact-verified-brightgreen.svg"
128
128
  when :failed then "pact-failed-red.svg"
129
129
  when :stale then "pact-changed-orange.svg"
@@ -14,31 +14,91 @@ module PactBroker
14
14
  end
15
15
 
16
16
  def call
17
- db[:verifications].where(id: db[:head_matrix].select(:verification_id)).invert.delete
18
- pp_ids = db[:head_matrix].select(:pact_publication_id)
17
+ deleted_counts = {}
18
+ kept_counts = {}
19
+ date = options[:date]
20
+ pact_publication_ids_to_delete = if date
21
+ db[:pact_publications].select(:id).where(Sequel.lit('created_at < ?', date))
22
+ else
23
+ db[:pact_publications].select(:id).where(id: db[:head_matrix].select(:pact_publication_id)).invert
24
+ end
19
25
 
20
- triggered_webhook_ids = db[:triggered_webhooks].where(pact_publication_id: pp_ids).invert.select(:id)
26
+ deleted_counts[:pact_publications] = pact_publication_ids_to_delete.count
27
+ kept_counts[:pact_publications] = db[:pact_publications].where(id: pact_publication_ids_to_delete).invert.count
28
+
29
+ # TODO head matrix is the head for the consumer tags, not the provider tags.
30
+ # Work out how to keep the head verifications for the provider tags.
31
+ verification_ids = get_verification_ids(pact_publication_ids_to_delete)
32
+ deleted_counts[:verification_results] = verification_ids.count
33
+ kept_counts[:verification_results] = db[:verifications].where(id:verification_ids ).invert.count
34
+
35
+ delete_webhook_data(db[:triggered_webhooks].where(verification_id: verification_ids).select(:id))
36
+ verification_ids.delete
37
+
38
+ delete_webhook_data(db[:triggered_webhooks].where(pact_publication_id: pact_publication_ids_to_delete).select(:id))
39
+ delete_deprecated_webhook_executions(pact_publication_ids_to_delete)
40
+ delete_pact_publications(pact_publication_ids_to_delete)
41
+
42
+ delete_orphan_pact_versions
43
+ overwritten_delete_counts = delete_overwritten_verifications
44
+ deleted_counts[:verification_results] = deleted_counts[:verification_results] + overwritten_delete_counts[:verification_results]
45
+ kept_counts[:verification_results] = kept_counts[:verification_results] - overwritten_delete_counts[:verification_results]
46
+
47
+
48
+ referenced_version_ids = db[:pact_publications].select(:consumer_version_id).collect{ | h| h[:consumer_version_id] } +
49
+ db[:verifications].select(:provider_version_id).collect{ | h| h[:provider_version_id] }
50
+
51
+ delete_orphan_tags(referenced_version_ids)
52
+ delete_orphan_versions(referenced_version_ids)
53
+
54
+ { kept: kept_counts, deleted: deleted_counts }
55
+ end
56
+
57
+ private
58
+
59
+ attr_reader :db, :options
60
+
61
+ def get_verification_ids(pact_publication_ids)
62
+ db[:verifications].select(:id).where(pact_version_id: db[:pact_publications].select(:pact_version_id).where(id: pact_publication_ids))
63
+ end
64
+
65
+ def delete_webhook_data(triggered_webhook_ids)
21
66
  db[:webhook_executions].where(triggered_webhook_id: triggered_webhook_ids).delete
22
67
  db[:triggered_webhooks].where(id: triggered_webhook_ids).delete
23
- db[:webhook_executions].where(pact_publication_id: pp_ids).invert.delete
24
68
 
25
- db[:pact_publications].where(id: pp_ids).invert.delete
69
+ end
70
+
71
+ def delete_deprecated_webhook_executions(pact_publication_ids)
72
+ db[:webhook_executions].where(pact_publication_id: pact_publication_ids).delete
73
+ end
74
+
75
+ def delete_pact_publications(pact_publication_ids)
76
+ db[:pact_publications].where(id: pact_publication_ids).delete
77
+ db[:pact_versions].where(id: db[:pact_publications].select(:pact_version_id)).invert.delete
78
+ end
26
79
 
80
+ def delete_orphan_pact_versions
81
+ # TODO use union
27
82
  referenced_pact_version_ids = db[:pact_publications].select(:pact_version_id).collect{ | h| h[:pact_version_id] } +
28
83
  db[:verifications].select(:pact_version_id).collect{ | h| h[:pact_version_id] }
29
84
  db[:pact_versions].where(id: referenced_pact_version_ids).invert.delete
85
+ end
30
86
 
31
- referenced_version_ids = db[:pact_publications].select(:consumer_version_id).collect{ | h| h[:consumer_version_id] } +
32
- db[:verifications].select(:provider_version_id).collect{ | h| h[:provider_version_id] }
33
-
87
+ def delete_orphan_tags(referenced_version_ids)
34
88
  db[:tags].where(version_id: referenced_version_ids).invert.delete
35
- db[:versions].where(id: referenced_version_ids).invert.delete
36
89
  end
37
90
 
38
- private
39
-
40
- attr_reader :db
91
+ def delete_orphan_versions(referenced_version_ids)
92
+ db[:versions].where(id: referenced_version_ids).invert.delete
93
+ end
41
94
 
95
+ def delete_overwritten_verifications
96
+ verification_ids = db[:verifications].select(:id).where(id: db[:latest_verification_id_for_pact_version_and_provider_version].select(:verification_id)).invert
97
+ deleted_counts = { verification_results: verification_ids.count }
98
+ delete_webhook_data(db[:triggered_webhooks].where(verification_id: verification_ids).select(:id))
99
+ verification_ids.delete
100
+ deleted_counts
101
+ end
42
102
  end
43
103
  end
44
104
  end
@@ -13,7 +13,9 @@ module PactBroker
13
13
 
14
14
  MAPPINGS = {
15
15
  'webhooks-create' => 'webhooks',
16
- 'webhooks-webhooks' => 'webhooks'
16
+ 'webhooks-webhooks' => 'webhooks',
17
+ 'can-i-deploy-pacticipant-version-to-tag' => 'can-i-deploy',
18
+ 'pacticipant' => 'pacticipants'
17
19
  }.freeze
18
20
 
19
21
  helpers do
@@ -0,0 +1,14 @@
1
+ # Can I Deploy
2
+
3
+ Allowed methods: `GET`
4
+
5
+ A simplified resource that accepts the same parameters as the basic usage of the `can-i-deploy` CLI command.
6
+
7
+ **Parameters**:
8
+
9
+ * _pacticipant_: The name of the pacticipant (application) you want to deploy (required).
10
+ * _version_: The version of the pacticipant (application) you want to deploy (required).
11
+ * _to_: The tag used to identify the environment into which you wish to deploy the application (eg. `test` or `prod`). This assumes you have already tagged the currently deployed versions of each of the integrated applications with the same tag. To be specific, the logic checks if the application version you have specified is compatible with the latest versions _for the specified tag_ of all the other applications it is integrated with. This parameter is optional - if not specified, it checks for compatiblity with the latest version of all the integrated applications.
12
+
13
+
14
+ If you have an environment that you identify with the tag `prod`, and each time you deployed an application to the prod environment you tagged the relevant application version in the Pact Broker with the tag `prod`, then calling `/can-i-deploy?pacticipant=Foo&version=734137278d&to=prod` will check that version 734137278d of Foo has a successful verification result with each of the integrated application versions that are currently in prod. That is, it is safe to deploy.
@@ -0,0 +1,8 @@
1
+ # Pacticipant version tag
2
+
3
+ Allowed methods: `GET`, `PUT`, `DELETE`
4
+ Path: `/pacticipants/{pacticipant}/versions/{version}/tags/{tag}`
5
+
6
+ To create a tag, send an empty request with the URL specified above and `Content-Type` of `application/json`.
7
+
8
+ Tags must be applied before pacts or verification results are published to ensure that the webhook fires with the correct metadata.
@@ -2,6 +2,6 @@
2
2
 
3
3
  Allowed methods: `GET`
4
4
 
5
- Content types: `text/vnd.graphviz`
5
+ Content types: `text/vnd.graphviz`, `application/hal+json`
6
6
 
7
7
  A list of all the integrations (consumer/provider pairs) stored in the Pact Broker.
@@ -0,0 +1,7 @@
1
+ # Matrix
2
+
3
+ Allowed methods: `GET`
4
+
5
+ This resource returns the "cartesian join" of every pact publication and every verification results publication, and is used to determine whether or not an application is safe to deploy.
6
+
7
+ If you need to use this API, consider calling the `/can-i-deploy` resource instead.
@@ -0,0 +1,5 @@
1
+ # Metrics
2
+
3
+ Allowed methods: `GET`
4
+
5
+ Returns counts for the Pact Broker resources.
@@ -1,4 +1,4 @@
1
- require 'pact_broker/verifications/verification_status'
1
+ require 'pact_broker/verifications/pseudo_branch_status'
2
2
  require 'pact_broker/webhooks/status'
3
3
 
4
4
  module PactBroker
@@ -85,8 +85,8 @@ module PactBroker
85
85
  @last_webhook_execution_date ||= @triggered_webhooks.any? ? @triggered_webhooks.sort{|a, b| a.created_at <=> b.created_at }.last.created_at : nil
86
86
  end
87
87
 
88
- def verification_status
89
- @verification_status ||= PactBroker::Verifications::Status.new(@latest_pact, @latest_verification).to_sym
88
+ def pseudo_branch_verification_status
89
+ @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(@latest_pact, @latest_verification).to_sym
90
90
  end
91
91
 
92
92
  def ever_verified?
@@ -1,13 +1,17 @@
1
1
  require 'pact_broker/db'
2
2
  require 'pact_broker/json'
3
3
 
4
+ =begin
5
+ This class most accurately represents a PactPublication
6
+ =end
7
+
4
8
  module PactBroker
5
9
 
6
10
  module Domain
7
11
  class Pact
8
12
 
13
+ # The ID is the pact_publication ID
9
14
  attr_accessor :id, :provider, :consumer_version, :consumer, :created_at, :json_content, :consumer_version_number, :revision_number, :pact_version_sha, :latest_verification, :head_tag_names
10
-
11
15
  def initialize attributes
12
16
  attributes.each_pair do | key, value |
13
17
  self.send(key.to_s + "=", value)
@@ -30,6 +34,10 @@ module PactBroker
30
34
  consumer_version.tags.collect(&:name)
31
35
  end
32
36
 
37
+ def latest_consumer_version_tag_names= latest_consumer_version_tag_names
38
+ @latest_consumer_version_tag_names = latest_consumer_version_tag_names
39
+ end
40
+
33
41
  def to_s
34
42
  "Pact: consumer=#{consumer.name} provider=#{provider.name}"
35
43
  end
@@ -53,6 +61,25 @@ module PactBroker
53
61
  def pact_publication_id
54
62
  id
55
63
  end
64
+
65
+ def select_pending_provider_version_tags(provider_version_tags)
66
+ provider_version_tags - db_model.pact_version.select_provider_tags_with_successful_verifications(provider_version_tags)
67
+ end
68
+
69
+ def pending?
70
+ !pact_version.verified_successfully_by_any_provider_version?
71
+ end
72
+
73
+ private
74
+
75
+ attr_accessor :db_model
76
+
77
+ # Really not sure about mixing Sequel model class into this PORO...
78
+ # But it's much nicer than using a repository to find out the pending information :(
79
+ def pact_version
80
+ db_model.pact_version
81
+ end
56
82
  end
83
+
57
84
  end
58
85
  end