summaryrefslogtreecommitdiff
path: root/app/models/projects/branch_rule.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/projects/branch_rule.rb')
-rw-r--r--app/models/projects/branch_rule.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/models/projects/branch_rule.rb b/app/models/projects/branch_rule.rb
new file mode 100644
index 00000000000..ae59d24e557
--- /dev/null
+++ b/app/models/projects/branch_rule.rb
@@ -0,0 +1,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