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
Boxiang Sun
gitlab-ce
Commits
4cbe87d5
Commit
4cbe87d5
authored
Feb 23, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite references in issue description when moving it
parent
5ed8a1e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+16
-1
spec/services/issues/move_service_spec.rb
spec/services/issues/move_service_spec.rb
+19
-6
No files found.
app/services/issues/move_service.rb
View file @
4cbe87d5
...
...
@@ -45,7 +45,8 @@ module Issues
end
def
open_new_issue
@issue_new
.
update
(
project:
@project_new
)
new_description
=
rewrite_references
(
@issue_old
,
@issue_old
.
description
)
@issue_new
.
update
(
project:
@project_new
,
description:
new_description
)
end
def
rewrite_notes
...
...
@@ -69,5 +70,19 @@ module Issues
def
add_moved_to_note
SystemNoteService
.
noteable_moved
(
:to
,
@issue_old
,
@project_old
,
@issue_new
,
@current_user
)
end
def
rewrite_references
(
mentionable
,
text
)
new_content
=
text
.
dup
references
=
mentionable
.
all_references
[
:issues
,
:merge_requests
,
:milestones
].
each
do
|
type
|
references
.
public_send
(
type
).
each
do
|
mentioned
|
new_content
.
gsub!
(
mentioned
.
to_reference
,
mentioned
.
to_reference
(
@project_new
))
end
end
new_content
end
end
end
spec/services/issues/move_service_spec.rb
View file @
4cbe87d5
...
...
@@ -4,8 +4,8 @@ describe Issues::MoveService, services: true do
let
(
:user
)
{
create
(
:user
)
}
let
(
:title
)
{
'Some issue'
}
let
(
:description
)
{
'Some issue description'
}
let
(
:old_
issue
)
{
create
(
:issue
,
title:
title
,
description:
description
)
}
let
(
:old_
project
)
{
old_issue
.
project
}
let
(
:old_
project
)
{
create
(
:project
)
}
let
(
:old_
issue
)
{
create
(
:issue
,
title:
title
,
description:
description
,
project:
old_project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:move_service
)
{
described_class
.
new
(
old_project
,
user
,
move_params
,
old_issue
)
}
...
...
@@ -61,13 +61,12 @@ describe Issues::MoveService, services: true do
expect
(
old_issue
.
closed?
).
to
be
true
end
it
'persists changes to old and new issue'
do
expect
(
new_issue
.
changed?
).
to
be
false
expect
(
old_issue
.
changed?
).
to
be
false
it
'persists new issue'
do
expect
(
new_issue
.
persisted?
).
to
be
true
end
end
context
'
notes exist
'
do
context
'
issue with notes
'
do
let
(
:note_contents
)
do
[
'Some system note 1'
,
'Some comment'
,
'Some system note 2'
]
end
...
...
@@ -91,6 +90,20 @@ describe Issues::MoveService, services: true do
expect
(
new_notes
.
last
).
to
match
/^Moved from/
end
end
describe
'rewritting references'
do
include_context
'issue move executed'
context
'issue reference'
do
let
(
:another_issue
)
{
create
(
:issue
,
project:
old_project
)
}
let
(
:description
)
{
"Some description
#{
another_issue
.
to_reference
}
"
}
it
'rewrites referenced issues creating cross project reference'
do
expect
(
new_issue
.
description
)
.
to
eq
"Some description
#{
old_project
.
to_reference
}#{
another_issue
.
to_reference
}
"
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