pact_broker 2.83.0 → 2.84.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Dockerfile +1 -1
- data/db/migrations/20210816_create_branches_tables.rb +40 -0
- data/db/migrations/20210831_add_index_to_pact_publications.rb +7 -0
- data/db/migrations/20210908_add_auto_created.rb +24 -0
- data/issue-reproduction/Dockerfile-pact-broker +1 -1
- data/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema.rb → pacts_for_verification_json_query_schema.rb} +1 -1
- data/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema.rb → pacts_for_verification_query_string_schema.rb} +1 -1
- data/lib/pact_broker/api/decorators/branch_version_decorator.rb +20 -0
- data/lib/pact_broker/api/decorators/dashboard_decorator.rb +4 -2
- data/lib/pact_broker/api/decorators/embedded_branch_version_decorator.rb +21 -0
- data/lib/pact_broker/api/decorators/embedded_tag_decorator.rb +0 -5
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +11 -2
- data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +8 -0
- data/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator.rb → pacts_for_verification_query_decorator.rb} +2 -2
- data/lib/pact_broker/api/decorators/version_decorator.rb +1 -1
- data/lib/pact_broker/api/pact_broker_urls.rb +8 -0
- data/lib/pact_broker/api/resources/branch_version.rb +48 -0
- data/lib/pact_broker/api/resources/index.rb +6 -0
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +6 -6
- data/lib/pact_broker/api/resources/version.rb +0 -8
- data/lib/pact_broker/api.rb +1 -0
- data/lib/pact_broker/config/runtime_configuration.rb +12 -0
- data/lib/pact_broker/contracts/service.rb +1 -1
- data/lib/pact_broker/db/data_migrations/create_branches.rb +97 -0
- data/lib/pact_broker/db/data_migrations/set_pacticipant_main_branch.rb +2 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -1
- data/lib/pact_broker/db/models.rb +6 -0
- data/lib/pact_broker/deployments/deployed_version.rb +4 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +4 -3
- data/lib/pact_broker/deployments/environment.rb +4 -0
- data/lib/pact_broker/deployments/environment_service.rb +13 -8
- data/lib/pact_broker/doc/views/index/pacticipant-branch-version.markdown +14 -0
- data/lib/pact_broker/doc/views/webhooks.markdown +1 -0
- data/lib/pact_broker/domain/index_item.rb +15 -17
- data/lib/pact_broker/domain/pacticipant.rb +11 -0
- data/lib/pact_broker/domain/tag.rb +1 -2
- data/lib/pact_broker/domain/verification.rb +16 -13
- data/lib/pact_broker/domain/version.rb +87 -33
- data/lib/pact_broker/index/service.rb +8 -4
- data/lib/pact_broker/locale/en.yml +1 -0
- data/lib/pact_broker/matrix/quick_row.rb +6 -6
- data/lib/pact_broker/metrics/service.rb +7 -1
- data/lib/pact_broker/pacts/pact_publication.rb +22 -25
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +74 -33
- data/lib/pact_broker/pacts/pact_publication_selector_dataset_module.rb +18 -13
- data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +16 -4
- data/lib/pact_broker/pacts/pact_version.rb +11 -0
- data/lib/pact_broker/pacts/pacts_for_verification_repository.rb +3 -3
- data/lib/pact_broker/pacts/selected_pact.rb +2 -2
- data/lib/pact_broker/pacts/selector.rb +98 -33
- data/lib/pact_broker/repositories.rb +5 -0
- data/lib/pact_broker/services.rb +9 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +32 -7
- data/lib/pact_broker/test/test_data_builder.rb +25 -24
- data/lib/pact_broker/ui/view_models/index_item.rb +11 -0
- data/lib/pact_broker/ui/view_models/matrix_branch.rb +39 -0
- data/lib/pact_broker/ui/view_models/matrix_line.rb +11 -16
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +12 -11
- data/lib/pact_broker/ui/views/matrix/show.haml +8 -8
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/branch.rb +29 -0
- data/lib/pact_broker/versions/branch_head.rb +45 -0
- data/lib/pact_broker/versions/branch_service.rb +24 -0
- data/lib/pact_broker/versions/branch_version.rb +64 -0
- data/lib/pact_broker/versions/branch_version_repository.rb +34 -0
- data/lib/pact_broker/versions/eager_loaders.rb +0 -42
- data/lib/pact_broker/versions/repository.rb +25 -12
- data/lib/pact_broker/versions/service.rb +3 -22
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +11 -2
- data/lib/sequel/plugins/insert_ignore.rb +4 -0
- data/lib/sequel/plugins/upsert.rb +4 -0
- data/public/javascripts/index.js +129 -34
- data/scaffolding/templates/decorator.rb.erb +3 -1
- data/scaffolding/templates/migration.erb +1 -1
- data/scaffolding/templates/model.erb +2 -2
- data/scaffolding/templates/repository.rb.erb +2 -2
- data/scaffolding/templates/repository_spec.rb.erb +1 -1
- data/scaffolding/templates/resource.erb +2 -2
- data/scaffolding/templates/resource_spec.rb.erb +1 -1
- data/scaffolding/templates/service.rb.erb +3 -3
- data/scaffolding/templates/service_spec.rb.erb +1 -1
- data/script/data/branches.rb +35 -0
- data/script/data/issue-494.rb +25 -0
- data/spec/features/create_branch_version_spec.rb +29 -0
- data/spec/features/create_tag_spec.rb +1 -1
- data/spec/features/create_version_spec.rb +2 -4
- data/spec/features/get_branch_version_spec.rb +12 -0
- data/spec/features/publish_pact_all_in_one_spec.rb +0 -1
- data/spec/features/update_version_spec.rb +0 -55
- data/spec/fixtures/approvals/modifiable_resources.approved.json +3 -0
- data/spec/fixtures/approvals/publish_contract_nothing_exists.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_nothing_exists_with_webhook.approved.json +1 -2
- data/spec/fixtures/approvals/publish_contract_verification_already_exists.approved.json +1 -2
- data/spec/fixtures/dashboard.json +4 -2
- data/spec/integration/ui/index_spec.rb +0 -2
- data/spec/integration/ui/matrix_spec.rb +0 -1
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_combinations_spec.rb → pacts_for_verification_json_query_schema_combinations_spec.rb} +6 -6
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_json_query_schema_spec.rb → pacts_for_verification_json_query_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/contracts/{verifiable_pacts_query_schema_spec.rb → pacts_for_verification_query_string_schema_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/dashboard_decorator_spec.rb +7 -7
- data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +19 -4
- data/spec/lib/pact_broker/api/decorators/{verifiable_pacts_query_decorator_spec.rb → pacts_for_verification_query_decorator_spec.rb} +3 -3
- data/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +7 -3
- data/spec/lib/pact_broker/contracts/service_spec.rb +24 -3
- data/spec/lib/pact_broker/db/data_migrations/create_branches_spec.rb +57 -0
- data/spec/lib/pact_broker/domain/index_item_spec.rb +1 -1
- data/spec/lib/pact_broker/domain/version_spec.rb +1 -35
- data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
- data/spec/lib/pact_broker/pacts/pact_publication_dataset_module_spec.rb +109 -10
- data/spec/lib/pact_broker/pacts/pact_publication_selector_dataset_module_spec.rb +3 -2
- data/spec/lib/pact_broker/pacts/pact_publication_spec.rb +5 -5
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_deployed_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/repository_find_for_currently_supported_releases_spec.rb +2 -2
- data/spec/lib/pact_broker/pacts/selector_spec.rb +45 -3
- data/spec/lib/pact_broker/pacts/verifiable_pact_messages_spec.rb +5 -5
- data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -5
- data/spec/lib/pact_broker/ui/view_models/index_item_spec.rb +15 -3
- data/spec/lib/pact_broker/verifications/repository_spec.rb +1 -1
- data/spec/lib/pact_broker/versions/branch_service_spec.rb +71 -0
- data/spec/lib/pact_broker/versions/branch_version_repository_spec.rb +81 -0
- data/spec/lib/pact_broker/versions/branch_version_spec.rb +27 -0
- data/spec/lib/pact_broker/versions/repository_spec.rb +91 -6
- data/spec/lib/pact_broker/versions/service_spec.rb +4 -3
- data/spec/lib/pact_broker/webhooks/render_spec.rb +6 -0
- data/spec/lib/sequel/plugins/upsert_spec.rb +11 -5
- data/spec/migrations/44_add_provider_version_to_verification_spec.rb +6 -9
- metadata +42 -15
- data/lib/pact_broker/versions/lazy_loaders.rb +0 -13
@@ -2,6 +2,9 @@ require "sequel"
|
|
2
2
|
require "pact_broker/logging"
|
3
3
|
require "pact_broker/domain/version"
|
4
4
|
require "pact_broker/tags/repository"
|
5
|
+
require "pact_broker/versions/branch"
|
6
|
+
require "pact_broker/versions/branch_version"
|
7
|
+
require "pact_broker/versions/branch_head"
|
5
8
|
|
6
9
|
module PactBroker
|
7
10
|
module Versions
|
@@ -49,22 +52,29 @@ module PactBroker
|
|
49
52
|
end
|
50
53
|
|
51
54
|
# There may be a race condition if two simultaneous requests come in to create the same version
|
52
|
-
def create
|
55
|
+
def create(args)
|
53
56
|
logger.info "Upserting version #{args[:number]} for pacticipant_id=#{args[:pacticipant_id]}"
|
54
57
|
version_params = {
|
55
58
|
number: args[:number],
|
56
59
|
pacticipant_id: args[:pacticipant_id],
|
57
60
|
created_at: Sequel.datetime_class.now,
|
58
|
-
updated_at: Sequel.datetime_class.now
|
59
|
-
|
61
|
+
updated_at: Sequel.datetime_class.now,
|
62
|
+
build_url: args[:build_url]
|
63
|
+
}.compact
|
60
64
|
|
61
|
-
|
65
|
+
|
66
|
+
version = PactBroker::Domain::Version.new(version_params).upsert
|
67
|
+
# branch can't be set from CRUD on the version resource, but it's convenient to be able
|
68
|
+
# to make a version with a branch for internal code.
|
69
|
+
branch_version_repository.add_branch(version, args[:branch]) if args[:branch]
|
70
|
+
version
|
62
71
|
end
|
63
72
|
|
64
73
|
def create_or_update(pacticipant, version_number, open_struct_version)
|
65
74
|
saved_version = PactBroker::Domain::Version.where(pacticipant_id: pacticipant.id, number: version_number).single_record
|
66
75
|
params = open_struct_version.to_h
|
67
76
|
tags = params.delete(:tags)
|
77
|
+
branch_name = params.delete(:branch)
|
68
78
|
if saved_version
|
69
79
|
saved_version.update(params)
|
70
80
|
else
|
@@ -74,10 +84,11 @@ module PactBroker
|
|
74
84
|
params.merge(
|
75
85
|
pacticipant_id: pacticipant.id,
|
76
86
|
number: version_number
|
77
|
-
)
|
87
|
+
).compact
|
78
88
|
).upsert
|
79
89
|
end
|
80
90
|
|
91
|
+
branch_version_repository.add_branch(saved_version, branch_name) if branch_name
|
81
92
|
replace_tags(saved_version, tags) if tags
|
82
93
|
saved_version
|
83
94
|
end
|
@@ -86,8 +97,7 @@ module PactBroker
|
|
86
97
|
saved_version = PactBroker::Domain::Version.new(
|
87
98
|
number: version_number,
|
88
99
|
pacticipant: pacticipant,
|
89
|
-
build_url: open_struct_version.build_url
|
90
|
-
branch: open_struct_version.branch
|
100
|
+
build_url: open_struct_version.build_url
|
91
101
|
).upsert
|
92
102
|
|
93
103
|
if open_struct_version.tags
|
@@ -112,7 +122,15 @@ module PactBroker
|
|
112
122
|
end
|
113
123
|
|
114
124
|
def delete_by_id version_ids
|
125
|
+
branches = Versions::Branch.where(id: Versions::BranchHead.select(:branch_id).where(version_id: version_ids)).all # these will be deleted
|
115
126
|
Domain::Version.where(id: version_ids).delete
|
127
|
+
branches.each do | branch |
|
128
|
+
new_head_branch_version = Versions::BranchVersion.find_latest_for_branch(branch)
|
129
|
+
if new_head_branch_version
|
130
|
+
PactBroker::Versions::BranchHead.new(branch: branch, branch_version: new_head_branch_version).upsert
|
131
|
+
end
|
132
|
+
end
|
133
|
+
nil
|
116
134
|
end
|
117
135
|
|
118
136
|
def delete_orphan_versions consumer, provider
|
@@ -129,11 +147,6 @@ module PactBroker
|
|
129
147
|
PactBroker::Domain::Version.select_all_qualified.for_selector(selector).all
|
130
148
|
end
|
131
149
|
|
132
|
-
def set_branch_if_unset(version, branch)
|
133
|
-
version.update(branch: branch) if version.branch.nil?
|
134
|
-
version
|
135
|
-
end
|
136
|
-
|
137
150
|
def find_latest_version_from_main_branch(pacticipant)
|
138
151
|
if pacticipant.main_branch
|
139
152
|
latest_from_main_branch = PactBroker::Domain::Version
|
@@ -10,23 +10,6 @@ module PactBroker
|
|
10
10
|
extend PactBroker::Services
|
11
11
|
include PactBroker::Logging
|
12
12
|
|
13
|
-
def self.conflict_errors(_existing_version, _open_struct_version, _version_url)
|
14
|
-
# This validation is causing problems in the PF build when branches are merged
|
15
|
-
# TODO remove this properly when re-doing the version -> branch relationship
|
16
|
-
{}
|
17
|
-
# if existing_version&.branch && open_struct_version.to_h.key?(:branch) && existing_version.branch != open_struct_version.branch
|
18
|
-
# message_params = {
|
19
|
-
# old_branch: existing_version&.branch,
|
20
|
-
# new_branch: open_struct_version.branch,
|
21
|
-
# version_url: version_url
|
22
|
-
# }
|
23
|
-
# error_message = message("errors.validation.cannot_modify_version_branch", message_params)
|
24
|
-
# { branch: [error_message] }
|
25
|
-
# else
|
26
|
-
# {}
|
27
|
-
# end
|
28
|
-
end
|
29
|
-
|
30
13
|
def self.find_latest_by_pacticpant_name params
|
31
14
|
version_repository.find_latest_by_pacticpant_name params.fetch(:pacticipant_name)
|
32
15
|
end
|
@@ -42,14 +25,12 @@ module PactBroker
|
|
42
25
|
def self.create_or_overwrite(pacticipant_name, version_number, version)
|
43
26
|
pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
|
44
27
|
version = version_repository.create_or_overwrite(pacticipant, version_number, version)
|
45
|
-
pacticipant_service.maybe_set_main_branch(pacticipant, version.branch)
|
46
28
|
version
|
47
29
|
end
|
48
30
|
|
49
31
|
def self.create_or_update(pacticipant_name, version_number, version)
|
50
32
|
pacticipant = pacticipant_repository.find_by_name_or_create(pacticipant_name)
|
51
33
|
version = version_repository.create_or_update(pacticipant, version_number, version)
|
52
|
-
pacticipant_service.maybe_set_main_branch(pacticipant, version.branch)
|
53
34
|
version
|
54
35
|
end
|
55
36
|
|
@@ -66,9 +47,9 @@ module PactBroker
|
|
66
47
|
end
|
67
48
|
|
68
49
|
def self.maybe_set_version_branch_from_tag(version, tag_name)
|
69
|
-
if use_tag_as_branch?(version) &&
|
70
|
-
logger.info "
|
71
|
-
|
50
|
+
if use_tag_as_branch?(version) && version.branch_versions.empty?
|
51
|
+
logger.info "Adding #{version.pacticipant.name} version #{version.number} to branch '#{tag_name}' (from first tag, because use_first_tag_as_branch=true)"
|
52
|
+
branch_version_repository.add_branch(version, tag_name, auto_created: true)
|
72
53
|
end
|
73
54
|
end
|
74
55
|
|
@@ -14,6 +14,7 @@ module PactBroker
|
|
14
14
|
GITHUB_VERIFICATION_STATUS = "pactbroker.githubVerificationStatus"
|
15
15
|
BITBUCKET_VERIFICATION_STATUS = "pactbroker.bitbucketVerificationStatus"
|
16
16
|
AZURE_DEV_OPS_VERIFICATION_STATUS = "pactbroker.azureDevOpsVerificationStatus"
|
17
|
+
GITLAB_VERIFICATION_STATUS = "pactbroker.gitlabVerificationStatus"
|
17
18
|
CONSUMER_LABELS = "pactbroker.consumerLabels"
|
18
19
|
PROVIDER_LABELS = "pactbroker.providerLabels"
|
19
20
|
EVENT_NAME = "pactbroker.eventName"
|
@@ -33,6 +34,7 @@ module PactBroker
|
|
33
34
|
GITHUB_VERIFICATION_STATUS,
|
34
35
|
BITBUCKET_VERIFICATION_STATUS,
|
35
36
|
AZURE_DEV_OPS_VERIFICATION_STATUS,
|
37
|
+
GITLAB_VERIFICATION_STATUS,
|
36
38
|
CONSUMER_LABELS,
|
37
39
|
PROVIDER_LABELS,
|
38
40
|
EVENT_NAME,
|
@@ -46,7 +48,6 @@ module PactBroker
|
|
46
48
|
@base_url = webhook_context.fetch(:base_url)
|
47
49
|
end
|
48
50
|
|
49
|
-
# rubocop: disable Metrics/CyclomaticComplexity
|
50
51
|
def to_hash
|
51
52
|
@hash ||= {
|
52
53
|
PACT_URL => pact ? PactBroker::Api::PactBrokerUrls.pact_version_url_with_webhook_metadata(pact, base_url) : "",
|
@@ -62,13 +63,13 @@ module PactBroker
|
|
62
63
|
GITHUB_VERIFICATION_STATUS => github_verification_status,
|
63
64
|
BITBUCKET_VERIFICATION_STATUS => bitbucket_verification_status,
|
64
65
|
AZURE_DEV_OPS_VERIFICATION_STATUS => azure_dev_ops_verification_status,
|
66
|
+
GITLAB_VERIFICATION_STATUS => gitlab_verification_status,
|
65
67
|
CONSUMER_LABELS => pacticipant_labels(pact && pact.consumer),
|
66
68
|
PROVIDER_LABELS => pacticipant_labels(pact && pact.provider),
|
67
69
|
EVENT_NAME => event_name,
|
68
70
|
CURRENTLY_DEPLOYED_PROVIDER_VERSION_NUMBER => currently_deployed_provider_version_number
|
69
71
|
}
|
70
72
|
end
|
71
|
-
# rubocop: enable Metrics/CyclomaticComplexity
|
72
73
|
|
73
74
|
private
|
74
75
|
|
@@ -98,6 +99,14 @@ module PactBroker
|
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
102
|
+
def gitlab_verification_status
|
103
|
+
if verification
|
104
|
+
verification.success ? "success" : "failed"
|
105
|
+
else
|
106
|
+
"pending"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
101
110
|
def verification_url
|
102
111
|
if verification
|
103
112
|
PactBroker::Api::PactBrokerUrls.verification_url(verification, base_url)
|
@@ -26,6 +26,7 @@ module Sequel
|
|
26
26
|
self
|
27
27
|
rescue Sequel::NoExistingObject
|
28
28
|
load_values_from_previously_inserted_object
|
29
|
+
self
|
29
30
|
end
|
30
31
|
|
31
32
|
private
|
@@ -41,6 +42,9 @@ module Sequel
|
|
41
42
|
insert_ignore_primary_key_columns.each do | column |
|
42
43
|
self.send("#{column}=".to_sym, existing_record[column])
|
43
44
|
end
|
45
|
+
# Need to clear out the _update_dataset when the NoExistingObject is thrown because
|
46
|
+
# the ID gets incremented somewhere in the Sequel code
|
47
|
+
@this = nil
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
@@ -28,6 +28,7 @@ module Sequel
|
|
28
28
|
self
|
29
29
|
rescue Sequel::NoExistingObject
|
30
30
|
load_values_from_previously_inserted_object
|
31
|
+
self
|
31
32
|
ensure
|
32
33
|
@upsert_plugin_upserting = false
|
33
34
|
end
|
@@ -45,6 +46,9 @@ module Sequel
|
|
45
46
|
upsert_primary_key_columns.each do | column |
|
46
47
|
self.send("#{column}=".to_sym, existing_record[column])
|
47
48
|
end
|
49
|
+
# Need to clear out the _update_dataset when the NoExistingObject is thrown because
|
50
|
+
# the ID gets incremented somewhere in the Sequel code
|
51
|
+
@this = nil
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
data/public/javascripts/index.js
CHANGED
@@ -1,24 +1,13 @@
|
|
1
1
|
$(document).ready(function() {
|
2
|
-
$(".integration-settings")
|
3
|
-
.
|
2
|
+
$(".integration-settings").click(function() {
|
3
|
+
const clickedElementData = $(this).closest("tr").data();
|
4
|
+
$(this).materialMenu("init", {
|
4
5
|
position: "overlay",
|
5
6
|
animationSpeed: 1,
|
6
|
-
items:
|
7
|
-
{
|
8
|
-
type: "normal",
|
9
|
-
text: "Delete pacts ...",
|
10
|
-
click: handleDeletePactsSelected
|
11
|
-
},
|
12
|
-
{
|
13
|
-
type: "normal",
|
14
|
-
text: "Delete integration...",
|
15
|
-
click: handleDeleteIntegrationsSelected
|
16
|
-
}
|
17
|
-
]
|
18
|
-
})
|
19
|
-
.click(function() {
|
20
|
-
$(this).materialMenu("open");
|
7
|
+
items: buildMaterialMenuItems(clickedElementData)
|
21
8
|
});
|
9
|
+
$(this).materialMenu("open");
|
10
|
+
});
|
22
11
|
});
|
23
12
|
|
24
13
|
function createPactDeletionConfirmationText(rowData) {
|
@@ -35,6 +24,16 @@ function createIntegrationDeletionConfirmationText(rowData) {
|
|
35
24
|
}, and all associated data (pacts, verifications, application versions, tags and webhooks) that are not associated with other integrations. Do you wish to continue?`;
|
36
25
|
}
|
37
26
|
|
27
|
+
function createPactTagDeletionConfirmationText({
|
28
|
+
providerName,
|
29
|
+
consumerName,
|
30
|
+
pactTagName
|
31
|
+
}) {
|
32
|
+
return `This will delete the pacts for provider ${providerName} and all versions of ${
|
33
|
+
consumerName
|
34
|
+
} with tag ${pactTagName}. Do you wish to continue?`;
|
35
|
+
}
|
36
|
+
|
38
37
|
function handleDeletePactsSelected(clickedElement) {
|
39
38
|
const tr = $(clickedElement).closest("tr");
|
40
39
|
const confirmationText = createPactDeletionConfirmationText(tr.data());
|
@@ -51,12 +50,47 @@ function handleDeleteIntegrationsSelected(clickedElement) {
|
|
51
50
|
handleDeleteResourcesSelected(tr, tr.data().integrationUrl, confirmationText);
|
52
51
|
}
|
53
52
|
|
54
|
-
function
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
function handleDeleteTagSelected({
|
54
|
+
providerName,
|
55
|
+
consumerName,
|
56
|
+
pactTagName,
|
57
|
+
deletionUrl
|
58
|
+
}) {
|
59
|
+
return function(clickedElement) {
|
60
|
+
const tr = $(clickedElement).closest("tr");
|
61
|
+
const confirmationText = createPactTagDeletionConfirmationText({
|
62
|
+
providerName,
|
63
|
+
consumerName,
|
64
|
+
pactTagName
|
65
|
+
});
|
66
|
+
handleDeleteResourcesSelected(
|
67
|
+
tr,
|
68
|
+
deletionUrl,
|
69
|
+
confirmationText,
|
70
|
+
pactTagName
|
59
71
|
);
|
72
|
+
};
|
73
|
+
}
|
74
|
+
|
75
|
+
function findRowsToBeDeleted(table, consumerName, providerName, tagName) {
|
76
|
+
if (!tagName) {
|
77
|
+
return table
|
78
|
+
.children("tbody")
|
79
|
+
.find(
|
80
|
+
`[data-consumer-name="${consumerName}"][data-provider-name="${providerName}"]`
|
81
|
+
);
|
82
|
+
}
|
83
|
+
|
84
|
+
return table
|
85
|
+
.children("tbody")
|
86
|
+
.find("tr")
|
87
|
+
.find("td")
|
88
|
+
.filter(function() {
|
89
|
+
return $(this)
|
90
|
+
.text()
|
91
|
+
.includes(`tag: ${tagName}`);
|
92
|
+
})
|
93
|
+
.closest("tr");
|
60
94
|
}
|
61
95
|
|
62
96
|
function highlightRowsToBeDeleted(rows) {
|
@@ -87,13 +121,20 @@ function confirmDeleteResources(
|
|
87
121
|
});
|
88
122
|
}
|
89
123
|
|
90
|
-
function handleDeleteResourcesSelected(
|
124
|
+
function handleDeleteResourcesSelected(
|
125
|
+
row,
|
126
|
+
deletionUrl,
|
127
|
+
confirmationText,
|
128
|
+
tagName
|
129
|
+
) {
|
91
130
|
const rowData = row.data();
|
92
131
|
const rows = findRowsToBeDeleted(
|
93
132
|
row.closest("table"),
|
94
133
|
rowData.consumerName,
|
95
|
-
rowData.providerName
|
134
|
+
rowData.providerName,
|
135
|
+
tagName
|
96
136
|
);
|
137
|
+
const isRefreshingThePage = !!tagName;
|
97
138
|
const cancelled = function() {
|
98
139
|
unHighlightRows(rows);
|
99
140
|
};
|
@@ -101,14 +142,17 @@ function handleDeleteResourcesSelected(row, deletionUrl, confirmationText) {
|
|
101
142
|
deleteResources(
|
102
143
|
deletionUrl,
|
103
144
|
function() {
|
104
|
-
handleDeletionSuccess(rows);
|
145
|
+
handleDeletionSuccess(rows, isRefreshingThePage);
|
105
146
|
},
|
106
147
|
function(response) {
|
107
148
|
handleDeletionFailure(rows, response);
|
108
149
|
}
|
109
150
|
);
|
110
151
|
};
|
111
|
-
|
152
|
+
|
153
|
+
if (!isRefreshingThePage) {
|
154
|
+
highlightRowsToBeDeleted(rows);
|
155
|
+
}
|
112
156
|
confirmDeleteResources(confirmationText, confirmed, cancelled);
|
113
157
|
}
|
114
158
|
|
@@ -125,19 +169,34 @@ function hideDeletedRows(rows) {
|
|
125
169
|
});
|
126
170
|
}
|
127
171
|
|
128
|
-
function
|
172
|
+
function refreshPage() {
|
173
|
+
const url = new URL(window.location);
|
174
|
+
url.searchParams.delete("search");
|
175
|
+
window.location = url.toString();
|
176
|
+
}
|
177
|
+
|
178
|
+
function handleDeletionSuccess(rows, isRefreshingThePage) {
|
179
|
+
if (isRefreshingThePage) {
|
180
|
+
return refreshPage();
|
181
|
+
}
|
182
|
+
|
129
183
|
hideDeletedRows(rows);
|
130
184
|
}
|
131
185
|
|
132
186
|
function createErrorMessage(responseBody) {
|
133
|
-
if (
|
134
|
-
|
135
|
-
|
136
|
-
|
187
|
+
if (
|
188
|
+
responseBody &&
|
189
|
+
responseBody.error &&
|
190
|
+
responseBody.error.message &&
|
191
|
+
responseBody.error.reference
|
192
|
+
) {
|
193
|
+
return `<p>Could not delete resources due to error: ${responseBody.error.message}</p><p>Error reference:
|
137
194
|
${responseBody.error.reference}
|
138
195
|
</p>`;
|
139
196
|
} else if (responseBody) {
|
140
|
-
return `Could not delete resources due to error: ${JSON.stringify(
|
197
|
+
return `Could not delete resources due to error: ${JSON.stringify(
|
198
|
+
responseBody
|
199
|
+
)}`;
|
141
200
|
}
|
142
201
|
|
143
202
|
return "Could not delete resources.";
|
@@ -159,11 +218,47 @@ function deleteResources(url, successCallback, errorCallback) {
|
|
159
218
|
accepts: {
|
160
219
|
text: "application/hal+json"
|
161
220
|
},
|
162
|
-
success: function(
|
221
|
+
success: function() {
|
163
222
|
successCallback();
|
164
223
|
},
|
165
|
-
error: function(jqXhr
|
224
|
+
error: function(jqXhr) {
|
166
225
|
errorCallback(jqXhr.responseJSON);
|
167
226
|
}
|
168
227
|
});
|
169
228
|
}
|
229
|
+
|
230
|
+
function buildMaterialMenuItems(clickedElementData) {
|
231
|
+
const baseOptions = [
|
232
|
+
{
|
233
|
+
type: "normal",
|
234
|
+
text: "Delete pacts ...",
|
235
|
+
click: handleDeletePactsSelected
|
236
|
+
},
|
237
|
+
{
|
238
|
+
type: "normal",
|
239
|
+
text: "Delete integration...",
|
240
|
+
click: handleDeleteIntegrationsSelected
|
241
|
+
}
|
242
|
+
];
|
243
|
+
|
244
|
+
const taggedPacts = clickedElementData.taggedPacts || [];
|
245
|
+
const providerName = clickedElementData.providerName;
|
246
|
+
const consumerName = clickedElementData.consumerName;
|
247
|
+
const taggedPactsOptions = taggedPacts.map(taggedPact => {
|
248
|
+
const taggedPactObject = JSON.parse(taggedPact);
|
249
|
+
const pactTagName = taggedPactObject.tag;
|
250
|
+
const taggedPactUrl = taggedPactObject.deletionUrl;
|
251
|
+
return {
|
252
|
+
type: "normal",
|
253
|
+
text: `Delete pacts for ${pactTagName}...`,
|
254
|
+
click: handleDeleteTagSelected({
|
255
|
+
providerName,
|
256
|
+
consumerName,
|
257
|
+
pactTagName,
|
258
|
+
deletionUrl: taggedPactUrl
|
259
|
+
})
|
260
|
+
};
|
261
|
+
});
|
262
|
+
|
263
|
+
return [...baseOptions, ...taggedPactsOptions];
|
264
|
+
}
|