diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-12-08 13:35:36 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-12-08 14:01:15 +0300 |
commit | ad3be46b9fe7d6d42b30d257a923b0070f79da94 (patch) | |
tree | 6684c983fb05c6bccdf88f4da62f5c9f74b17010 /lib/gitlab/ci/pipeline/chain/command.rb | |
parent | b30e0e0691716c2ef0b858b81dd5cef8d4728c59 (diff) |
Implement and use Gitlab::Ci::Pipeline::Chain::Command
Diffstat (limited to 'lib/gitlab/ci/pipeline/chain/command.rb')
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/command.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/command.rb b/lib/gitlab/ci/pipeline/chain/command.rb new file mode 100644 index 00000000000..f74235d8452 --- /dev/null +++ b/lib/gitlab/ci/pipeline/chain/command.rb @@ -0,0 +1,65 @@ +module Gitlab + module Ci + module Pipeline + module Chain + Command = Struct.new( + :source, :project, :current_user, + :origin_ref, :checkout_sha, :after_sha, :before_sha, + :trigger_request, :schedule, + :ignore_skip_ci, :save_incompleted, + :seeds_block + ) 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 + checkout_sha || before_sha || Gitlab::Git::BLANK_SHA + end + + def protected_ref? + strong_memoize(:protected_ref) do + project.protected_for?(ref) + end + end + + def error(message) + pipeline.errors.add(:base, message) + end + end + end + end + end +end |