debian-mirror-gitlab/app/models/ci/persistent_ref.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
976 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
module Ci
##
# The persistent pipeline ref to ensure runners can safely fetch source code
# even if force-push/source-branch-deletion happens.
class PersistentRef
include ActiveModel::Model
attr_accessor :pipeline
delegate :project, :sha, to: :pipeline
delegate :repository, to: :project
delegate :ref_exists?, :create_ref, :delete_refs, to: :repository
def exist?
ref_exists?(path)
2021-06-08 01:23:25 +05:30
rescue StandardError
2019-12-21 20:55:43 +05:30
false
end
def create
create_ref(sha, path)
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2020-01-01 13:55:28 +05:30
Gitlab::ErrorTracking
.track_exception(e, pipeline_id: pipeline.id)
2019-12-21 20:55:43 +05:30
end
def delete
delete_refs(path)
rescue Gitlab::Git::Repository::NoRepository
# no-op
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2020-01-01 13:55:28 +05:30
Gitlab::ErrorTracking
.track_exception(e, pipeline_id: pipeline.id)
2019-12-21 20:55:43 +05:30
end
def path
"refs/#{Repository::REF_PIPELINES}/#{pipeline.id}"
end
end
end