2018-12-04 06:55:49 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Checks
|
|
|
|
class BaseChecker
|
2019-09-13 09:26:31 -04:00
|
|
|
prepend_if_ee('EE::Gitlab::Checks::BaseChecker') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
2018-12-04 06:55:49 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
attr_reader :change_access
|
|
|
|
delegate(*ChangeAccess::ATTRIBUTES, to: :change_access)
|
|
|
|
|
|
|
|
def initialize(change_access)
|
|
|
|
@change_access = change_access
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate!
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-20 11:45:06 -05:00
|
|
|
def creation?
|
|
|
|
Gitlab::Git.blank_ref?(oldrev)
|
|
|
|
end
|
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
def deletion?
|
|
|
|
Gitlab::Git.blank_ref?(newrev)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2018-12-20 11:45:06 -05:00
|
|
|
!creation? && !deletion?
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def updated_from_web?
|
|
|
|
protocol == 'web'
|
|
|
|
end
|
|
|
|
|
|
|
|
def tag_exists?
|
|
|
|
project.repository.tag_exists?(tag_name)
|
|
|
|
end
|
2018-12-28 05:44:25 -05:00
|
|
|
|
|
|
|
def validate_once(resource)
|
|
|
|
Gitlab::SafeRequestStore.fetch(cache_key_for_resource(resource)) do
|
|
|
|
yield(resource)
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_key_for_resource(resource)
|
|
|
|
"git_access:#{checker_cache_key}:#{resource.cache_key}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def checker_cache_key
|
|
|
|
self.class.name.demodulize.underscore
|
|
|
|
end
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|