Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
f0e7d79c
Commit
f0e7d79c
authored
Feb 02, 2018
by
Andrew McCallum
Committed by
Sean McGivern
Feb 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Incorrect merge request title when Jira activated and multiple commits on branch"
parent
283ace44
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
12 deletions
+81
-12
app/services/merge_requests/build_service.rb
app/services/merge_requests/build_service.rb
+23
-7
changelogs/unreleased/40793-fix-mr-title-for-jira.yml
changelogs/unreleased/40793-fix-mr-title-for-jira.yml
+5
-0
spec/services/merge_requests/build_service_spec.rb
spec/services/merge_requests/build_service_spec.rb
+53
-5
No files found.
app/services/merge_requests/build_service.rb
View file @
f0e7d79c
module
MergeRequests
module
MergeRequests
class
BuildService
<
MergeRequests
::
BaseService
class
BuildService
<
MergeRequests
::
BaseService
include
Gitlab
::
Utils
::
StrongMemoize
def
execute
def
execute
@issue_iid
=
params
.
delete
(
:issue_iid
)
@
params_
issue_iid
=
params
.
delete
(
:issue_iid
)
self
.
merge_request
=
MergeRequest
.
new
(
params
)
self
.
merge_request
=
MergeRequest
.
new
(
params
)
merge_request
.
compare_commits
=
[]
merge_request
.
compare_commits
=
[]
...
@@ -123,7 +125,7 @@ module MergeRequests
...
@@ -123,7 +125,7 @@ module MergeRequests
#
#
def
assign_title_and_description
def
assign_title_and_description
assign_title_and_description_from_single_commit
assign_title_and_description_from_single_commit
assign_title_from_issue
assign_title_from_issue
if
target_project
.
issues_enabled?
||
target_project
.
external_issue_tracker
merge_request
.
title
||=
source_branch
.
titleize
.
humanize
merge_request
.
title
||=
source_branch
.
titleize
.
humanize
merge_request
.
title
=
wip_title
if
compare_commits
.
empty?
merge_request
.
title
=
wip_title
if
compare_commits
.
empty?
...
@@ -132,9 +134,9 @@ module MergeRequests
...
@@ -132,9 +134,9 @@ module MergeRequests
end
end
def
append_closes_description
def
append_closes_description
return
unless
issue
_iid
return
unless
issue
closes_issue
=
"Closes #
#{
issue_iid
}
"
closes_issue
=
"Closes
#
{
issue
.
to_reference
}
"
if
description
.
present?
if
description
.
present?
merge_request
.
description
+=
closes_issue
.
prepend
(
"
\n\n
"
)
merge_request
.
description
+=
closes_issue
.
prepend
(
"
\n\n
"
)
...
@@ -154,13 +156,27 @@ module MergeRequests
...
@@ -154,13 +156,27 @@ module MergeRequests
end
end
def
assign_title_from_issue
def
assign_title_from_issue
return
unless
issue
&&
issue
.
is_a?
(
Issue
)
return
unless
issue
merge_request
.
title
=
"Resolve
\"
#{
issue
.
title
}
\"
"
if
issue
.
is_a?
(
Issue
)
merge_request
.
title
=
"Resolve
\"
#{
issue
.
title
}
\"
"
unless
merge_request
.
title
branch_title
=
source_branch
.
downcase
.
remove
(
issue_iid
.
downcase
).
titleize
.
humanize
merge_request
.
title
=
"Resolve
#{
issue_iid
}
"
merge_request
.
title
+=
"
\"
#{
branch_title
}
\"
"
unless
branch_title
.
empty?
end
end
end
def
issue_iid
def
issue_iid
@issue_iid
||=
source_branch
.
match
(
/\A(\d+)-/
).
try
(
:[]
,
1
)
strong_memoize
(
:issue_iid
)
do
@params_issue_iid
||
begin
id
=
if
target_project
.
external_issue_tracker
source_branch
.
match
(
target_project
.
external_issue_reference_pattern
).
try
(
:[]
,
0
)
end
id
||
source_branch
.
match
(
/\A(\d+)-/
).
try
(
:[]
,
1
)
end
end
end
end
def
issue
def
issue
...
...
changelogs/unreleased/40793-fix-mr-title-for-jira.yml
0 → 100644
View file @
f0e7d79c
---
title
:
Prevent JIRA issue identifier from being humanized.
merge_request
:
16491
author
:
Andrew McCallum
type
:
fixed
spec/services/merge_requests/build_service_spec.rb
View file @
f0e7d79c
...
@@ -172,11 +172,32 @@ describe MergeRequests::BuildService do
...
@@ -172,11 +172,32 @@ describe MergeRequests::BuildService do
end
end
end
end
context
'branch starts with
external issue IID followed by a hyphen
'
do
context
'branch starts with
numeric characters followed by a hyphen with no issue tracker
'
do
let
(
:source_branch
)
{
'12345-fix-issue'
}
let
(
:source_branch
)
{
'12345-fix-issue'
}
before
do
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:issues_enabled?
).
and_return
(
false
)
end
it
'uses the title of the commit as the title of the merge request'
do
expect
(
merge_request
.
title
).
to
eq
(
commit_1
.
safe_message
.
split
(
"
\n
"
).
first
)
end
it
'uses the description of the commit as the description of the merge request'
do
commit_description
=
commit_1
.
safe_message
.
split
(
/\n+/
,
2
).
last
expect
(
merge_request
.
description
).
to
eq
(
"
#{
commit_description
}
"
)
end
end
context
'branch starts with JIRA-formatted external issue IID followed by a hyphen'
do
let
(
:source_branch
)
{
'EXMPL-12345-fix-issue'
}
before
do
before
do
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:issues_enabled?
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:external_issue_reference_pattern
).
and_return
(
IssueTrackerService
.
reference_pattern
)
end
end
it
'uses the title of the commit as the title of the merge request'
do
it
'uses the title of the commit as the title of the merge request'
do
...
@@ -186,7 +207,7 @@ describe MergeRequests::BuildService do
...
@@ -186,7 +207,7 @@ describe MergeRequests::BuildService do
it
'uses the description of the commit as the description of the merge request and appends the closes text'
do
it
'uses the description of the commit as the description of the merge request and appends the closes text'
do
commit_description
=
commit_1
.
safe_message
.
split
(
/\n+/
,
2
).
last
commit_description
=
commit_1
.
safe_message
.
split
(
/\n+/
,
2
).
last
expect
(
merge_request
.
description
).
to
eq
(
"
#{
commit_description
}
\n\n
Closes
#
12345"
)
expect
(
merge_request
.
description
).
to
eq
(
"
#{
commit_description
}
\n\n
Closes
EXMPL-
12345"
)
end
end
end
end
end
end
...
@@ -252,19 +273,46 @@ describe MergeRequests::BuildService do
...
@@ -252,19 +273,46 @@ describe MergeRequests::BuildService do
end
end
end
end
context
'branch starts with
external issue IID followed by a hyphen
'
do
context
'branch starts with
numeric characters followed by a hyphen with no issue tracker
'
do
let
(
:source_branch
)
{
'12345-fix-issue'
}
let
(
:source_branch
)
{
'12345-fix-issue'
}
before
do
before
do
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:issues_enabled?
).
and_return
(
false
)
end
end
it
'sets the title to the humanized branch title'
do
it
'sets the title to the humanized branch title'
do
expect
(
merge_request
.
title
).
to
eq
(
'12345 fix issue'
)
expect
(
merge_request
.
title
).
to
eq
(
'12345 fix issue'
)
end
end
end
context
'branch starts with JIRA-formatted external issue IID'
do
let
(
:source_branch
)
{
'EXMPL-12345'
}
before
do
allow
(
project
).
to
receive
(
:external_issue_tracker
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:issues_enabled?
).
and_return
(
false
)
allow
(
project
).
to
receive
(
:external_issue_reference_pattern
).
and_return
(
IssueTrackerService
.
reference_pattern
)
end
it
'sets the title to the humanized branch title'
do
expect
(
merge_request
.
title
).
to
eq
(
'Resolve EXMPL-12345'
)
end
it
'appends the closes text'
do
it
'appends the closes text'
do
expect
(
merge_request
.
description
).
to
eq
(
'Closes #12345'
)
expect
(
merge_request
.
description
).
to
eq
(
'Closes EXMPL-12345'
)
end
context
'followed by hyphenated text'
do
let
(
:source_branch
)
{
'EXMPL-12345-fix-issue'
}
it
'sets the title to the humanized branch title'
do
expect
(
merge_request
.
title
).
to
eq
(
'Resolve EXMPL-12345 "Fix issue"'
)
end
it
'appends the closes text'
do
expect
(
merge_request
.
description
).
to
eq
(
'Closes EXMPL-12345'
)
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment