debian-mirror-gitlab/lib/gitlab/ci/pipeline/chain/command.rb

65 lines
1.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# rubocop:disable Naming/FileName
# 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,
:origin_ref, :checkout_sha, :after_sha, :before_sha,
2018-12-23 12:14:25 +05:30
:trigger_request, :schedule, :merge_request,
2018-03-17 18:26:18 +05:30
:ignore_skip_ci, :save_incompleted,
2018-10-15 14:42:47 +05:30
:seeds_block, :variables_attributes
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
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
project.protected_for?(ref)
end
end
end
end
end
end
end