diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 18:09:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-13 18:09:21 +0300 |
commit | c36152ff8c41fad2f413f253eb7ac5c927e47c56 (patch) | |
tree | bbf300da207de3e8bbf272d44111ceedb18f5833 /app/models/concerns/ci | |
parent | 286fe61013674fe2d245ffc8d2233baf09923e70 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/ci')
-rw-r--r-- | app/models/concerns/ci/has_ref.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/concerns/ci/has_ref.rb b/app/models/concerns/ci/has_ref.rb new file mode 100644 index 00000000000..cf57ff47743 --- /dev/null +++ b/app/models/concerns/ci/has_ref.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +## +# We will disable `ref` and `sha` attributes in `Ci::Build` in the future +# and remove this module in favor of Ci::PipelineDelegator. +module Ci + module HasRef + extend ActiveSupport::Concern + + def branch? + !tag? && !merge_request? + end + + def git_ref + if branch? + Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s + elsif tag? + Gitlab::Git::TAG_REF_PREFIX + ref.to_s + end + end + + # A slugified version of the build ref, suitable for inclusion in URLs and + # domain names. Rules: + # + # * Lowercased + # * Anything not matching [a-z0-9-] is replaced with a - + # * Maximum length is 63 bytes + # * First/Last Character is not a hyphen + def ref_slug + Gitlab::Utils.slugify(ref.to_s) + end + end +end |