debian-mirror-gitlab/lib/gitlab/checks/change_access.rb

56 lines
1.5 KiB
Ruby
Raw Normal View History

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
2019-02-13 22:33:31 +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
2019-02-13 22:33:31 +05:30
attr_reader(*ATTRIBUTES)
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
def initialize(
2019-02-13 22:33:31 +05:30
change, user_access:, project:,
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
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
2019-02-13 22:33:31 +05:30
def exec
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
2019-02-13 22:33:31 +05:30
def commits
@commits ||= project.repository.new_commits(newrev)
2019-01-03 12:48:30 +05:30
end
2019-02-13 22:33:31 +05:30
protected
2019-01-03 12:48:30 +05:30
2019-02-13 22:33:31 +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
2019-02-13 22:33:31 +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