Commit 538e0cb1 authored by Mayra Cabrera's avatar Mayra Cabrera 0️⃣ Committed by Grzegorz Bizon
Browse files

20868 - Includes External Files in Gitlab CI YML

parent a78ed649
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -8,16 +8,16 @@ class GitlabCiYml < Base
    self.file_types = %i(gitlab_ci)
    self.binary = false

    def validation_message
    def validation_message(project, sha)
      return @validation_message if defined?(@validation_message)

      prepare!

      @validation_message = Gitlab::Ci::YamlProcessor.validation_message(blob.data)
      @validation_message = Gitlab::Ci::YamlProcessor.validation_message(blob.data, { project: project, sha: sha })
    end

    def valid?
      validation_message.blank?
    def valid?(project, sha)
      validation_message(project, sha).blank?
    end
  end
end
+5 −1
Original line number Diff line number Diff line
@@ -406,7 +406,7 @@ def config_processor
      return @config_processor if defined?(@config_processor)

      @config_processor ||= begin
        Gitlab::Ci::YamlProcessor.new(ci_yaml_file)
        initialize_yaml_processor
      rescue Gitlab::Ci::YamlProcessor::ValidationError, Psych::SyntaxError => e
        self.yaml_errors = e.message
        nil
@@ -416,6 +416,10 @@ def config_processor
      end
    end

    def initialize_yaml_processor
      Gitlab::Ci::YamlProcessor.new(ci_yaml_file)
    end

    def ci_yaml_file_path
      if project.ci_config_path.blank?
        '.gitlab-ci.yml'
+8 −8
Original line number Diff line number Diff line
@@ -1061,6 +1061,14 @@ def rebase(user, merge_request)
                                       remote_branch: merge_request.target_branch)
  end

  def blob_data_at(sha, path)
    blob = blob_at(sha, path)
    return unless blob

    blob.load_all_data!
    blob.data
  end

  private

  # TODO Generice finder, later split this on finders by Ref or Oid
@@ -1075,14 +1083,6 @@ def find_commit(oid_or_ref)
    ::Commit.new(commit, @project) if commit
  end

  def blob_data_at(sha, path)
    blob = blob_at(sha, path)
    return unless blob

    blob.load_all_data!
    blob.data
  end

  def cache
    # TODO: should we use UUIDs here? We could move repositories without clearing this cache
    @cache ||= RepositoryCache.new(full_path, @project.id)
+2 −2
Original line number Diff line number Diff line
- if viewer.valid?
- if viewer.valid?(@project, @commit.sha)
  = icon('check fw')
  This GitLab CI configuration is valid.
- else
  = icon('warning fw')
  This GitLab CI configuration is invalid:
  = viewer.validation_message
  = viewer.validation_message(@project, @commit.sha)

= link_to 'Learn more', help_page_path('ci/yaml/README')
+5 −0
Original line number Diff line number Diff line
---
title: Dry up CI/CD gitlab-ci.yml configuration by allowing inclusion of external files
merge_request: 4262
author:
type: added
Loading