summaryrefslogtreecommitdiff
path: root/lib/release_highlights/validator.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /lib/release_highlights/validator.rb
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'lib/release_highlights/validator.rb')
-rw-r--r--lib/release_highlights/validator.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/release_highlights/validator.rb b/lib/release_highlights/validator.rb
new file mode 100644
index 00000000000..6f3f90b5f30
--- /dev/null
+++ b/lib/release_highlights/validator.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+module ReleaseHighlights
+ class Validator
+ attr_reader :errors, :file
+
+ def initialize(file:)
+ @file = file
+ @errors = []
+ end
+
+ def valid?
+ document = YAML.parse(File.read(file))
+
+ document.root.children.each do |entry|
+ entry = ReleaseHighlights::Validator::Entry.new(entry)
+
+ errors.push(entry.errors.full_messages) unless entry.valid?
+ end
+
+ errors.none?
+ end
+
+ def self.validate_all!
+ @all_errors = []
+
+ ReleaseHighlight.file_paths.each do |file_path|
+ instance = self.new(file: file_path)
+
+ @all_errors.push([instance.errors, instance.file]) unless instance.valid?
+ end
+
+ @all_errors.none?
+ end
+
+ def self.error_message
+ io = StringIO.new
+
+ @all_errors.each do |errors, file|
+ message = "Validation failed for #{file}"
+ line = -> { io.puts "-" * message.length }
+
+ line.call
+ io.puts message
+ line.call
+
+ errors.flatten.each { |error| io.puts "* #{error}" }
+ io.puts
+ end
+
+ io.string
+ end
+ end
+end