Class: Gitlab::Checks::SnippetCheck

Inherits:
BaseChecker show all
Defined in:
lib/gitlab/checks/snippet_check.rb

Constant Summary collapse

DEFAULT_BRANCH =
'master'.freeze
ERROR_MESSAGES =
{
  create_delete_branch: 'You can not create or delete branches.'
}.freeze
ATTRIBUTES =
%i[oldrev newrev ref branch_name tag_name logger].freeze

Instance Attribute Summary

Attributes inherited from BaseChecker

#change_access

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(change, logger:) ⇒ SnippetCheck

Returns a new instance of SnippetCheck.


14
15
16
17
18
19
20
21
# File 'lib/gitlab/checks/snippet_check.rb', line 14

def initialize(change, logger:)
  @oldrev, @newrev, @ref = change.values_at(:oldrev, :newrev, :ref)
  @branch_name = Gitlab::Git.branch_name(@ref)
  @tag_name = Gitlab::Git.tag_name(@ref)

  @logger = logger
  @logger.append_message("Running checks for ref: #{@branch_name || @tag_name}")
end

Instance Method Details

#validate!Object


23
24
25
26
27
28
29
# File 'lib/gitlab/checks/snippet_check.rb', line 23

def validate!
  if creation? || deletion?
    raise GitAccess::ForbiddenError, ERROR_MESSAGES[:create_delete_branch]
  end

  true
end