Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-02-22 11:20:04 +0300
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-15 22:21:11 +0300
commit2b97c921196a7be904bfe4f0a31347c3583c9e88 (patch)
treee650acbaa92c45882f0a4681e67b5e07d5cf7d46
parente831a3b869cbb82e9a4294a5f9309ba56df46589 (diff)
Incorporate review
-rw-r--r--CHANGELOG3
-rw-r--r--app/assets/stylesheets/pages/issues.scss7
-rw-r--r--app/controllers/projects/branches_controller.rb7
-rw-r--r--app/models/issue.rb19
-rw-r--r--app/services/system_note_service.rb2
-rw-r--r--app/views/projects/issues/_new_branch.html.haml2
-rw-r--r--app/views/projects/issues/_related_branches.html.haml2
-rw-r--r--spec/controllers/projects/branches_controller_spec.rb19
-rw-r--r--spec/features/issues/new_branch_button_spec.rb50
-rw-r--r--spec/models/issue_spec.rb9
10 files changed, 93 insertions, 27 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fe65e7b34fc..563a5966400 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -59,6 +59,7 @@ v 8.5.3
- Show commit message in JIRA mention comment
- Makes issue page and merge request page usable on mobile browsers.
- Improved UI for profile settings
+ - New branch button appears on issues where applicable
v 8.5.2
- Fix sidebar overlapping content when screen width was below 1200px
@@ -175,8 +176,6 @@ v 8.5.0
- Add label description (Nuttanart Pornprasitsakul)
- Show label row when filtering issues or merge requests by label (Nuttanart Pornprasitsakul)
- Add Todos
- - User project limit is reached notice is hidden if the projects limit is zero
- - New branch button appears on issues where applicable (Zeger-Jan van de Weg)
v 8.4.5
- No CE-specific changes
diff --git a/app/assets/stylesheets/pages/issues.scss b/app/assets/stylesheets/pages/issues.scss
index 5f1810cbaf6..0f2e14d1a20 100644
--- a/app/assets/stylesheets/pages/issues.scss
+++ b/app/assets/stylesheets/pages/issues.scss
@@ -49,12 +49,7 @@ form.edit-issue {
margin: 0;
}
-.related-branches-title {
- font-size: 16px;
- font-weight: 600;
-}
-
-.merge-requests-title {
+.merge-requests-title, .related-branches-title {
font-size: 16px;
font-weight: 600;
}
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
index bcbd3aa5d9b..43ea717cbd2 100644
--- a/app/controllers/projects/branches_controller.rb
+++ b/app/controllers/projects/branches_controller.rb
@@ -27,10 +27,9 @@ class Projects::BranchesController < Projects::ApplicationController
result = CreateBranchService.new(project, current_user).
execute(branch_name, ref)
- if params[:issue_id]
- issue = Issue.where(id: params[:issue_id], project: @project).limit(1).first
-
- SystemNoteService.new_issue_branch(issue, @project, current_user, branch_name)
+ if params[:issue_iid]
+ issue = @project.issues.find_by(iid: params[:issue_iid])
+ SystemNoteService.new_issue_branch(issue, @project, current_user, branch_name) if issue
end
if result[:status] == :success
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 3b6bff6c577..ec275d5f5b5 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -87,11 +87,16 @@ class Issue < ActiveRecord::Base
end
def referenced_merge_requests(current_user = nil)
- Gitlab::ReferenceExtractor.lazily do
- [self, *notes].flat_map do |note|
- note.all_references(current_user).merge_requests
- end
- end.sort_by(&:iid)
+ if defined?(@referenced_merge_requests)
+ @referenced_merge_requests[current_user] ||= Gitlab::ReferenceExtractor.lazily do
+ [self, *notes].flat_map do |note|
+ note.all_references(current_user).merge_requests
+ end
+ end.sort_by(&:iid).uniq
+ else
+ @referenced_merge_requests = {}
+ referenced_merge_requests(current_user)
+ end
end
def related_branches
@@ -132,7 +137,7 @@ class Issue < ActiveRecord::Base
def can_be_worked_on?(current_user)
!self.closed? &&
!self.project.forked? &&
- referenced_merge_requests(current_user).none? { |mr| mr.closes_issue?(self) } &&
- related_branches.empty?
+ self.related_branches.empty? &&
+ self.referenced_merge_requests(current_user).empty?
end
end
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index b65ac47bce3..5ea7d405e4d 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -213,7 +213,7 @@ class SystemNoteService
# "Started branch `201-issue-branch-button`"
def self.new_issue_branch(issue, project, author, branch)
h = Gitlab::Application.routes.url_helpers
- link = "#{Gitlab.config.gitlab.url}#{h.namespace_project_compare_path(project.namespace, project, from: project.default_branch, to: branch)}"
+ link = "#{h.namespace_project_compare_url(project.namespace, project, from: project.default_branch, to: branch)}"
body = "Started branch [#{branch}](#{link})"
create_note(noteable: issue, project: project, author: author, note: body)
diff --git a/app/views/projects/issues/_new_branch.html.haml b/app/views/projects/issues/_new_branch.html.haml
index a6b97b90e64..e66e4669d48 100644
--- a/app/views/projects/issues/_new_branch.html.haml
+++ b/app/views/projects/issues/_new_branch.html.haml
@@ -1,5 +1,5 @@
- if current_user && can?(current_user, :push_code, @project) && @issue.can_be_worked_on?(current_user)
.pull-right
- = link_to namespace_project_branches_path(@project.namespace, @project, branch_name: @issue.to_branch_name, issue_id: @issue.id), method: :post, class: 'btn', title: @issue.to_branch_name do
+ = link_to namespace_project_branches_path(@project.namespace, @project, branch_name: @issue.to_branch_name, issue_iid: @issue.iid), method: :post, class: 'btn', title: @issue.to_branch_name do
= icon('code-fork')
New Branch
diff --git a/app/views/projects/issues/_related_branches.html.haml b/app/views/projects/issues/_related_branches.html.haml
index 56387661989..b10cd03515f 100644
--- a/app/views/projects/issues/_related_branches.html.haml
+++ b/app/views/projects/issues/_related_branches.html.haml
@@ -11,5 +11,5 @@
= render_ci_status(ci_commit)
%span.related-branch-info
%strong
- = link_to namespace_project_compare_path(@project.namespace, @project, from: @project.default_branch, to: branch) do
+ = link_to namespace_project_compare_path(@project.namespace, @project, from: @project.default_branch, to: branch), class: "label-branch" do
= branch
diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb
index b509714e75c..98ae424ed7c 100644
--- a/spec/controllers/projects/branches_controller_spec.rb
+++ b/spec/controllers/projects/branches_controller_spec.rb
@@ -66,21 +66,30 @@ describe Projects::BranchesController do
describe "created from the new branch button on issues" do
let(:branch) { "1-feature-branch" }
- let!(:issue) { create(:issue) }
+ let!(:issue) { create(:issue, project: project) }
- before do
+
+ it 'redirects' do
post :create,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
branch_name: branch,
- issue_id: issue.id
- end
+ issue_iid: issue.iid
- it 'redirects' do
expect(subject).
to redirect_to("/#{project.path_with_namespace}/tree/1-feature-branch")
end
+ it 'posts a system note' do
+ expect(SystemNoteService).to receive(:new_issue_branch).with(issue, project, user, "1-feature-branch")
+
+ post :create,
+ namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ branch_name: branch,
+ issue_iid: issue.iid
+ end
+
end
end
diff --git a/spec/features/issues/new_branch_button_spec.rb b/spec/features/issues/new_branch_button_spec.rb
new file mode 100644
index 00000000000..f47d7a5471b
--- /dev/null
+++ b/spec/features/issues/new_branch_button_spec.rb
@@ -0,0 +1,50 @@
+require 'rails_helper'
+
+feature 'Start new branch from an issue', feature: true do
+ let!(:project) { create(:project) }
+ let!(:issue) { create(:issue, project: project) }
+ let!(:user) { create(:user)}
+
+ context "for team members" do
+ before do
+ project.team << [user, :master]
+ login_as(user)
+ end
+
+ it 'shown the new branch button', js: false do
+ visit namespace_project_issue_path(project.namespace, project, issue)
+
+ expect(page).to have_link "New Branch"
+ end
+
+ context "when there is a referenced merge request" do
+ let(:note) do
+ create(:note, :on_issue, :system, project: project,
+ note: "mentioned in !#{referenced_mr.iid}")
+ end
+ let(:referenced_mr) do
+ create(:merge_request, source_project: project,
+ target_project: project,
+ description: "Fixes ##{issue.iid}")
+ end
+
+ before do
+ issue.notes << note
+
+ visit namespace_project_issue_path(project.namespace, project, issue)
+ end
+
+ it "hides the new branch button", js: true do
+ expect(page).not_to have_link "New Branch"
+ expect(page).to have_content /1 Related Merge Request/
+ end
+ end
+ end
+
+ context "for visiters" do
+ it 'no button is shown', js: false do
+ visit namespace_project_issue_path(project.namespace, project, issue)
+ expect(page).not_to have_link "New Branch"
+ end
+ end
+end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 97b2db2fba5..2ccdec1eeff 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -130,6 +130,15 @@ describe Issue, models: true do
end
end
+ describe '#related_branches' do
+ it "should " do
+ allow(subject.project.repository).to receive(:branch_names).
+ and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name])
+
+ expect(subject.related_branches).to eq [subject.to_branch_name]
+ end
+ end
+
it_behaves_like 'an editable mentionable' do
subject { create(:issue) }