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
path: root/danger
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-05 12:12:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-05 12:12:42 +0300
commit2a134be97dafb4743eee8fc908463136ddf23b1f (patch)
tree43ce3854f0a69a5938db1a56abc20cdce3517a52 /danger
parent7c0c3a7dc95668d20ec8f4bbc2d505f373b6032a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'danger')
-rw-r--r--danger/ci_tables/Dangerfile32
-rw-r--r--danger/plugins/database_dictionary.rb10
2 files changed, 42 insertions, 0 deletions
diff --git a/danger/ci_tables/Dangerfile b/danger/ci_tables/Dangerfile
new file mode 100644
index 00000000000..1d4601d33b2
--- /dev/null
+++ b/danger/ci_tables/Dangerfile
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+SEE_DB_DOC = "See the [database dictionary documentation](https://docs.gitlab.com/ee/development/database/database_dictionary.html)."
+
+PARTITIONING_COMMENT = <<~SUGGEST_COMMENT
+When adding new CI tables, consider [partitioning](https://docs.gitlab.com/ee/development/cicd/cicd_tables.html) the table
+from the start if it references any of the larger CI tables: `ci_pipelines`, `ci_stages`, `ci_builds`, `p_ci_builds_metadata`, `ci_job_artifacts`, `ci_pipeline_variables`.
+SUGGEST_COMMENT
+
+def check_database_dictionary_yaml(database_dictionary)
+ return unless database_dictionary.ci_schema?
+ # `p_` prefix is used by the partitioned tables, so we can assume that the table is already partitioned
+ return if database_dictionary.table_name.to_s.start_with?('p_')
+
+ mr_line = database_dictionary.raw.lines.find_index { |line| line.start_with?('table_name:') }
+ return unless mr_line
+
+ markdown(PARTITIONING_COMMENT, file: database_dictionary.path, line: mr_line.succ)
+rescue Psych::Exception
+ # YAML could not be parsed, fail the build.
+ fail "#{helper.html_link(database_ditionary.path)} isn't valid YAML! #{SEE_DB_DOC}" # rubocop:disable Style/SignalException
+rescue StandardError => e
+ warn "There was a problem trying to check the database dictionary file. Exception: #{e.class.name} - #{e.message}"
+end
+
+def added_database_dictionary_files
+ database_dictionary.database_dictionary_files(change_type: :added)
+end
+
+added_database_dictionary_files.each do |database_dictionary|
+ check_database_dictionary_yaml(database_dictionary)
+end
diff --git a/danger/plugins/database_dictionary.rb b/danger/plugins/database_dictionary.rb
new file mode 100644
index 00000000000..b6a3c320891
--- /dev/null
+++ b/danger/plugins/database_dictionary.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+require_relative '../../tooling/danger/database_dictionary'
+
+module Danger
+ class DatabaseDictionary < Plugin
+ # Put the helper code somewhere it can be tested
+ include Tooling::Danger::DatabaseDictionary
+ end
+end