2018-10-11 20:12:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-18 08:16:56 +00:00
|
|
|
module Gitlab
|
|
|
|
module Checks
|
|
|
|
class ChangeAccess
|
2018-12-04 11:55:49 +00: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 23:13:36 +00:00
|
|
|
|
2018-12-04 11:55:49 +00:00
|
|
|
attr_reader(*ATTRIBUTES)
|
2016-07-18 08:16:56 +00:00
|
|
|
|
2016-11-17 19:48:23 +00:00
|
|
|
def initialize(
|
2018-12-20 16:39:20 +00:00
|
|
|
change, user_access:, project:,
|
2018-10-22 14:49:20 +00:00
|
|
|
skip_lfs_integrity_check: false, protocol:, logger:
|
2017-03-13 11:31:27 +00:00
|
|
|
)
|
2016-07-28 04:04:57 +00:00
|
|
|
@oldrev, @newrev, @ref = change.values_at(:oldrev, :newrev, :ref)
|
|
|
|
@branch_name = Gitlab::Git.branch_name(@ref)
|
2017-03-31 16:57:29 +00:00
|
|
|
@tag_name = Gitlab::Git.tag_name(@ref)
|
2016-07-18 08:16:56 +00:00
|
|
|
@user_access = user_access
|
|
|
|
@project = project
|
2018-02-13 19:33:13 +00:00
|
|
|
@skip_lfs_integrity_check = skip_lfs_integrity_check
|
2017-03-13 11:31:27 +00:00
|
|
|
@protocol = protocol
|
2018-10-22 14:49:20 +00:00
|
|
|
|
|
|
|
@logger = logger
|
2018-10-25 08:49:59 +00:00
|
|
|
@logger.append_message("Running checks for ref: #{@branch_name || @tag_name}")
|
2016-07-18 08:16:56 +00:00
|
|
|
end
|
|
|
|
|
2018-12-04 11:55:49 +00: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 08:16:56 +00:00
|
|
|
|
2017-05-23 19:21:57 +00:00
|
|
|
true
|
2016-07-18 08:16:56 +00:00
|
|
|
end
|
|
|
|
|
2018-12-04 11:55:49 +00:00
|
|
|
def commits
|
|
|
|
@commits ||= project.repository.new_commits(newrev)
|
2017-03-31 16:57:29 +00:00
|
|
|
end
|
|
|
|
|
2018-12-04 11:55:49 +00:00
|
|
|
protected
|
2017-03-31 16:57:29 +00:00
|
|
|
|
2018-12-04 11:55:49 +00: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 16:57:29 +00:00
|
|
|
end
|
|
|
|
|
2018-02-07 13:00:53 +00:00
|
|
|
def commits_check
|
2018-12-04 11:55:49 +00:00
|
|
|
Gitlab::Checks::DiffCheck.new(self).validate!
|
2018-03-06 22:30:47 +00:00
|
|
|
end
|
2016-07-18 08:16:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 12:09:44 +00:00
|
|
|
|
|
|
|
Gitlab::Checks::ChangeAccess.prepend_if_ee('EE::Gitlab::Checks::ChangeAccess')
|