Class: PactBroker::Index::Service
Constant Summary
collapse
- COLS =
[:id, :consumer_name, :provider_name, :consumer_version_order]
- LATEST_PPS =
Sequel::Model.db[:latest_pact_publications].select(*COLS)
- LATEST_TAGGED_PPS =
Sequel::Model.db[:latest_tagged_pact_publications].select(*COLS)
- HEAD_PP_ORDER_COLUMNS =
[
Sequel.asc(Sequel.function(:lower, :consumer_name)),
Sequel.desc(:consumer_version_order),
Sequel.asc(Sequel.function(:lower, :provider_name))
].freeze
- DEFAULT_PAGE_SIZE =
30
- DEFAULT_PAGE_NUMBER =
1
Class Method Summary
collapse
label_repository, matrix_repository, pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, certificate_service, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service
Methods included from Logging
included, log_error
Class Method Details
99
100
101
102
103
104
105
106
107
|
# File 'lib/pact_broker/index/service.rb', line 99
def self.consumer_version_tags(pact_publication, tags_option)
if tags_option == true
pact_publication.head_pact_tags.collect(&:name)
elsif tags_option.is_a?(Array)
pact_publication.head_pact_tags.collect(&:name) & tags_option
else
[]
end
end
|
.find_all_index_items ⇒ Object
35
36
37
38
39
|
# File 'lib/pact_broker/index/service.rb', line 35
def self.find_all_index_items
find_index_items(page_number: 1, page_size: 100000000000)
end
|
.find_index_items(options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/pact_broker/index/service.rb', line 41
def self.find_index_items options = {}
latest_verifications_for_cv_tags = latest_verifications_for_consumer_version_tags(options)
latest_pact_publication_ids = latest_pact_publications.select(:id).all.collect{ |h| h[:id] }
webhooks = PactBroker::Webhooks::Webhook.select(:consumer_id, :provider_id).distinct.all
pact_publication_ids = head_pact_publication_ids(options)
= pact_publication_ids.
pact_publications = pact_publication_scope
.where(id: pact_publication_ids)
.select_all_qualified
.eager(:consumer)
.eager(:provider)
.eager(:pact_version)
.eager(integration: [{latest_verification: :provider_version}, :latest_triggered_webhooks])
.eager(:consumer_version)
.eager(latest_verification: { provider_version: :tags_with_latest_flag })
.eager(:head_pact_tags)
index_items = pact_publications.all.collect do | pact_publication |
is_overall_latest_for_integration = latest_pact_publication_ids.include?(pact_publication.id)
latest_verification = latest_verification_for_pseudo_branch(pact_publication, is_overall_latest_for_integration, latest_verifications_for_cv_tags, options[:tags])
webhook = webhooks.find{ |webhook| webhook.is_for?(pact_publication.integration) }
PactBroker::Domain::IndexItem.create(
pact_publication.consumer,
pact_publication.provider,
pact_publication.to_domain_lightweight,
is_overall_latest_for_integration,
latest_verification,
webhook ? [webhook]: [],
pact_publication.integration.latest_triggered_webhooks,
consumer_version_tags(pact_publication, options[:tags]),
options[:tags] && latest_verification ? latest_verification.provider_version.tags_with_latest_flag.select(&:latest?) : []
)
end.sort
Page.new(index_items, )
end
|
.find_index_items_for_api(consumer_name: nil, provider_name: nil, **ignored) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/pact_broker/index/service.rb', line 109
def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, **ignored)
latest_pact_publication_ids = latest_pact_publications.select(:id).all.collect{ |h| h[:id] }
pact_publication_ids = head_pact_publication_ids(consumer_name: consumer_name, provider_name: provider_name, tags: true)
pact_publications = pact_publication_scope
.where(id: pact_publication_ids)
.select_all_qualified
.eager(:consumer)
.eager(:provider)
.eager(:pact_version)
.eager(:consumer_version)
.eager(latest_verification: { provider_version: :tags_with_latest_flag })
.eager(:head_pact_tags)
pact_publications.all.collect do | pact_publication |
is_overall_latest_for_integration = latest_pact_publication_ids.include?(pact_publication.id)
PactBroker::Domain::IndexItem.create(
pact_publication.consumer,
pact_publication.provider,
pact_publication.to_domain_lightweight,
is_overall_latest_for_integration,
pact_publication.latest_verification,
[],
[],
pact_publication.head_pact_tags.collect(&:name),
pact_publication.latest_verification ? pact_publication.latest_verification.provider_version.tags_with_latest_flag.select(&:latest?) : []
)
end.sort
end
|
.head_pact_publication_ids(options = {}) ⇒ Object
.latest_pact_publications ⇒ Object
142
143
144
|
# File 'lib/pact_broker/index/service.rb', line 142
def self.latest_pact_publications
db[:latest_pact_publications]
end
|
.latest_verification_for_pseudo_branch(pact_publication, is_overall_latest, latest_verifications_for_cv_tags, tags_option) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/pact_broker/index/service.rb', line 85
def self.latest_verification_for_pseudo_branch(pact_publication, is_overall_latest, latest_verifications_for_cv_tags, tags_option)
if tags_option == true
latest_verifications_for_cv_tags
.select{ | v | v.consumer_id == pact_publication.consumer_id && v.provider_id == pact_publication.provider_id && pact_publication.head_pact_tags.collect(&:name).include?(v.consumer_version_tag_name) }
.sort{ |v1, v2| v1.id <=> v2.id }.last || (is_overall_latest && pact_publication.integration.latest_verification)
elsif tags_option.is_a?(Array)
latest_verifications_for_cv_tags
.select{ | v | v.consumer_id == pact_publication.consumer_id && v.provider_id == pact_publication.provider_id && pact_publication.head_pact_tags.collect(&:name).include?(v.consumer_version_tag_name) && tags_option.include?(v.consumer_version_tag_name) }
.sort{ |v1, v2| v1.id <=> v2.id }.last || (is_overall_latest && pact_publication.integration.latest_verification)
else
pact_publication.integration.latest_verification
end
end
|
.pact_publication_scope ⇒ Object
This method provides data for both the OSS server side rendered index (with and without tags) and the Pactflow UI. It really needs to be broken into to separate methods, as it’s getting too messy supporting both