2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
module Gitlab
|
|
|
|
module Checks
|
|
|
|
class ChangeAccess
|
2018-12-23 12:14:25 +05:30
|
|
|
ATTRIBUTES = %i[user_access project skip_authorization
|
|
|
|
skip_lfs_integrity_check protocol oldrev newrev ref
|
|
|
|
branch_name tag_name logger commits].freeze
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
attr_reader(*ATTRIBUTES)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def initialize(
|
|
|
|
change, user_access:, project:, skip_authorization: false,
|
2018-12-13 13:39:08 +05:30
|
|
|
skip_lfs_integrity_check: false, protocol:, logger:
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
2016-09-13 17:45:13 +05:30
|
|
|
@oldrev, @newrev, @ref = change.values_at(:oldrev, :newrev, :ref)
|
|
|
|
@branch_name = Gitlab::Git.branch_name(@ref)
|
2017-08-17 22:00:37 +05:30
|
|
|
@tag_name = Gitlab::Git.tag_name(@ref)
|
2016-08-24 12:49:21 +05:30
|
|
|
@user_access = user_access
|
|
|
|
@project = project
|
2017-08-17 22:00:37 +05:30
|
|
|
@skip_authorization = skip_authorization
|
2018-03-17 18:26:18 +05:30
|
|
|
@skip_lfs_integrity_check = skip_lfs_integrity_check
|
2017-08-17 22:00:37 +05:30
|
|
|
@protocol = protocol
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
@logger = logger
|
|
|
|
@logger.append_message("Running checks for ref: #{@branch_name || @tag_name}")
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def exec
|
2017-09-10 17:25:29 +05:30
|
|
|
return true if skip_authorization
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
ref_level_checks
|
|
|
|
# Check of commits should happen as the last step
|
|
|
|
# given they're expensive in terms of performance
|
|
|
|
commits_check
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
true
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def commits
|
|
|
|
@commits ||= project.repository.new_commits(newrev)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
protected
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
def ref_level_checks
|
|
|
|
Gitlab::Checks::PushCheck.new(self).validate!
|
|
|
|
Gitlab::Checks::BranchCheck.new(self).validate!
|
|
|
|
Gitlab::Checks::TagCheck.new(self).validate!
|
|
|
|
Gitlab::Checks::LfsCheck.new(self).validate!
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def commits_check
|
2018-12-23 12:14:25 +05:30
|
|
|
Gitlab::Checks::DiffCheck.new(self).validate!
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|