Class: Gitlab::Checks::BranchCheck

Inherits:
BaseSingleChecker show all
Defined in:
lib/gitlab/checks/branch_check.rb

Constant Summary collapse

ERROR_MESSAGES =
{
  delete_default_branch: 'The default branch of a project cannot be deleted.',
  force_push_protected_branch: 'You are not allowed to force push code to a protected branch on this project.',
  non_master_delete_protected_branch: 'You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.',
  non_web_delete_protected_branch: 'You can only delete protected branches using the web interface.',
  merge_protected_branch: 'You are not allowed to merge code into protected branches on this project.',
  push_protected_branch: 'You are not allowed to push code to protected branches on this project.',
  create_protected_branch: 'You are not allowed to create protected branches on this project.',
  invalid_commit_create_protected_branch: 'You can only use an existing protected branch ref as the basis of a new protected branch.',
  non_web_create_protected_branch: 'You can only create protected branches using the web interface and API.',
  prohibited_hex_branch_name: 'You cannot create a branch with a 40-character hexadecimal branch name.',
  invalid_branch_name: 'You cannot create a branch with an invalid name.'
}.freeze
LOG_MESSAGES =
{
  delete_default_branch_check: "Checking if default branch is being deleted...",
  protected_branch_checks: "Checking if you are force pushing to a protected branch...",
  protected_branch_push_checks: "Checking if you are allowed to push to the protected branch...",
  protected_branch_creation_checks: "Checking if you are allowed to create a protected branch...",
  protected_branch_deletion_checks: "Checking if you are allowed to delete the protected branch..."
}.freeze

Instance Attribute Summary

Attributes inherited from BaseSingleChecker

#change_access

Instance Method Summary collapse

Methods inherited from BaseSingleChecker

#initialize

Constructor Details

This class inherits a constructor from Gitlab::Checks::BaseSingleChecker

Instance Method Details

#validate!Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/checks/branch_check.rb', line 28

def validate!
  return unless branch_name

  logger.log_timed(LOG_MESSAGES[:delete_default_branch_check]) do
    if deletion? && branch_name == project.default_branch
      raise GitAccess::ForbiddenError, ERROR_MESSAGES[:delete_default_branch]
    end
  end

  prohibited_branch_checks
  protected_branch_checks
end