summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/chain/config/content.rb
blob: d41213ef6dde3ebc38ac2ce52b6a01d34235cc16 (plain)
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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Chain
        module Config
          class Content < Chain::Base
            include Chain::Helpers
            include ::Gitlab::Utils::StrongMemoize

            def perform!
              if pipeline_config&.exists?
                @pipeline.build_pipeline_config(content: pipeline_config.content)
                @command.config_content = pipeline_config.content
                @pipeline.config_source = pipeline_config.source
              else
                error('Missing CI config file')
              end
            end

            def break?
              @pipeline.errors.any? || @pipeline.persisted?
            end

            private

            def pipeline_config
              strong_memoize(:pipeline_config) do
                ::Gitlab::Ci::ProjectConfig.new(
                  project: project, sha: @pipeline.sha,
                  custom_content: @command.content,
                  pipeline_source: @command.source, pipeline_source_bridge: @command.bridge
                )
              end
            end
          end
        end
      end
    end
  end
end