Class: ProtectedBranch
Defined Under Namespace
Classes: MergeAccessLevel, PushAccessLevel
Constant Summary
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD
ApplicationRecord::MAX_PLUCK
Class Method Summary
collapse
Instance Method Summary
collapse
#commit
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.allow_force_push?(project, ref_name) ⇒ Boolean
41
42
43
|
# File 'app/models/protected_branch.rb', line 41
def self.allow_force_push?(project, ref_name)
project.protected_branches.allowing_force_push.matching(ref_name).any?
end
|
.any_protected?(project, ref_names) ⇒ Boolean
45
46
47
48
49
50
51
|
# File 'app/models/protected_branch.rb', line 45
def self.any_protected?(project, ref_names)
protected_refs(project).any? do |protected_ref|
ref_names.any? do |ref_name|
protected_ref.matches?(ref_name)
end
end
end
|
.branch_requires_code_owner_approval?(project, branch_name) ⇒ Boolean
58
59
60
|
# File 'app/models/protected_branch.rb', line 58
def self.branch_requires_code_owner_approval?(project, branch_name)
false
end
|
.by_name(query) ⇒ Object
62
63
64
65
66
|
# File 'app/models/protected_branch.rb', line 62
def self.by_name(query)
return none if query.blank?
where(fuzzy_arel_match(:name, query.downcase))
end
|
.downcase_humanized_name ⇒ Object
72
73
74
|
# File 'app/models/protected_branch.rb', line 72
def self.downcase_humanized_name
name.underscore.humanize.downcase
end
|
.protected?(project, ref_name) ⇒ Boolean
Check if branch name is marked as protected in the system
28
29
30
31
32
33
34
35
|
# File 'app/models/protected_branch.rb', line 28
def self.protected?(project, ref_name)
return true if project.empty_repo? && project.default_branch_protected?
return false if ref_name.blank?
Rails.cache.fetch(protected_ref_cache_key(project, ref_name)) do
self.matching(ref_name, protected_refs: protected_refs(project)).present?
end
end
|
.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil) ⇒ Boolean
17
18
19
20
21
22
23
24
25
|
# File 'app/models/protected_branch.rb', line 17
def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil)
if project.empty_repo? && project.default_branch_protected?
return true if user.admin? || project.team.max_member_access(user.id) > Gitlab::Access::DEVELOPER
end
super
end
|
.protected_ref_cache_key(project, ref_name) ⇒ Object
37
38
39
|
# File 'app/models/protected_branch.rb', line 37
def self.protected_ref_cache_key(project, ref_name)
"protected_ref-#{project.cache_key}-#{Digest::SHA1.hexdigest(ref_name)}"
end
|
.protected_refs(project) ⇒ Object
53
54
55
|
# File 'app/models/protected_branch.rb', line 53
def self.protected_refs(project)
project.protected_branches
end
|
Instance Method Details
#allow_multiple?(type) ⇒ Boolean
68
69
70
|
# File 'app/models/protected_branch.rb', line 68
def allow_multiple?(type)
type == :push
end
|