Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-07-10 13:10:54 +0300
committerRémy Coutable <remy@rymai.me>2018-07-11 12:52:03 +0300
commitab87e7bab1d5cc20c7b69644843bfcb1f3f16918 (patch)
tree2f908718378fbe6984d65781ea76c623ace57eb6 /danger/database
parentdc629bb6b8146477fdbf9fcd11d10ebedc785029 (diff)
Improve Danger files after first review
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'danger/database')
-rw-r--r--danger/database/Dangerfile41
1 files changed, 28 insertions, 13 deletions
diff --git a/danger/database/Dangerfile b/danger/database/Dangerfile
index 136dcef7972..4759ceb7eb4 100644
--- a/danger/database/Dangerfile
+++ b/danger/database/Dangerfile
@@ -1,16 +1,31 @@
# rubocop:disable Style/SignalException
-db_schema_updated = !git.modified_files.grep(%r{\A(ee/)?(db/(geo/)?(post_)?migrate)/}).empty?
-migration_created = !git.added_files.grep(%r{\A(db/(post_)?migrate)/}).empty?
-geo_migration_created = !git.added_files.grep(%r{\Aee/(db/geo/(post_)?migrate)/}).empty?
-
-if (migration_created || geo_migration_created) && !db_schema_updated
- msg = ["New migrations were added but #{gitlab.html_link("db/schema.rb")}"]
- msg << "(nor #{gitlab.html_link("ee/db/geo/schema.rb")})" if geo_migration_created
- msg << "wasn't. Usually, when adding new migrations, #{gitlab.html_link("db/schema.rb")}"
- msg << "(and #{gitlab.html_link("ee/db/geo/schema.rb")})" if geo_migration_created
- msg << "should be updated too (unless your migrations are data migrations and your"
- msg << "migration isn't the most recent one)."
-
- warn msg.join(" ")
+ANY_MIGRATIONS_REGEX = %r{\A(ee/)?(db/(geo/)?(post_)?migrate)/}
+SCHEMA_NOT_UPDATED_MESSAGE = <<~MSG
+**New %<migrations>s added but %<schema>s wasn't updated.**
+
+Usually, when adding new %<migrations>s, %<schema>s should be
+updated too (unless the migration isn't changing the DB schema
+and isn't the most recent one).
+MSG
+
+non_geo_db_schema_updated = !git.modified_files.grep(%r{\Adb/schema\.rb/}).empty?
+geo_db_schema_updated = !git.modified_files.grep(%r{\Aee/db/geo/schema\.rb/}).empty?
+
+any_migration_created = !git.added_files.grep(ANY_MIGRATIONS_REGEX).empty?
+any_migration_updated = !git.modified_files.grep(ANY_MIGRATIONS_REGEX).empty?
+
+non_geo_migration_created = !git.added_files.grep(%r{\A(db/(post_)?migrate)/}).empty?
+geo_migration_created = !git.added_files.grep(%r{\Aee/db/geo/(post_)?migrate/}).empty?
+
+if any_migration_created || any_migration_updated || non_geo_db_schema_updated || geo_db_schema_updated
+ message "Please make sure to ask a Database engineer for a review."
+end
+
+if non_geo_migration_created && !non_geo_db_schema_updated
+ warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'migrations', schema: gitlab.html_link("db/schema.rb"))
+end
+
+if geo_migration_created && !geo_db_schema_updated
+ warn format(SCHEMA_NOT_UPDATED_MESSAGE, migrations: 'Geo migrations', schema: gitlab.html_link("ee/db/geo/schema.rb"))
end