-
Notifications
You must be signed in to change notification settings - Fork 926
/
Copy pathvalidate-contributors.rb
executable file
·52 lines (42 loc) · 1.5 KB
/
validate-contributors.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'yaml'
require 'kwalify'
require './bin/gtn'
# Any error messages
CONTRIBUTORS_SCHEMA_UNSAFE = YAML.load_file('bin/schema-contributors.yaml')
CONTRIBUTORS_SCHEMA = automagic_loading(CONTRIBUTORS_SCHEMA_UNSAFE)
contribs_validator = Kwalify::Validator.new(CONTRIBUTORS_SCHEMA)
GRANTS_SCHEMA_UNSAFE = YAML.load_file('bin/schema-grants.yaml')
GRANTS_SCHEMA = automagic_loading(GRANTS_SCHEMA_UNSAFE)
grants_validator = Kwalify::Validator.new(GRANTS_SCHEMA)
ORGANISATIONS_SCHEMA_UNSAFE = YAML.load_file('bin/schema-organisations.yaml')
ORGANISATIONS_SCHEMA = automagic_loading(ORGANISATIONS_SCHEMA_UNSAFE)
organisations_validator = Kwalify::Validator.new(ORGANISATIONS_SCHEMA)
def validate_document(document, validator)
errors = validator.validate(document)
return errors if errors && !errors.empty?
[]
end
def show_errors(file, errs)
# If we had no errors, validated successfully
if errs.empty?
puts "\e[38;5;40m#{file} validated succesfully\e[m"
0
else
# Otherwise, print errors and exit non-zero
puts "\e[48;5;09m#{file} has errors\e[m"
errs.each { |x| puts " #{x}" }
1
end
end
ec = 0
# This variable from bin/gtn.rb
errs = validate_document(CONTRIBUTORS, contribs_validator)
ec |= show_errors('CONTRIBUTORS.yaml', errs)
errs = validate_document(GRANTS, grants_validator)
ec |= show_errors('GRANTS.yaml', errs)
errs = validate_document(ORGANISATIONS, organisations_validator)
ec | show_errors('ORGANISATIONS.yaml', errs)
# Exit
exit ec