Commit 228007df authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Zeger-Jan van de Weg

new-branch-button

parent bc590ce6
......@@ -175,6 +175,8 @@ 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
......
......@@ -49,6 +49,11 @@ form.edit-issue {
margin: 0;
}
.related-branches-title {
font-size: 16px;
font-weight: 600;
}
.merge-requests-title {
font-size: 16px;
font-weight: 600;
......
......@@ -23,8 +23,7 @@ class Projects::BranchesController < Projects::ApplicationController
def create
branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name)
ref = sanitize(strip_tags(params[:ref]))
ref = Addressable::URI.unescape(ref)
result = CreateBranchService.new(project, current_user).
execute(branch_name, ref)
......@@ -49,4 +48,15 @@ class Projects::BranchesController < Projects::ApplicationController
format.js { render status: status[:return_code] }
end
end
private
def ref
if params[:ref]
ref_escaped = sanitize(strip_tags(params[:ref]))
Addressable::URI.unescape(ref_escaped)
else
@project.default_branch
end
end
end
......@@ -65,6 +65,7 @@ class Projects::IssuesController < Projects::ApplicationController
@notes = @issue.notes.nonawards.with_associations.fresh
@noteable = @issue
@merge_requests = @issue.referenced_merge_requests(current_user)
@related_branches = @issue.related_branches - @merge_requests.map(&:source_branch)
respond_with(@issue)
end
......
......@@ -94,6 +94,10 @@ class Issue < ActiveRecord::Base
end.sort_by(&:iid)
end
def related_branches
self.project.repository.branch_names.select { |branch| /\A#{iid}-/ =~ branch }
end
# Reset issue events cache
#
# Since we do cache @event we need to reset cache in special cases:
......@@ -120,4 +124,14 @@ class Issue < ActiveRecord::Base
note.all_references(current_user).merge_requests
end.uniq.select { |mr| mr.open? && mr.closes_issue?(self) }
end
def to_branch_name
"#{iid}-#{title.parameterize}"[0,25]
end
def new_branch_button?(current_user)
!self.closed? &&
referenced_merge_requests(current_user).empty? &&
related_branches.empty?
end
end
......@@ -47,6 +47,17 @@ module MergeRequests
merge_request.title = merge_request.source_branch.titleize.humanize
end
# When your branch name starts with an iid followed by a dash this pattern will
# be interpreted as the use wants to close that issue on this project
# Pattern example: 112-fix-mep-mep
# Will lead to appending `Closes #112` to the description
if merge_request.source_branch =~ /\A\d+-/
closes_issue = "Closes ##{Regexp.last_match(0)[0...-1]}"
closes_issue.prepend("\n") if merge_request.description.present?
merge_request.description << closes_issue
end
merge_request
end
......
-if @merge_requests.any?
- if @merge_requests.any?
%h2.merge-requests-title
= pluralize(@merge_requests.count, 'Related Merge Request')
%ul.unstyled-list
......
- if current_user && can?(current_user, :push_code, @project) && @issue.new_branch_button?(current_user)
.pull-right
= link_to namespace_project_branches_path(@project.namespace, @project, branch_name: @issue.to_branch_name), method: :post, class: 'btn' do
= icon('code-fork')
New Branch
- if @related_branches.any?
%h2.related-branches-title
= pluralize(@related_branches.count, 'Related Branch')
%ul.unstyled-list
- @related_branches.each do |branch|
%li
- sha = @project.repository.find_branch(branch).target
- ci_commit = @project.ci_commit(sha) if sha
- if ci_commit
%span.related-branch-ci-status
= 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
= branch
......@@ -70,8 +70,10 @@
.merge-requests
= render 'merge_requests'
= render 'related_branches'
.content-block.content-block-small
= render 'new_branch'
= render 'votes/votes_block', votable: @issue
.row
......
......@@ -140,4 +140,16 @@ describe Issue, models: true do
it_behaves_like 'a Taskable' do
let(:subject) { create :issue }
end
describe "#to_branch_name" do
let(:issue) { build(:issue, title: 'a' * 30) }
it "is expected not to exceed 25 chars" do
expect(issue.to_branch_name.length).to eq 25
end
it "starts with the issue iid" do
expect(issue.to_branch_name).to match /\A#{issue.iid}-a+\z/
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment