2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
2018-03-17 18:26:18 +05:30
|
|
|
module Ci
|
|
|
|
module Pipeline
|
|
|
|
module Chain
|
|
|
|
Command = Struct.new(
|
|
|
|
:source, :project, :current_user,
|
2019-07-07 11:18:12 +05:30
|
|
|
:origin_ref, :checkout_sha, :after_sha, :before_sha, :source_sha, :target_sha,
|
2019-12-04 20:38:33 +05:30
|
|
|
:trigger_request, :schedule, :merge_request, :external_pull_request,
|
2018-03-17 18:26:18 +05:30
|
|
|
:ignore_skip_ci, :save_incompleted,
|
2019-07-07 11:18:12 +05:30
|
|
|
:seeds_block, :variables_attributes, :push_options,
|
2020-07-28 23:09:34 +05:30
|
|
|
:chat_data, :allow_mirror_update, :bridge, :content,
|
2019-12-26 22:10:19 +05:30
|
|
|
# These attributes are set by Chains during processing:
|
|
|
|
:config_content, :config_processor, :stage_seeds
|
2018-03-17 18:26:18 +05:30
|
|
|
) do
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def initialize(**params)
|
|
|
|
params.each do |key, value|
|
|
|
|
self[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_exists?
|
|
|
|
strong_memoize(:is_branch) do
|
|
|
|
project.repository.branch_exists?(ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_exists?
|
|
|
|
strong_memoize(:is_tag) do
|
|
|
|
project.repository.tag_exists?(ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def merge_request_ref_exists?
|
|
|
|
strong_memoize(:merge_request_ref_exists) do
|
|
|
|
MergeRequest.merge_request_ref?(origin_ref) &&
|
|
|
|
project.repository.ref_exists?(origin_ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def ref
|
|
|
|
strong_memoize(:ref) do
|
|
|
|
Gitlab::Git.ref_name(origin_ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sha
|
|
|
|
strong_memoize(:sha) do
|
|
|
|
project.commit(origin_sha || origin_ref).try(:id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def origin_sha
|
|
|
|
checkout_sha || after_sha
|
|
|
|
end
|
|
|
|
|
|
|
|
def before_sha
|
|
|
|
self[:before_sha] || checkout_sha || Gitlab::Git::BLANK_SHA
|
|
|
|
end
|
|
|
|
|
|
|
|
def protected_ref?
|
|
|
|
strong_memoize(:protected_ref) do
|
2019-01-03 12:48:30 +05:30
|
|
|
project.protected_for?(origin_ref)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ambiguous_ref?
|
|
|
|
strong_memoize(:ambiguous_ref) do
|
|
|
|
project.repository.ambiguous_ref?(origin_ref)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def parent_pipeline
|
|
|
|
bridge&.parent_pipeline
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def metrics
|
2020-07-28 23:09:34 +05:30
|
|
|
@metrics ||= ::Gitlab::Ci::Pipeline::Metrics.new
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def observe_creation_duration(duration)
|
2020-06-23 00:09:42 +05:30
|
|
|
metrics.pipeline_creation_duration_histogram
|
|
|
|
.observe({}, duration.seconds)
|
|
|
|
end
|
|
|
|
|
|
|
|
def observe_pipeline_size(pipeline)
|
|
|
|
metrics.pipeline_size_histogram
|
|
|
|
.observe({ source: pipeline.source.to_s }, pipeline.total_size)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
def dangling_build?
|
|
|
|
%i[ondemand_dast_scan webide].include?(source)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|