summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/chain/validate/repository.rb
blob: 3cec55cdb7172c6a3dc8df7cd6cd71f328dc1ebb (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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Chain
        module Validate
          class Repository < Chain::Base
            include Chain::Helpers

            def perform!
              unless @command.branch_exists? || @command.tag_exists?
                return error('Reference not found')
              end

              unless @command.sha
                return error('Commit not found')
              end

              begin
                @command.project.resolve_ref(@command.origin_ref)
              rescue Project::AmbiguousRef
                return error('Ref is ambiguous')
              end
            end

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