2018-10-11 16:12:21 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-18 04:16:56 -04:00
|
|
|
module Gitlab
|
|
|
|
module Checks
|
|
|
|
class ChangeAccess
|
2019-09-13 09:26:31 -04:00
|
|
|
prepend_if_ee('EE::Gitlab::Checks::ChangeAccess') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
ATTRIBUTES = %i[user_access project skip_authorization
|
|
|
|
skip_lfs_integrity_check protocol oldrev newrev ref
|
|
|
|
branch_name tag_name logger commits].freeze
|
2017-05-15 19:13:36 -04:00
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
attr_reader(*ATTRIBUTES)
|
2016-07-18 04:16:56 -04:00
|
|
|
|
2016-11-17 14:48:23 -05:00
|
|
|
def initialize(
|
2018-12-20 11:39:20 -05:00
|
|
|
change, user_access:, project:,
|
2018-10-22 10:49:20 -04:00
|
|
|
skip_lfs_integrity_check: false, protocol:, logger:
|
2017-03-13 07:31:27 -04:00
|
|
|
)
|
2016-07-28 00:04:57 -04:00
|
|
|
@oldrev, @newrev, @ref = change.values_at(:oldrev, :newrev, :ref)
|
|
|
|
@branch_name = Gitlab::Git.branch_name(@ref)
|
2017-03-31 12:57:29 -04:00
|
|
|
@tag_name = Gitlab::Git.tag_name(@ref)
|
2016-07-18 04:16:56 -04:00
|
|
|
@user_access = user_access
|
|
|
|
@project = project
|
2018-02-13 14:33:13 -05:00
|
|
|
@skip_lfs_integrity_check = skip_lfs_integrity_check
|
2017-03-13 07:31:27 -04:00
|
|
|
@protocol = protocol
|
2018-10-22 10:49:20 -04:00
|
|
|
|
|
|
|
@logger = logger
|
2018-10-25 04:49:59 -04:00
|
|
|
@logger.append_message("Running checks for ref: #{@branch_name || @tag_name}")
|
2016-07-18 04:16:56 -04:00
|
|
|
end
|
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
def exec
|
|
|
|
ref_level_checks
|
|
|
|
# Check of commits should happen as the last step
|
|
|
|
# given they're expensive in terms of performance
|
|
|
|
commits_check
|
2016-07-18 04:16:56 -04:00
|
|
|
|
2017-05-23 15:21:57 -04:00
|
|
|
true
|
2016-07-18 04:16:56 -04:00
|
|
|
end
|
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
def commits
|
|
|
|
@commits ||= project.repository.new_commits(newrev)
|
2017-03-31 12:57:29 -04:00
|
|
|
end
|
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
protected
|
2017-03-31 12:57:29 -04:00
|
|
|
|
2018-12-04 06:55:49 -05:00
|
|
|
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!
|
2017-03-31 12:57:29 -04:00
|
|
|
end
|
|
|
|
|
2018-02-07 08:00:53 -05:00
|
|
|
def commits_check
|
2018-12-04 06:55:49 -05:00
|
|
|
Gitlab::Checks::DiffCheck.new(self).validate!
|
2018-03-06 17:30:47 -05:00
|
|
|
end
|
2016-07-18 04:16:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|