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

57 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
2021-09-04 01:27:46 +05:30
class SingleChangeAccess
2019-02-15 15:39:39 +05:30
ATTRIBUTES = %i[user_access project skip_authorization
2021-09-04 01:27:46 +05:30
protocol oldrev newrev ref
2019-02-15 15:39:39 +05:30
branch_name tag_name logger commits].freeze
2017-09-10 17:25:29 +05:30
2019-02-15 15:39:39 +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-15 15:39:39 +05:30
change, user_access:, project:,
2021-10-27 15:23:28 +05:30
protocol:, logger:, commits: nil
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
@protocol = protocol
2021-10-27 15:23:28 +05:30
@commits = commits
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
2020-10-24 23:57:45 +05:30
def validate!
2019-02-15 15:39:39 +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
2019-02-15 15:39:39 +05:30
def commits
@commits ||= project.repository.new_commits(newrev)
2019-01-03 12:48:30 +05:30
end
2019-02-15 15:39:39 +05:30
protected
2019-01-03 12:48:30 +05:30
2019-02-15 15:39:39 +05:30
def ref_level_checks
Gitlab::Checks::PushCheck.new(self).validate!
Gitlab::Checks::BranchCheck.new(self).validate!
Gitlab::Checks::TagCheck.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-15 15:39:39 +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
2020-05-24 23:13:21 +05:30
2021-09-04 01:27:46 +05:30
Gitlab::Checks::SingleChangeAccess.prepend_mod_with('Gitlab::Checks::SingleChangeAccess')