Module: PactBroker::Pacts::Service
Constant Summary
Repositories::REPOSITORY_FACTORIES
Constants included
from Services
Services::SERVICE_FACTORIES
Instance Method Summary
collapse
-
#contract_published_event_comment(pact) ⇒ Object
-
#create_or_update_pact(params) ⇒ Object
-
#delete(params) ⇒ Object
-
#delete_all_pact_publications_between(consumer, options) ⇒ Object
-
#delete_all_pact_versions_between(consumer, options) ⇒ Object
-
#disallowed_modification?(existing_pact, new_pact_version_sha) ⇒ Boolean
-
#find_all_pact_versions_between(consumer, options) ⇒ Object
-
#find_by_consumer_version(params) ⇒ Object
-
#find_distinct_pacts_between(consumer, options) ⇒ Object
-
#find_for_verification(provider_name, provider_version_branch, provider_version_tags, consumer_version_selectors, options) ⇒ Object
-
#find_for_verification_publication(pact_params, consumer_version_selector_hashes) ⇒ Object
-
#find_latest_pact(params) ⇒ Object
-
#find_latest_pacts ⇒ Object
-
#find_latest_pacts_for_provider(provider_name, options = {}) ⇒ Object
-
#find_pact(params) ⇒ Object
-
#find_pact_versions_for_provider(provider_name, options = {}) ⇒ Object
-
#find_previous_distinct_pact_version(params) ⇒ Object
-
#generate_sha(json_content) ⇒ Object
-
#merge_pact(params) ⇒ Object
-
#search_for_latest_pact(params) ⇒ Object
branch_repository, branch_version_repository, get_repository, integration_repository, label_repository, matrix_repository, pact_repository, pacticipant_repository, register_default_repositories, register_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, branch_service, certificate_service, contract_service, deployed_version_service, environment_service, get_service, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, register_default_services, register_service, released_version_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service
Methods included from Messages
message, pluralize, validation_message, validation_message_at_index
call, squash_pacts_for_verification
Methods included from Logging
included, #log_error, #log_with_tag, #measure_info
Instance Method Details
265
266
267
268
269
270
271
|
# File 'lib/pact_broker/pacts/service.rb', line 265
def pact
if pact.consumer_version_tag_names.count == 1
message("messages.events.pact_published_unchanged_with_single_tag", tag_name: pact.consumer_version_tag_names.first)
else
message("messages.events.pact_published_unchanged_with_multiple_tags", tag_names: pact.consumer_version_tag_names.join(", "))
end
end
|
#create_or_update_pact(params) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/pact_broker/pacts/service.rb', line 56
def create_or_update_pact params
provider = pacticipant_repository.find_by_name_or_create params[:provider_name]
consumer = pacticipant_repository.find_by_name_or_create params[:consumer_name]
consumer_version = version_repository.find_by_pacticipant_id_and_number_or_create consumer.id, params[:consumer_version_number]
existing_pact = pact_repository.find_by_version_and_provider(consumer_version.id, provider.id)
if existing_pact
create_pact_revision params, existing_pact
else
create_pact params, consumer_version, provider
end
end
|
#delete(params) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/pact_broker/pacts/service.rb', line 49
def delete params
logger.info("Deleting pact version", params)
pacts = pact_repository.find_all_revisions(params[:consumer_name], params[:consumer_version_number], params[:provider_name])
webhook_service.delete_all_webhook_related_objects_by_pact_publication_ids(pacts.collect(&:id))
pact_repository.delete(params)
end
|
#delete_all_pact_publications_between(consumer, options) ⇒ Object
86
87
88
|
# File 'lib/pact_broker/pacts/service.rb', line 86
def delete_all_pact_publications_between consumer, options
pact_repository.delete_all_pact_publications_between consumer, options
end
|
#delete_all_pact_versions_between(consumer, options) ⇒ Object
90
91
92
|
# File 'lib/pact_broker/pacts/service.rb', line 90
def delete_all_pact_versions_between consumer, options
pact_repository.delete_all_pact_versions_between consumer, options
end
|
#disallowed_modification?(existing_pact, new_pact_version_sha) ⇒ Boolean
187
188
189
|
# File 'lib/pact_broker/pacts/service.rb', line 187
def disallowed_modification?(existing_pact, new_pact_version_sha)
!PactBroker.configuration.allow_dangerous_contract_modification && existing_pact && existing_pact.pact_version_sha != new_pact_version_sha
end
|
#find_all_pact_versions_between(consumer, options) ⇒ Object
82
83
84
|
# File 'lib/pact_broker/pacts/service.rb', line 82
def find_all_pact_versions_between consumer, options
pact_repository.find_all_pact_versions_between consumer, options
end
|
#find_by_consumer_version(params) ⇒ Object
45
46
47
|
# File 'lib/pact_broker/pacts/service.rb', line 45
def find_by_consumer_version params
pact_repository.find_by_consumer_version(params[:consumer_name], params[:consumer_version_number])
end
|
#find_distinct_pacts_between(consumer, options) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/pact_broker/pacts/service.rb', line 108
def find_distinct_pacts_between consumer, options
all = pact_repository.find_all_pact_versions_between consumer, options
distinct = []
(0...all.size).each do | i |
if i == all.size - 1
distinct << all[i]
else
if all[i].json_content != all[i+1].json_content
distinct << all[i]
end
end
end
distinct
end
|
#find_for_verification(provider_name, provider_version_branch, provider_version_tags, consumer_version_selectors, options) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/pact_broker/pacts/service.rb', line 124
def find_for_verification(provider_name, provider_version_branch, provider_version_tags, consumer_version_selectors, options)
explicitly_specified_verifiable_pacts = pact_repository
.find_for_verification(provider_name, consumer_version_selectors)
.collect do | selected_pact |
squash_pacts_for_verification(provider_version_tags, provider_version_branch, selected_pact, options[:include_pending_status])
end
verifiable_wip_pacts = if options[:include_wip_pacts_since]
pact_repository.find_wip_pact_versions_for_provider(provider_name, provider_version_branch, provider_version_tags, explicitly_specified_verifiable_pacts, options)
else
[]
end
explicitly_specified_verifiable_pacts + verifiable_wip_pacts
end
|
#find_for_verification_publication(pact_params, consumer_version_selector_hashes) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/pact_broker/pacts/service.rb', line 141
def find_for_verification_publication(pact_params, consumer_version_selector_hashes)
if consumer_version_selector_hashes&.any?
selected_pacts = consumer_version_selector_hashes.collect do | consumer_version_selector_hash |
find_pact_params = {
consumer_name: pact_params.consumer_name,
provider_name: pact_params.provider_name,
pact_version_sha: pact_params.pact_version_sha,
consumer_version_number: consumer_version_selector_hash[:consumer_version_number]
}
pact = find_pact(find_pact_params)
resolved_selector = Selector.new(consumer_version_selector_hash.without(:consumer_version_number)).resolve(pact.consumer_version)
SelectedPact.new(pact, Selectors.new(resolved_selector))
end
SelectedPact.merge_by_consumer_version_number(selected_pacts)
else
[SelectedPact.new(find_pact(pact_params), Selectors.new)]
end
end
|
#find_latest_pact(params) ⇒ Object
29
30
31
|
# File 'lib/pact_broker/pacts/service.rb', line 29
def find_latest_pact params
pact_repository.find_latest_pact(params[:consumer_name], params[:provider_name], params[:tag], params[:branch_name])
end
|
#find_latest_pacts ⇒ Object
37
38
39
|
# File 'lib/pact_broker/pacts/service.rb', line 37
def find_latest_pacts
pact_repository.find_latest_pacts
end
|
#find_latest_pacts_for_provider(provider_name, options = {}) ⇒ Object
94
95
96
|
# File 'lib/pact_broker/pacts/service.rb', line 94
def find_latest_pacts_for_provider provider_name, options = {}
pact_repository.find_latest_pacts_for_provider provider_name, options[:tag]
end
|
#find_pact(params) ⇒ Object
41
42
43
|
# File 'lib/pact_broker/pacts/service.rb', line 41
def find_pact params
pact_repository.find_pact(params[:consumer_name], params[:consumer_version_number], params[:provider_name], params[:pact_version_sha])
end
|
#find_pact_versions_for_provider(provider_name, options = {}) ⇒ Object
98
99
100
|
# File 'lib/pact_broker/pacts/service.rb', line 98
def find_pact_versions_for_provider provider_name, options = {}
pact_repository.find_pact_versions_for_provider provider_name, options[:tag]
end
|
#find_previous_distinct_pact_version(params) ⇒ Object
102
103
104
105
106
|
# File 'lib/pact_broker/pacts/service.rb', line 102
def find_previous_distinct_pact_version params
pact = find_pact params
return nil if pact.nil?
pact_repository.find_previous_distinct_pact pact
end
|
#generate_sha(json_content) ⇒ Object
25
26
27
|
# File 'lib/pact_broker/pacts/service.rb', line 25
def generate_sha(json_content)
PactBroker.configuration.sha_generator.call(json_content)
end
|
#merge_pact(params) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pact_broker/pacts/service.rb', line 69
def merge_pact params
provider = pacticipant_repository.find_by_name_or_create params[:provider_name]
consumer = pacticipant_repository.find_by_name_or_create params[:consumer_name]
consumer_version = version_repository.find_by_pacticipant_id_and_number_or_create consumer.id, params[:consumer_version_number]
existing_pact = pact_repository.find_by_version_and_provider(consumer_version.id, provider.id)
params[:json_content] = Merger.merge_pacts(
existing_pact.json_content, params[:json_content]
)
create_pact_revision params, existing_pact
end
|
#search_for_latest_pact(params) ⇒ Object
33
34
35
|
# File 'lib/pact_broker/pacts/service.rb', line 33
def search_for_latest_pact params
pact_repository.search_for_latest_pact(params[:consumer_name], params[:provider_name], params[:tag])
end
|