\#to_branch_name now uses the iid as postfix

Given the branch name 'mep-mep' with an iid being 1,
the current way, master's way, would yield a branch name of
1-mep-mep. The problem for larger projects however would be that
a developer might forget what iid the issue was.

When this developer would try to tab complete it would:
- Or result in 20+ branches possibly
- Or start with the wrong digit, try again with digit++
  - Would see 20 branches, repeat

Thus the obvious way of solving this is letting the dev tab complete
on the issue title, which is easier to remember.
This commit is contained in:
Zeger-Jan van de Weg 2016-03-18 19:34:04 +01:00
parent eba0032552
commit 70ca3370eb
4 changed files with 8 additions and 9 deletions

View File

@ -106,9 +106,8 @@ class Issue < ActiveRecord::Base
def related_branches def related_branches
return [] if self.project.empty_repo? return [] if self.project.empty_repo?
self.project.repository.branch_names.select do |branch|
branch =~ /\A#{iid}-(?!\d+-stable)/i self.project.repository.branch_names.select { |branch| branch.end_with?("-#{iid}") }
end
end end
# Reset issue events cache # Reset issue events cache
@ -139,7 +138,7 @@ class Issue < ActiveRecord::Base
end end
def to_branch_name def to_branch_name
"#{iid}-#{title.parameterize}" "#{title.parameterize}-#{iid}"
end end
def can_be_worked_on?(current_user) def can_be_worked_on?(current_user)

View File

@ -51,7 +51,7 @@ module MergeRequests
# be interpreted as the use wants to close that issue on this project # be interpreted as the use wants to close that issue on this project
# Pattern example: 112-fix-mep-mep # Pattern example: 112-fix-mep-mep
# Will lead to appending `Closes #112` to the description # Will lead to appending `Closes #112` to the description
if match = merge_request.source_branch.match(/\A(\d+)-/) if match = merge_request.source_branch.match(/-(\d+)\z/)
iid = match[1] iid = match[1]
closes_issue = "Closes ##{iid}" closes_issue = "Closes ##{iid}"

View File

@ -210,7 +210,7 @@ class SystemNoteService
# Called when a branch is created from the 'new branch' button on a issue # Called when a branch is created from the 'new branch' button on a issue
# Example note text: # Example note text:
# #
# "Started branch `201-issue-branch-button`" # "Started branch `issue-branch-button-201`"
def self.new_issue_branch(issue, project, author, branch) def self.new_issue_branch(issue, project, author, branch)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Application.routes.url_helpers
link = h.namespace_project_compare_url(project.namespace, project, from: project.default_branch, to: branch) link = h.namespace_project_compare_url(project.namespace, project, from: project.default_branch, to: branch)

View File

@ -131,7 +131,7 @@ describe Issue, models: true do
end end
describe '#related_branches' do describe '#related_branches' do
it "should " do it "selects the right branches" do
allow(subject.project.repository).to receive(:branch_names). allow(subject.project.repository).to receive(:branch_names).
and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name]) and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name])
@ -151,10 +151,10 @@ describe Issue, models: true do
end end
describe "#to_branch_name" do describe "#to_branch_name" do
let(:issue) { build(:issue, title: 'a' * 30) } let(:issue) { create(:issue, title: 'a' * 30) }
it "starts with the issue iid" do it "starts with the issue iid" do
expect(issue.to_branch_name).to match /\A#{issue.iid}-a+\z/ expect(issue.to_branch_name).to match /-#{issue.iid}\z/
end end
end end
end end