diff options
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r-- | lib/gitlab/checks/diff_check.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/checks/push_check.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/checks/snippet_check.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/checks/timed_logger.rb | 2 |
4 files changed, 29 insertions, 10 deletions
diff --git a/lib/gitlab/checks/diff_check.rb b/lib/gitlab/checks/diff_check.rb index 8780b410a07..c0b228dee59 100644 --- a/lib/gitlab/checks/diff_check.rb +++ b/lib/gitlab/checks/diff_check.rb @@ -17,17 +17,26 @@ module Gitlab file_paths = [] - process_commits do |commit| - validate_once(commit) do - commit.raw_deltas.each do |diff| - file_paths.concat([diff.new_path, diff.old_path].compact) + if ::Feature.enabled?(:diff_check_with_paths_changed_rpc, project, default_enabled: true) + paths = project.repository.find_changed_paths(commits.map(&:sha)) + paths.each do |path| + file_paths.concat([path.path]) - validate_diff(diff) + validate_diff(path) + end + else + process_commits do |commit| + validate_once(commit) do + commit.raw_deltas.each do |diff| + file_paths.concat([diff.new_path, diff.old_path].compact) + + validate_diff(diff) + end end end end - validate_file_paths(file_paths) + validate_file_paths(file_paths.uniq) end private diff --git a/lib/gitlab/checks/push_check.rb b/lib/gitlab/checks/push_check.rb index 7cc5bc56cbb..47aa25aae4c 100644 --- a/lib/gitlab/checks/push_check.rb +++ b/lib/gitlab/checks/push_check.rb @@ -14,7 +14,7 @@ module Gitlab private def can_push? - user_access.can_do_action?(:push_code) || + user_access.can_push_for_ref?(ref) || project.branch_allows_collaboration?(user_access.user, branch_name) end end diff --git a/lib/gitlab/checks/snippet_check.rb b/lib/gitlab/checks/snippet_check.rb index 8c61b782baa..d5efbfcc5bc 100644 --- a/lib/gitlab/checks/snippet_check.rb +++ b/lib/gitlab/checks/snippet_check.rb @@ -10,12 +10,13 @@ module Gitlab ATTRIBUTES = %i[oldrev newrev ref branch_name tag_name logger].freeze attr_reader(*ATTRIBUTES) - def initialize(change, default_branch:, logger:) + def initialize(change, default_branch:, root_ref:, logger:) @oldrev, @newrev, @ref = change.values_at(:oldrev, :newrev, :ref) @branch_name = Gitlab::Git.branch_name(@ref) @tag_name = Gitlab::Git.tag_name(@ref) @default_branch = default_branch + @root_ref = root_ref @logger = logger @logger.append_message("Running checks for ref: #{@branch_name || @tag_name}") end @@ -26,12 +27,21 @@ module Gitlab end true + rescue GitAccess::ForbiddenError => e + Gitlab::ErrorTracking.log_exception(e, default_branch: @default_branch, branch_name: @branch_name, creation: creation?, deletion: deletion?) + + raise e end private + # If the `root_ref` is not present means that this is the first commit to the + # repository and when the default branch is going to be created. + # We allow the first branch creation no matter the name because + # it can be even an imported snippet from an instance with a different + # default branch. def creation? - @branch_name != @default_branch && super + super && @root_ref && (@branch_name != @default_branch) end end end diff --git a/lib/gitlab/checks/timed_logger.rb b/lib/gitlab/checks/timed_logger.rb index f365e0a43f6..0db38d32bb3 100644 --- a/lib/gitlab/checks/timed_logger.rb +++ b/lib/gitlab/checks/timed_logger.rb @@ -31,7 +31,7 @@ module Gitlab args = { cancelled: true } args[:start] = start if timed - append_message(log_message + time_suffix_message(args)) + append_message(log_message + time_suffix_message(**args)) raise TimeoutError end |