Module: Gitlab::Ci::Lint

Defined in:
lib/gitlab/ci/lint.rb,
lib/gitlab/ci/lint/version.rb

Constant Summary collapse

VERSION =
"0.1.6".freeze

Class Method Summary collapse

Class Method Details

.validate(values, configuration, options) ⇒ Object



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
# File 'lib/gitlab/ci/lint.rb', line 9

def self.validate values, configuration, options
  system = GitLab::CI::Lint::System.new
  actions = GitLab::CI::Lint::Actions.new

  system.file_exist?(values, "Error: You must specify the values.yml file")

  values = File.absolute_path(values)

  system.file_is_readable?(values, "Error: Could not find file at '#{values}'")

  yml_reader = GitLab::CI::Lint::YMLReader.new(values)
  content = yml_reader.get_content

  gitlab = content["gitlab"]

  logger = GitLab::CI::Lint::Log.instance

  gitlab_endpoint = options["endpoint"] ?
      options["endpoint"] : ((!gitlab["endpoint"].to_s.empty? && !gitlab["endpoint"].nil?) ?
      gitlab["endpoint"] : configuration.gitlab_endpoint)

  gitlab_token = options["token"] ?
      options["token"] : ((!gitlab["token"].to_s.empty? && !gitlab["token"].nil?) ?
      gitlab["token"] : configuration.gitlab_token)

  timeout = options["timeout"] ?
      options["timeout"] : ((!gitlab["timeout"].to_s.empty? && !gitlab["timeout"].nil?) ?
      gitlab["timeout"] : configuration.timeout)

  gitlab_ci_file = options["file"] ?
      options["file"] : ((!gitlab["file"].to_s.empty? && !gitlab["file"].nil?) ?
      gitlab["file"] : configuration.gitlab_ci_file)

  logger.info("Starting GitLab CI YML Validation...")

  headers = gitlab_token ? { "Content-Type" => "application/json", "Private-Token" => gitlab_token } : { "Content-Type" => "application/json" }

  actions.validate_gitlab_ci_yml(gitlab_endpoint, gitlab_ci_file, headers, timeout)

  return 0
end