summaryrefslogtreecommitdiff
path: root/app/models/projects/branch_rule.rb
blob: ae59d24e5572c6da9a7e99cf03ad1b1ed74650f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Projects
  class BranchRule
    extend Forwardable

    attr_reader :project, :protected_branch

    def_delegators(:protected_branch, :name, :group, :default_branch?, :created_at, :updated_at)

    def initialize(project, protected_branch)
      @protected_branch = protected_branch
      @project = project
    end

    def protected?
      true
    end

    def matching_branches_count
      branch_names = project.repository.branch_names
      matching_branches = protected_branch.matching(branch_names)
      matching_branches.count
    end

    def branch_protection
      protected_branch
    end
  end
end

Projects::BranchRule.prepend_mod