summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-04-04 10:37:44 +0000
committerRémy Coutable <remy@rymai.me>2018-04-04 10:37:44 +0000
commit1f59aa242279acb1b6feaefd9a868a2353520f02 (patch)
treedb050a39442f8474aeca27102b9a6c9327d18a38
parent6587a0cdbbe917042e0eecfed67e533f73db7372 (diff)
parentc2823a4bda24c2d78219fc47c472276e4cfd7404 (diff)
downloadgitlab-ce-1f59aa242279acb1b6feaefd9a868a2353520f02.tar.gz
Merge branch '20394-protected-branches-wildcard' into 'master'
Resolve "Protected branches count is wrong when a wildcard includes several protected branches" Closes #20394 See merge request gitlab-org/gitlab-ce!17920
-rw-r--r--app/controllers/projects/settings/repository_controller.rb4
-rw-r--r--app/views/projects/protected_branches/shared/_branches_list.html.haml4
-rw-r--r--app/views/projects/protected_tags/shared/_tags_list.html.haml4
-rw-r--r--changelogs/unreleased/20394-protected-branches-wildcard.yml5
-rw-r--r--spec/features/protected_branches_spec.rb5
-rw-r--r--spec/features/protected_tags_spec.rb5
6 files changed, 21 insertions, 6 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb
index d06d18c498b..dd9e4a2af3e 100644
--- a/app/controllers/projects/settings/repository_controller.rb
+++ b/app/controllers/projects/settings/repository_controller.rb
@@ -16,6 +16,10 @@ module Projects
@protected_tags = @project.protected_tags.order(:name).page(params[:page])
@protected_branch = @project.protected_branches.new
@protected_tag = @project.protected_tags.new
+
+ @protected_branches_count = @protected_branches.reduce(0) { |sum, branch| sum + branch.matching(@project.repository.branches).size }
+ @protected_tags_count = @protected_tags.reduce(0) { |sum, tag| sum + tag.matching(@project.repository.tags).size }
+
load_gon_index
end
diff --git a/app/views/projects/protected_branches/shared/_branches_list.html.haml b/app/views/projects/protected_branches/shared/_branches_list.html.haml
index 2a0704bc7af..a09c13176c3 100644
--- a/app/views/projects/protected_branches/shared/_branches_list.html.haml
+++ b/app/views/projects/protected_branches/shared/_branches_list.html.haml
@@ -2,7 +2,7 @@
- if @protected_branches.empty?
.panel-heading
%h3.panel-title
- Protected branch (#{@protected_branches.size})
+ Protected branch (#{@protected_branches_count})
%p.settings-message.text-center
There are currently no protected branches, protect a branch with the form above.
- else
@@ -16,7 +16,7 @@
%col
%thead
%tr
- %th Protected branch (#{@protected_branches.size})
+ %th Protected branch (#{@protected_branches_count})
%th Last commit
%th Allowed to merge
%th Allowed to push
diff --git a/app/views/projects/protected_tags/shared/_tags_list.html.haml b/app/views/projects/protected_tags/shared/_tags_list.html.haml
index 3f42ae58438..02908e16dc5 100644
--- a/app/views/projects/protected_tags/shared/_tags_list.html.haml
+++ b/app/views/projects/protected_tags/shared/_tags_list.html.haml
@@ -2,7 +2,7 @@
- if @protected_tags.empty?
.panel-heading
%h3.panel-title
- Protected tag (#{@protected_tags.size})
+ Protected tag (#{@protected_tags_count})
%p.settings-message.text-center
There are currently no protected tags, protect a tag with the form above.
- else
@@ -17,7 +17,7 @@
%col
%thead
%tr
- %th Protected tag (#{@protected_tags.size})
+ %th Protected tag (#{@protected_tags_count})
%th Last commit
%th Allowed to create
- if can_admin_project
diff --git a/changelogs/unreleased/20394-protected-branches-wildcard.yml b/changelogs/unreleased/20394-protected-branches-wildcard.yml
new file mode 100644
index 00000000000..3fa8ee4f69f
--- /dev/null
+++ b/changelogs/unreleased/20394-protected-branches-wildcard.yml
@@ -0,0 +1,5 @@
+---
+title: Include matching branches and tags in protected branches / tags count
+merge_request:
+author: Jan Beckmann
+type: fixed
diff --git a/spec/features/protected_branches_spec.rb b/spec/features/protected_branches_spec.rb
index a4084818284..43cabd3b9f2 100644
--- a/spec/features/protected_branches_spec.rb
+++ b/spec/features/protected_branches_spec.rb
@@ -142,7 +142,10 @@ feature 'Protected Branches', :js do
set_protected_branch_name('*-stable')
click_on "Protect"
- within(".protected-branches-list") { expect(page).to have_content("2 matching branches") }
+ within(".protected-branches-list") do
+ expect(page).to have_content("Protected branch (2)")
+ expect(page).to have_content("2 matching branches")
+ end
end
it "displays all the branches matching the wildcard" do
diff --git a/spec/features/protected_tags_spec.rb b/spec/features/protected_tags_spec.rb
index 8cc6f17b8d9..efccaeaff6c 100644
--- a/spec/features/protected_tags_spec.rb
+++ b/spec/features/protected_tags_spec.rb
@@ -65,7 +65,10 @@ feature 'Protected Tags', :js do
set_protected_tag_name('*-stable')
click_on "Protect"
- within(".protected-tags-list") { expect(page).to have_content("2 matching tags") }
+ within(".protected-tags-list") do
+ expect(page).to have_content("Protected tag (2)")
+ expect(page).to have_content("2 matching tags")
+ end
end
it "displays all the tags matching the wildcard" do