pact_broker 2.91.0 → 2.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/db/migrations/20210608_add_uuid_to_webhook.rb +1 -0
- data/db/migrations/20211120_create_pact_version_provider_tag_successful_verifications.rb +23 -0
- data/db/migrations/20211121_migrate_pact_version_provider_tag_successful_verifications_data.rb +11 -0
- data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +2 -2
- data/lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb +5 -1
- data/lib/pact_broker/config/runtime_configuration_database_methods.rb +6 -0
- data/lib/pact_broker/db/clean_incremental.rb +17 -2
- data/lib/pact_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications.rb +38 -0
- data/lib/pact_broker/db/migrate_data.rb +1 -0
- data/lib/pact_broker/deployments/deployed_version.rb +9 -1
- data/lib/pact_broker/initializers/database_connection.rb +6 -4
- data/lib/pact_broker/pacts/pact_publication_dataset_module.rb +35 -38
- data/lib/pact_broker/pacts/pact_publication_wip_dataset_module.rb +44 -0
- data/lib/pact_broker/test/http_test_data_builder.rb +1 -0
- data/lib/pact_broker/test/test_data_builder.rb +36 -9
- data/lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.rb +11 -0
- data/lib/pact_broker/verifications/repository.rb +16 -0
- data/lib/pact_broker/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24079bee3bfb14bfb86f5c9bc12d6f1110a19eb3e4098b8a1543d93a309a562c
|
4
|
+
data.tar.gz: 59ef52df7edeb89738512914f8dbaca0a500d27ce84700e2c5e3bd06f3ce1421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 954b6742ba7f76c9af9153c7ba05205e51993df3b97eba56219cbb7a5027df3808cabcb3a4611d72bb2bff7376a2bf3e5b7876eadccc0bda8f23e0affdaad28f
|
7
|
+
data.tar.gz: 8485529fb6980f2925892871d382376d0860b9c7ee9e72afeb3235a99dff18cb2afb08993666095fe6b084373ed79ce5396a16a22a3c70ea5a656246a0335310
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
<a name="v2.92.0"></a>
|
2
|
+
### v2.92.0 (2021-11-27)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* allow SQL caller logging to be enabled ([861d8f21](/../../commit/861d8f21))
|
7
|
+
* use a separate table to track the successful verifications of pact versions for each provider version tag (feature toggled with "new_wip_calculation") ([df0acfa3](/../../commit/df0acfa3))
|
8
|
+
|
9
|
+
#### Bug Fixes
|
10
|
+
|
11
|
+
* **cleanup**
|
12
|
+
* Improve delete orphans SQL query (#527) ([853354ea](/../../commit/853354ea))
|
13
|
+
|
14
|
+
* cast PACT_BROKER_DATABASE_CONNECTION_VALIDATION_TIMEOUT to an integer ([8816c61f](/../../commit/8816c61f))
|
15
|
+
|
1
16
|
<a name="v2.91.0"></a>
|
2
17
|
### v2.91.0 (2021-11-15)
|
3
18
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
create_table(:pact_version_provider_tag_successful_verifications, charset: "utf8") do
|
4
|
+
primary_key :id
|
5
|
+
foreign_key :pact_version_id, :pact_versions, null: false, on_delete: :cascade, foreign_key_constraint_name: "pact_version_provider_tag_successful_verifications_pv_id_fk"
|
6
|
+
String :provider_version_tag_name, null: false
|
7
|
+
Boolean :wip, null: false
|
8
|
+
Integer :verification_id
|
9
|
+
DateTime :execution_date, null: false
|
10
|
+
index([:pact_version_id, :provider_version_tag_name, :wip], unique: true, name: "pact_version_provider_tag_verifications_pv_pvtn_wip_unique")
|
11
|
+
# The implication of the on_delete: :set_null for verification_id is
|
12
|
+
# that even if the verification result is deleted from the broker,
|
13
|
+
# the wip/pending status stays the same.
|
14
|
+
# We may or may not want this. Will have to wait and see.
|
15
|
+
# Have made the foreign key a separate declaration so it can more easily be remade.
|
16
|
+
foreign_key([:verification_id], :verifications, on_delete: :set_null, name: "pact_version_provider_tag_successful_verifications_v_id_fk")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
down do
|
21
|
+
drop_table(:pact_version_provider_tag_successful_verifications)
|
22
|
+
end
|
23
|
+
end
|
data/db/migrations/20211121_migrate_pact_version_provider_tag_successful_verifications_data.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "pact_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications"
|
2
|
+
|
3
|
+
Sequel.migration do
|
4
|
+
up do
|
5
|
+
PactBroker::DB::DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications.call(self)
|
6
|
+
end
|
7
|
+
|
8
|
+
down do
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -18,6 +18,7 @@ module PactBroker
|
|
18
18
|
database_sslmode: nil,
|
19
19
|
sql_log_level: :debug,
|
20
20
|
sql_log_warn_duration: 5,
|
21
|
+
sql_enable_caller_logging: false,
|
21
22
|
database_max_connections: nil,
|
22
23
|
database_pool_timeout: 5,
|
23
24
|
database_connect_max_retries: 0,
|
@@ -36,6 +37,7 @@ module PactBroker
|
|
36
37
|
encoding: "utf8",
|
37
38
|
sslmode: database_sslmode,
|
38
39
|
sql_log_level: sql_log_level,
|
40
|
+
enable_caller_logging: sql_enable_caller_logging,
|
39
41
|
log_warn_duration: sql_log_warn_duration,
|
40
42
|
max_connections: database_max_connections,
|
41
43
|
pool_timeout: database_pool_timeout,
|
@@ -65,6 +67,10 @@ module PactBroker
|
|
65
67
|
super(metrics_sql_statement_timeout&.to_i)
|
66
68
|
end
|
67
69
|
|
70
|
+
def database_connection_validation_timeout= database_connection_validation_timeout
|
71
|
+
super(database_connection_validation_timeout&.to_i)
|
72
|
+
end
|
73
|
+
|
68
74
|
def postgres?
|
69
75
|
database_credentials[:adapter] == "postgres"
|
70
76
|
end
|
@@ -92,8 +92,23 @@ module PactBroker
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def delete_orphan_pact_versions
|
95
|
-
|
96
|
-
|
95
|
+
db[:pact_versions].where(id: orphan_pact_versions).delete
|
96
|
+
rescue Sequel::DatabaseError => e
|
97
|
+
raise unless e.cause.class.name == "Mysql2::Error"
|
98
|
+
|
99
|
+
ids = orphan_pact_versions.map { |row| row[:id] }
|
100
|
+
db[:pact_versions].where(id: ids).delete
|
101
|
+
end
|
102
|
+
|
103
|
+
def orphan_pact_versions
|
104
|
+
db[:pact_versions]
|
105
|
+
.left_join(:pact_publications, pact_version_id: :id)
|
106
|
+
.left_join(:verifications, pact_version_id: :id)
|
107
|
+
.select(Sequel[:pact_versions][:id])
|
108
|
+
.where(
|
109
|
+
Sequel[:pact_publications][:id] => nil,
|
110
|
+
Sequel[:verifications][:id] => nil
|
111
|
+
)
|
97
112
|
end
|
98
113
|
|
99
114
|
def version_info(version)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "pact_broker/db/data_migrations/helpers"
|
2
|
+
|
3
|
+
module PactBroker
|
4
|
+
module DB
|
5
|
+
module DataMigrations
|
6
|
+
class MigratePactVersionProviderTagSuccessfulVerifications
|
7
|
+
extend Helpers
|
8
|
+
|
9
|
+
def self.call(connection)
|
10
|
+
successful_verifications_join = {
|
11
|
+
Sequel[:sv][:pact_version_id] => Sequel[:verifications][:pact_version_id],
|
12
|
+
Sequel[:sv][:provider_version_tag_name] => Sequel[:tags][:name],
|
13
|
+
Sequel[:sv][:wip] => Sequel[:verifications][:wip]
|
14
|
+
}
|
15
|
+
|
16
|
+
missing_verifications = connection
|
17
|
+
.select(
|
18
|
+
Sequel[:verifications][:pact_version_id],
|
19
|
+
Sequel[:tags][:name],
|
20
|
+
Sequel[:verifications][:wip],
|
21
|
+
Sequel[:verifications][:id],
|
22
|
+
Sequel[:verifications][:execution_date]
|
23
|
+
)
|
24
|
+
.order(Sequel[:verifications][:execution_date], Sequel[:verifications][:id])
|
25
|
+
.from(:verifications)
|
26
|
+
.join(:tags, { Sequel[:verifications][:provider_version_id] => Sequel[:tags][:version_id] })
|
27
|
+
.left_outer_join(:pact_version_provider_tag_successful_verifications, successful_verifications_join, { table_alias: :sv })
|
28
|
+
.where(Sequel[:sv][:pact_version_id] => nil)
|
29
|
+
.where(Sequel[:verifications][:success] => true)
|
30
|
+
|
31
|
+
connection[:pact_version_provider_tag_successful_verifications]
|
32
|
+
.insert_ignore
|
33
|
+
.insert([:pact_version_id, :provider_version_tag_name, :wip, :verification_id, :execution_date], missing_verifications)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -28,6 +28,7 @@ module PactBroker
|
|
28
28
|
DataMigrations::SetExtraColumnsForTags.call(database_connection)
|
29
29
|
DataMigrations::CreateBranches.call(database_connection)
|
30
30
|
DataMigrations::MigrateIntegrations.call(database_connection)
|
31
|
+
DataMigrations::MigratePactVersionProviderTagSuccessfulVerifications.call(database_connection)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -88,6 +88,15 @@ module PactBroker
|
|
88
88
|
!!currently_deployed_version_id
|
89
89
|
end
|
90
90
|
|
91
|
+
# target has been renamed to applicationInstance in the API.
|
92
|
+
def application_instance
|
93
|
+
target
|
94
|
+
end
|
95
|
+
|
96
|
+
def application_instance= application_instance
|
97
|
+
self.target = application_instance
|
98
|
+
end
|
99
|
+
|
91
100
|
def version_number
|
92
101
|
version.number
|
93
102
|
end
|
@@ -100,7 +109,6 @@ module PactBroker
|
|
100
109
|
self.class.where(id: id).record_undeployed
|
101
110
|
self.refresh
|
102
111
|
end
|
103
|
-
|
104
112
|
end
|
105
113
|
end
|
106
114
|
end
|
@@ -9,7 +9,8 @@ module PactBroker
|
|
9
9
|
sequel_config = config.dup
|
10
10
|
max_retries = sequel_config.delete(:connect_max_retries) || 0
|
11
11
|
connection_validation_timeout = config.delete(:connection_validation_timeout)
|
12
|
-
|
12
|
+
enable_caller_logging = config.delete(:enable_caller_logging)
|
13
|
+
configure_logger(sequel_config, logger)
|
13
14
|
create_sqlite_database_dir(config)
|
14
15
|
|
15
16
|
connection = with_retries(max_retries, logger) do
|
@@ -18,7 +19,7 @@ module PactBroker
|
|
18
19
|
|
19
20
|
logger&.info "Connected to database #{sequel_config[:database]}"
|
20
21
|
|
21
|
-
configure_connection(connection, connection_validation_timeout)
|
22
|
+
configure_connection(connection, connection_validation_timeout, enable_caller_logging)
|
22
23
|
end
|
23
24
|
|
24
25
|
private_class_method def self.with_retries(max_retries, logger)
|
@@ -46,7 +47,7 @@ module PactBroker
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
private_class_method def self.configure_logger(sequel_config)
|
50
|
+
private_class_method def self.configure_logger(sequel_config, logger)
|
50
51
|
if sequel_config[:sql_log_level] == :none
|
51
52
|
sequel_config.delete(:sql_log_level)
|
52
53
|
elsif logger
|
@@ -72,8 +73,9 @@ module PactBroker
|
|
72
73
|
# when databases are restarted and connections are killed. This has a performance
|
73
74
|
# penalty, so consider increasing this timeout if building a frequently accessed service.
|
74
75
|
|
75
|
-
private_class_method def self.configure_connection(connection, connection_validation_timeout)
|
76
|
+
private_class_method def self.configure_connection(connection, connection_validation_timeout, enable_caller_logging)
|
76
77
|
connection.extension(:connection_validator)
|
78
|
+
connection.extension(:caller_logging) if enable_caller_logging
|
77
79
|
connection.pool.connection_validation_timeout = connection_validation_timeout if connection_validation_timeout
|
78
80
|
connection
|
79
81
|
end
|
@@ -140,65 +140,62 @@ module PactBroker
|
|
140
140
|
end
|
141
141
|
|
142
142
|
# The latest pact publication for each tag
|
143
|
+
# This uses the old logic of "the latest pact for a version that has a tag" (which always returns a pact)
|
144
|
+
# rather than "the pact for the latest version with a tag"
|
145
|
+
# Need to see about updating this.
|
143
146
|
def latest_by_consumer_tag
|
144
147
|
tags_join = {
|
145
|
-
Sequel[:pact_publications][:consumer_version_id] => Sequel[:tags][:version_id]
|
148
|
+
Sequel[:pact_publications][:consumer_version_id] => Sequel[:tags][:version_id],
|
146
149
|
}
|
147
150
|
|
148
|
-
|
151
|
+
max_orders = join(:tags, tags_join)
|
152
|
+
.select_group(:consumer_id, :provider_id, Sequel[:tags][:name].as(:tag_name))
|
153
|
+
.select_append{ max(consumer_version_order).as(latest_consumer_version_order) }
|
154
|
+
|
155
|
+
max_join = {
|
156
|
+
Sequel[:max_orders][:consumer_id] => Sequel[:pact_publications][:consumer_id],
|
157
|
+
Sequel[:max_orders][:provider_id] => Sequel[:pact_publications][:provider_id],
|
158
|
+
Sequel[:max_orders][:latest_consumer_version_order] => Sequel[:pact_publications][:consumer_version_order]
|
159
|
+
}
|
149
160
|
|
161
|
+
base_query = self
|
150
162
|
if no_columns_selected?
|
151
|
-
base_query = base_query.select_all_qualified.select_append(Sequel[:
|
163
|
+
base_query = base_query.select_all_qualified.select_append(Sequel[:max_orders][:tag_name])
|
152
164
|
end
|
153
165
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
Sequel[:tags][:name].as(:tag_name)
|
158
|
-
)
|
159
|
-
|
160
|
-
self_join = {
|
161
|
-
Sequel[:pact_publications][:consumer_id] => Sequel[:pp2][:consumer_id],
|
162
|
-
Sequel[:tags][:name] => Sequel[:pp2][:tag_name]
|
163
|
-
}
|
164
|
-
base_query.left_join(joined_query, self_join, { table_alias: :pp2 } ) do
|
165
|
-
Sequel[:pp2][:version_order] > Sequel[:tags][:version_order]
|
166
|
-
end
|
167
|
-
.where(Sequel[:pp2][:version_order] => nil)
|
168
|
-
.remove_overridden_revisions_from_complete_query
|
166
|
+
base_query
|
167
|
+
.join(max_orders, max_join, { table_alias: :max_orders })
|
168
|
+
.remove_overridden_revisions_from_complete_query
|
169
169
|
end
|
170
170
|
|
171
|
+
# This uses the old logic of "the latest pact for a version that has a tag" (which always returns a pact)
|
172
|
+
# rather than "the pact for the latest version with a tag"
|
173
|
+
# Need to see about updating this.
|
171
174
|
def latest_for_consumer_tag(tag_name)
|
172
175
|
tags_join = {
|
173
176
|
Sequel[:pact_publications][:consumer_version_id] => Sequel[:tags][:version_id],
|
174
177
|
Sequel[:tags][:name] => tag_name
|
175
178
|
}
|
176
179
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
base_query = base_query
|
183
|
-
.join(:tags, tags_join)
|
184
|
-
.where(Sequel[:tags][:name] => tag_name)
|
180
|
+
max_orders = join(:tags, tags_join)
|
181
|
+
.select_group(:consumer_id, :provider_id, Sequel[:tags][:name].as(:tag_name))
|
182
|
+
.select_append{ max(consumer_version_order).as(latest_consumer_version_order) }
|
185
183
|
|
186
|
-
joined_query = base_query.select(
|
187
|
-
Sequel[:pact_publications][:consumer_id],
|
188
|
-
Sequel[:tags][:name].as(:tag_name),
|
189
|
-
Sequel[:tags][:version_order]
|
190
|
-
)
|
191
184
|
|
192
|
-
|
193
|
-
Sequel[:
|
194
|
-
Sequel[:
|
185
|
+
max_join = {
|
186
|
+
Sequel[:max_orders][:consumer_id] => Sequel[:pact_publications][:consumer_id],
|
187
|
+
Sequel[:max_orders][:provider_id] => Sequel[:pact_publications][:provider_id],
|
188
|
+
Sequel[:max_orders][:latest_consumer_version_order] => Sequel[:pact_publications][:consumer_version_order]
|
195
189
|
}
|
196
190
|
|
197
|
-
base_query
|
198
|
-
|
191
|
+
base_query = self
|
192
|
+
if no_columns_selected?
|
193
|
+
base_query = base_query.select_all_qualified.select_append(Sequel[:max_orders][:tag_name])
|
199
194
|
end
|
200
|
-
|
201
|
-
|
195
|
+
|
196
|
+
base_query
|
197
|
+
.join(max_orders, max_join, { table_alias: :max_orders })
|
198
|
+
.remove_overridden_revisions_from_complete_query
|
202
199
|
end
|
203
200
|
|
204
201
|
# The pacts for the latest versions with the specified tag (new logic)
|
@@ -33,6 +33,8 @@ module PactBroker
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def successfully_verified_by_provider_tag_when_not_wip(provider_id, provider_tag)
|
36
|
+
return new_successfully_verified_by_provider_tag_when_not_wip(provider_id, provider_tag) if PactBroker.feature_enabled?(:new_wip_calculation)
|
37
|
+
|
36
38
|
from_self(alias: :pp)
|
37
39
|
.select(Sequel[:pp].*)
|
38
40
|
.where(Sequel[:pp][:provider_id] => provider_id)
|
@@ -41,7 +43,23 @@ module PactBroker
|
|
41
43
|
.distinct
|
42
44
|
end
|
43
45
|
|
46
|
+
def new_successfully_verified_by_provider_tag_when_not_wip(_provider_id, provider_tag)
|
47
|
+
pact_version_provider_tag_verifications_join = {
|
48
|
+
Sequel[:sv][:pact_version_id] => Sequel[:pp][:pact_version_id],
|
49
|
+
Sequel[:sv][:provider_version_tag_name] => provider_tag,
|
50
|
+
Sequel[:sv][:wip] => false
|
51
|
+
}
|
52
|
+
|
53
|
+
from_self(alias: :pp)
|
54
|
+
.select(Sequel[:pp].*)
|
55
|
+
.join(:pact_version_provider_tag_successful_verifications, pact_version_provider_tag_verifications_join, { table_alias: :sv })
|
56
|
+
.distinct
|
57
|
+
|
58
|
+
end
|
59
|
+
|
44
60
|
def successfully_verified_by_provider_another_tag_before_this_tag_first_created(provider_id, provider_tag)
|
61
|
+
return new_successfully_verified_by_provider_another_tag_before_this_tag_first_created(provider_id, provider_tag) if PactBroker.feature_enabled?(:new_wip_calculation)
|
62
|
+
|
45
63
|
first_tag_with_name = PactBroker::Domain::Tag.where(pacticipant_id: provider_id, name: provider_tag).order(:created_at).first
|
46
64
|
from_self(alias: :pp)
|
47
65
|
.select(Sequel[:pp].*)
|
@@ -54,6 +72,32 @@ module PactBroker
|
|
54
72
|
.distinct
|
55
73
|
end
|
56
74
|
|
75
|
+
def new_successfully_verified_by_provider_another_tag_before_this_tag_first_created(provider_id, provider_tag)
|
76
|
+
first_tag_with_name = PactBroker::Domain::Tag.where(pacticipant_id: provider_id, name: provider_tag).order(:created_at).first
|
77
|
+
|
78
|
+
pact_version_provider_tag_verifications_join = {
|
79
|
+
Sequel[:sv][:pact_version_id] => Sequel[:pp][:pact_version_id],
|
80
|
+
Sequel[:sv][:wip] => false
|
81
|
+
}
|
82
|
+
|
83
|
+
created_at_criteria = if first_tag_with_name
|
84
|
+
Sequel.lit("sv.execution_date < ?", first_tag_with_name.created_at)
|
85
|
+
else
|
86
|
+
Sequel.lit("1 = 1")
|
87
|
+
end
|
88
|
+
|
89
|
+
from_self(alias: :pp)
|
90
|
+
.select(Sequel[:pp].*)
|
91
|
+
.where(Sequel[:pp][:provider_id] => provider_id)
|
92
|
+
.join(:pact_version_provider_tag_successful_verifications, pact_version_provider_tag_verifications_join, { table_alias: :sv }) do
|
93
|
+
Sequel.&(
|
94
|
+
Sequel.lit("sv.provider_version_tag_name NOT IN (?)", provider_tag),
|
95
|
+
created_at_criteria
|
96
|
+
)
|
97
|
+
end
|
98
|
+
.distinct
|
99
|
+
end
|
100
|
+
|
57
101
|
protected
|
58
102
|
|
59
103
|
def verified_before_date(date)
|
@@ -273,6 +273,7 @@ module PactBroker
|
|
273
273
|
"eventName" => "${pactbroker.eventName}",
|
274
274
|
"consumerVersionNumber" => "${pactbroker.consumerVersionNumber}",
|
275
275
|
"consumerVersionTags" => "${pactbroker.consumerVersionTags}",
|
276
|
+
"consumerVersionBranch" => "${pactbroker.consumerVersionBranch}",
|
276
277
|
"githubVerificationStatus" => "${pactbroker.githubVerificationStatus}",
|
277
278
|
"providerVersionNumber" => "${pactbroker.providerVersionNumber}",
|
278
279
|
"providerVersionTags" => "${pactbroker.providerVersionTags}",
|
@@ -31,6 +31,8 @@ require "pact_broker/deployments/deployed_version_service"
|
|
31
31
|
require "pact_broker/deployments/released_version_service"
|
32
32
|
require "pact_broker/versions/branch_version_repository"
|
33
33
|
require "pact_broker/integrations/repository"
|
34
|
+
require "pact_broker/contracts/service"
|
35
|
+
|
34
36
|
require "ostruct"
|
35
37
|
|
36
38
|
module PactBroker
|
@@ -219,6 +221,27 @@ module PactBroker
|
|
219
221
|
self
|
220
222
|
end
|
221
223
|
|
224
|
+
def publish_pact(consumer_name:, provider_name:, consumer_version_number: , tags: nil, branch: nil, build_url: nil, json_content: nil)
|
225
|
+
json_content = json_content || random_json_content(consumer_name, provider_name)
|
226
|
+
contracts = [
|
227
|
+
PactBroker::Contracts::ContractToPublish.from_hash(consumer_name: consumer_name, provider_name: provider_name, decoded_content: json_content, content_type: "application/json", specification: "pact")
|
228
|
+
]
|
229
|
+
contracts_to_publish = PactBroker::Contracts::ContractsToPublish.from_hash(
|
230
|
+
pacticipant_name: consumer_name,
|
231
|
+
pacticipant_version_number: consumer_version_number,
|
232
|
+
tags: tags,
|
233
|
+
branch: branch,
|
234
|
+
build_url: build_url,
|
235
|
+
contracts: contracts
|
236
|
+
)
|
237
|
+
PactBroker::Contracts::Service.publish(contracts_to_publish, base_url: "http://example.org")
|
238
|
+
@consumer = find_pacticipant(consumer_name)
|
239
|
+
@consumer_version = find_version(consumer_name, consumer_version_number)
|
240
|
+
@provider = find_pacticipant(provider_name)
|
241
|
+
@pact = PactBroker::Pacts::PactPublication.last.to_domain
|
242
|
+
self
|
243
|
+
end
|
244
|
+
|
222
245
|
def create_pact params = {}
|
223
246
|
params.delete(:comment)
|
224
247
|
json_content = params[:json_content] || default_json_content
|
@@ -363,6 +386,7 @@ module PactBroker
|
|
363
386
|
end
|
364
387
|
|
365
388
|
def create_verification parameters = {}
|
389
|
+
# This should use the verification service. what a mess
|
366
390
|
parameters.delete(:comment)
|
367
391
|
branch = parameters.delete(:branch)
|
368
392
|
tag_names = [parameters.delete(:tag_names), parameters.delete(:tag_name)].flatten.compact
|
@@ -373,20 +397,23 @@ module PactBroker
|
|
373
397
|
parameters.delete(:provider_version)
|
374
398
|
verification = PactBroker::Domain::Verification.new(parameters)
|
375
399
|
pact_version = PactBroker::Pacts::Repository.new.find_pact_version(@consumer, @provider, pact.pact_version_sha)
|
376
|
-
@
|
377
|
-
@provider_version = PactBroker::Domain::Version.where(pacticipant_id: @provider.id, number: provider_version_number).single_record
|
400
|
+
@provider_version = version_repository.find_by_pacticipant_id_and_number_or_create(provider.id, provider_version_number)
|
378
401
|
PactBroker::Versions::BranchVersionRepository.new.add_branch(@provider_version, branch) if branch
|
379
402
|
|
380
|
-
set_created_at_if_set(parameters[:created_at], :verifications, id: @verification.id)
|
381
|
-
set_created_at_if_set(parameters[:created_at], :versions, id: @provider_version.id)
|
382
|
-
set_created_at_if_set(parameters[:created_at], :latest_verification_id_for_pact_version_and_provider_version, pact_version_id: pact_version_id, provider_version_id: @provider_version.id)
|
383
|
-
|
384
403
|
if tag_names.any?
|
385
404
|
tag_names.each do | tag_name |
|
386
|
-
PactBroker::Domain::Tag.new(name: tag_name, version: @provider_version).insert_ignore
|
405
|
+
PactBroker::Domain::Tag.new(name: tag_name, version: @provider_version, version_order: @provider_version.order).insert_ignore
|
387
406
|
set_created_at_if_set(parameters[:created_at], :tags, version_id: @provider_version.id, name: tag_name)
|
388
407
|
end
|
389
408
|
end
|
409
|
+
|
410
|
+
@verification = PactBroker::Verifications::Repository.new.create(verification, provider_version_number, pact_version)
|
411
|
+
|
412
|
+
set_created_at_if_set(parameters[:created_at], :verifications, id: @verification.id)
|
413
|
+
set_created_at_if_set(parameters[:created_at], :versions, id: @provider_version.id)
|
414
|
+
set_created_at_if_set(parameters[:created_at], :latest_verification_id_for_pact_version_and_provider_version, pact_version_id: pact_version_id, provider_version_id: @provider_version.id)
|
415
|
+
set_created_at_if_set(parameters[:created_at], :pact_version_provider_tag_successful_verifications, { verification_id: @verification.id }, :execution_date)
|
416
|
+
|
390
417
|
self
|
391
418
|
end
|
392
419
|
|
@@ -594,10 +621,10 @@ module PactBroker
|
|
594
621
|
PactBroker::Pacts::Content.from_json(json_content).with_ids(false).to_json
|
595
622
|
end
|
596
623
|
|
597
|
-
def set_created_at_if_set created_at, table_name, selector
|
624
|
+
def set_created_at_if_set created_at, table_name, selector, date_column_name = :created_at
|
598
625
|
date_to_set = created_at || @now
|
599
626
|
if date_to_set
|
600
|
-
Sequel::Model.db[table_name].where(selector).update(
|
627
|
+
Sequel::Model.db[table_name].where(selector).update(date_column_name => date_to_set)
|
601
628
|
if Sequel::Model.db.schema(table_name).any?{ |col| col.first == :updated_at }
|
602
629
|
Sequel::Model.db[table_name].where(selector.keys.first => selector.values.first).update(updated_at: date_to_set)
|
603
630
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "pact_broker/domain/verification"
|
2
|
+
|
3
|
+
# Represents a non WIP, successful verification for a provider version with a tag.
|
4
|
+
|
5
|
+
module PactBroker
|
6
|
+
module Verifications
|
7
|
+
class PactVersionProviderTagSuccessfulVerification < Sequel::Model
|
8
|
+
plugin :insert_ignore, identifying_columns: [:pact_version_id, :provider_version_tag_name, :wip]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -2,6 +2,7 @@ require "sequel"
|
|
2
2
|
require "pact_broker/domain/verification"
|
3
3
|
require "pact_broker/verifications/sequence"
|
4
4
|
require "pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version"
|
5
|
+
require "pact_broker/verifications/pact_version_provider_tag_successful_verification"
|
5
6
|
|
6
7
|
module PactBroker
|
7
8
|
module Verifications
|
@@ -27,6 +28,7 @@ module PactBroker
|
|
27
28
|
verification.tag_names = version.tag_names # TODO pass this in from contracts service
|
28
29
|
verification.save
|
29
30
|
update_latest_verification_id(verification)
|
31
|
+
update_pact_version_provider_tag_verifications(verification, version.tag_names)
|
30
32
|
verification
|
31
33
|
end
|
32
34
|
|
@@ -46,6 +48,20 @@ module PactBroker
|
|
46
48
|
LatestVerificationIdForPactVersionAndProviderVersion.new(params).upsert
|
47
49
|
end
|
48
50
|
|
51
|
+
def update_pact_version_provider_tag_verifications(verification, tag_names)
|
52
|
+
if verification.success
|
53
|
+
tag_names&.each do | tag_name |
|
54
|
+
PactVersionProviderTagSuccessfulVerification.new(
|
55
|
+
pact_version_id: verification.pact_version_id,
|
56
|
+
provider_version_tag_name: tag_name,
|
57
|
+
wip: verification.wip,
|
58
|
+
verification_id: verification.id,
|
59
|
+
execution_date: verification.execution_date
|
60
|
+
).insert_ignore
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
49
65
|
def find consumer_name, provider_name, pact_version_sha, verification_number
|
50
66
|
PactBroker::Domain::Verification
|
51
67
|
.select_all_qualified
|
data/lib/pact_broker/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.92.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-11-
|
13
|
+
date: 2021-11-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -587,6 +587,8 @@ files:
|
|
587
587
|
- db/migrations/20211102_create_table_temp_integrations.rb
|
588
588
|
- db/migrations/20211103_migrate_integrations.rb
|
589
589
|
- db/migrations/20211104_switch_integrations_and_temp_integrations.rb
|
590
|
+
- db/migrations/20211120_create_pact_version_provider_tag_successful_verifications.rb
|
591
|
+
- db/migrations/20211121_migrate_pact_version_provider_tag_successful_verifications_data.rb
|
590
592
|
- db/migrations/migration_helper.rb
|
591
593
|
- docs/CONFIGURATION.md
|
592
594
|
- docs/api/WEBHOOKS.md
|
@@ -797,6 +799,7 @@ files:
|
|
797
799
|
- lib/pact_broker/db/data_migrations/delete_deprecated_webhook_executions.rb
|
798
800
|
- lib/pact_broker/db/data_migrations/helpers.rb
|
799
801
|
- lib/pact_broker/db/data_migrations/migrate_integrations.rb
|
802
|
+
- lib/pact_broker/db/data_migrations/migrate_pact_version_provider_tag_successful_verifications.rb
|
800
803
|
- lib/pact_broker/db/data_migrations/migrate_webhook_headers.rb
|
801
804
|
- lib/pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications.rb
|
802
805
|
- lib/pact_broker/db/data_migrations/set_consumer_version_order_for_pact_publications.rb
|
@@ -1028,6 +1031,7 @@ files:
|
|
1028
1031
|
- lib/pact_broker/verifications/latest_verification_for_consumer_and_provider.rb
|
1029
1032
|
- lib/pact_broker/verifications/latest_verification_for_consumer_version_tag.rb
|
1030
1033
|
- lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb
|
1034
|
+
- lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.rb
|
1031
1035
|
- lib/pact_broker/verifications/placeholder_verification.rb
|
1032
1036
|
- lib/pact_broker/verifications/pseudo_branch_status.rb
|
1033
1037
|
- lib/pact_broker/verifications/repository.rb
|
@@ -1220,7 +1224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1220
1224
|
- !ruby/object:Gem::Version
|
1221
1225
|
version: '0'
|
1222
1226
|
requirements: []
|
1223
|
-
rubygems_version: 3.2.
|
1227
|
+
rubygems_version: 3.2.32
|
1224
1228
|
signing_key:
|
1225
1229
|
specification_version: 4
|
1226
1230
|
summary: See description
|