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/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-26 12:10:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-26 12:10:25 +0300
commite2cf652edb5e9d9fa9a081952070074c07bf651e (patch)
tree43df576f4a9287977a95b2e3b6128175c16b7298 /lib
parent5a61836cf3492bcf3c1f865de66c2f2e61e37866 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/gitlab/audit_event_types/audit_event_types.rake28
-rw-r--r--lib/tasks/gitlab/audit_event_types/check_docs_task.rb34
-rw-r--r--lib/tasks/gitlab/audit_event_types/compile_docs_task.rb22
3 files changed, 84 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/audit_event_types/audit_event_types.rake b/lib/tasks/gitlab/audit_event_types/audit_event_types.rake
new file mode 100644
index 00000000000..289f79568a9
--- /dev/null
+++ b/lib/tasks/gitlab/audit_event_types/audit_event_types.rake
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+return if Rails.env.production?
+
+namespace :gitlab do
+ namespace :audit_event_types do
+ event_types_dir = Rails.root.join("doc/administration/audit_event_streaming")
+ event_types_doc_file = Rails.root.join(event_types_dir, 'audit_event_types.md')
+ template_directory = 'tooling/audit_events/docs/templates/'
+ template_erb_file_path = Rails.root.join(template_directory, 'audit_event_types.md.erb')
+
+ desc 'GitLab | Audit event types | Generate audit event types docs'
+ task compile_docs: :environment do
+ require_relative './compile_docs_task'
+
+ Tasks::Gitlab::AuditEventTypes::CompileDocsTask
+ .new(event_types_dir, event_types_doc_file, template_erb_file_path).run
+ end
+
+ desc 'GitLab | Audit event types | Check if Audit event types docs are up to date'
+ task check_docs: :environment do
+ require_relative './check_docs_task'
+
+ Tasks::Gitlab::AuditEventTypes::CheckDocsTask
+ .new(event_types_dir, event_types_doc_file, template_erb_file_path).run
+ end
+ end
+end
diff --git a/lib/tasks/gitlab/audit_event_types/check_docs_task.rb b/lib/tasks/gitlab/audit_event_types/check_docs_task.rb
new file mode 100644
index 00000000000..f62dd116ed1
--- /dev/null
+++ b/lib/tasks/gitlab/audit_event_types/check_docs_task.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Tasks
+ module Gitlab
+ module AuditEventTypes
+ class CheckDocsTask
+ def initialize(docs_dir, docs_path, template_erb_path)
+ @event_types_dir = docs_dir
+ @audit_event_types_doc_file = docs_path
+ @event_type_erb_template = ERB.new(File.read(template_erb_path), trim_mode: '<>')
+ end
+
+ def run
+ doc = File.read(@audit_event_types_doc_file)
+
+ if doc == @event_type_erb_template.result
+ puts "Audit event types documentation is up to date."
+ else
+ error_message = "Audit event types documentation is outdated! Please update it by running " \
+ "`bundle exec rake gitlab:audit_event_types:compile_docs`."
+ heading = '#' * 10
+ puts heading
+ puts '#'
+ puts "# #{error_message}"
+ puts '#'
+ puts heading
+
+ abort
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/tasks/gitlab/audit_event_types/compile_docs_task.rb b/lib/tasks/gitlab/audit_event_types/compile_docs_task.rb
new file mode 100644
index 00000000000..ffa4f6d3514
--- /dev/null
+++ b/lib/tasks/gitlab/audit_event_types/compile_docs_task.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Tasks
+ module Gitlab
+ module AuditEventTypes
+ class CompileDocsTask
+ def initialize(docs_dir, docs_path, template_erb_path)
+ @event_types_dir = docs_dir
+ @audit_event_types_doc_file = docs_path
+ @event_type_erb_template = ERB.new(File.read(template_erb_path), trim_mode: '<>')
+ end
+
+ def run
+ FileUtils.mkdir_p(@event_types_dir)
+ File.write(@audit_event_types_doc_file, @event_type_erb_template.result)
+
+ puts "Documentation compiled."
+ end
+ end
+ end
+ end
+end