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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
5e3c9475
Commit
5e3c9475
authored
Mar 16, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add minor improvements in code related to issue move
parent
1dd279d8
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
38 deletions
+50
-38
app/assets/javascripts/issuable_form.js.coffee
app/assets/javascripts/issuable_form.js.coffee
+4
-4
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+5
-3
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+11
-20
app/services/system_note_service.rb
app/services/system_note_service.rb
+4
-6
app/views/shared/issuable/_form.html.haml
app/views/shared/issuable/_form.html.haml
+1
-1
lib/gitlab/gfm/reference_unfolder.rb
lib/gitlab/gfm/reference_unfolder.rb
+24
-3
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+1
-1
No files found.
app/assets/javascripts/issuable_form.js.coffee
View file @
5e3c9475
...
...
@@ -30,11 +30,11 @@ class @IssuableForm
"description"
]
handleSubmit
:
(
e
)
=>
@
resetAutosave
handleSubmit
:
=>
if
(
parseInt
(
@
issueMoveField
?
.
val
())
?
0
)
>
0
e
.
preventDefault
()
unless
confirm
(
ISSUE_MOVE_CONFIRM_MSG
)
return
false
unless
confirm
(
ISSUE_MOVE_CONFIRM_MSG
)
@
resetAutosave
()
resetAutosave
:
=>
@
titleField
.
data
(
"autosave"
).
reset
()
...
...
app/helpers/issues_helper.rb
View file @
5e3c9475
...
...
@@ -60,12 +60,14 @@ module IssuesHelper
def
project_options
(
issuable
,
current_user
,
ability: :read_project
)
projects
=
current_user
.
authorized_projects
projects
=
projects
.
select
do
|
project
|
current_user
.
can?
(
ability
,
project
)
&&
project
!=
issuable
.
project
current_user
.
can?
(
ability
,
project
)
end
projects
.
unshift
(
OpenStruct
.
new
(
id:
0
,
name_with_namespace:
'No project'
))
no_project
=
OpenStruct
.
new
(
id:
0
,
name_with_namespace:
'No project'
)
projects
.
unshift
(
no_project
)
projects
.
delete
(
issuable
.
project
)
options_from_collection_for_select
(
projects
,
:id
,
:name_with_namespace
,
0
)
options_from_collection_for_select
(
projects
,
:id
,
:name_with_namespace
)
end
def
status_box_class
(
item
)
...
...
app/services/issues/move_service.rb
View file @
5e3c9475
...
...
@@ -7,7 +7,7 @@ module Issues
@issue_new
=
nil
@project_old
=
@project
if
new_project_id
if
new_project_id
.
to_i
>
0
@project_new
=
Project
.
find
(
new_project_id
)
end
...
...
@@ -19,7 +19,7 @@ module Issues
def
execute
return
unless
move?
# Using trasaction because of a high resources footprint
# Using tra
n
saction because of a high resources footprint
# on rewriting notes (unfolding references)
#
ActiveRecord
::
Base
.
transaction
do
...
...
@@ -54,10 +54,11 @@ module Issues
def
create_new_issue
new_params
=
{
id:
nil
,
iid:
nil
,
milestone:
nil
,
label_ids:
[],
project:
@project_new
,
author:
@issue_old
.
author
,
description:
rewrite_references
(
@issue_old
)
}
description:
unfold_references
(
@issue_old
.
description
)
}
new_params
=
@issue_old
.
serializable_hash
.
merge
(
new_params
)
create_service
=
CreateService
.
new
(
@project_new
,
@current_user
,
params
.
merge
(
new_params
)
)
new_params
)
@issue_new
=
create_service
.
execute
(
set_author:
false
)
end
...
...
@@ -66,7 +67,7 @@ module Issues
@issue_old
.
notes
.
find_each
do
|
note
|
new_note
=
note
.
dup
new_params
=
{
project:
@project_new
,
noteable:
@issue_new
,
note:
rewrite_references
(
new_
note
)
}
note:
unfold_references
(
new_note
.
note
)
}
new_note
.
update
(
new_params
)
end
...
...
@@ -78,30 +79,20 @@ module Issues
end
def
add_moved_from_note
SystemNoteService
.
noteable_moved
(
:from
,
@issue_new
,
@project_new
,
@issue_old
,
@current_user
)
SystemNoteService
.
noteable_moved
(
@issue_new
,
@project_new
,
@issue_old
,
@current_user
,
direction: :from
)
end
def
add_moved_to_note
SystemNoteService
.
noteable_moved
(
:to
,
@issue_old
,
@project_old
,
@issue_new
,
@current_user
)
SystemNoteService
.
noteable_moved
(
@issue_old
,
@project_old
,
@issue_new
,
@current_user
,
direction: :to
)
end
def
rewrite_references
(
noteable
)
content
=
noteable_content
(
noteable
).
dup
def
unfold_references
(
content
)
unfolder
=
Gitlab
::
Gfm
::
ReferenceUnfolder
.
new
(
content
,
@project_old
)
unfolder
.
unfold
(
@project_new
)
end
def
noteable_content
(
noteable
)
case
noteable
when
Issue
then
noteable
.
description
when
Note
then
noteable
.
note
else
raise
'Unexpected noteable while moving an issue!'
end
end
def
notify_participants
notification_service
.
issue_moved
(
@issue_old
,
@issue_new
,
@current_user
)
end
...
...
app/services/system_note_service.rb
View file @
5e3c9475
...
...
@@ -3,7 +3,6 @@
# Used for creating system notes (e.g., when a user references a merge request
# from an issue, an issue's assignee changes, an issue is closed, etc.)
class
SystemNoteService
extend
GitlabMarkdownHelper
# Called when commits are added to a Merge Request
#
# noteable - Noteable object
...
...
@@ -398,16 +397,15 @@ class SystemNoteService
#
# Example Note text:
#
# "Moved to
project_new/
#11"
# "Moved to
some_namespace/project_new
#11"
#
# Returns the created Note object
def
self
.
noteable_moved
(
direction
,
noteable
,
project
,
noteable_ref
,
author
)
def
self
.
noteable_moved
(
noteable
,
project
,
noteable_ref
,
author
,
direction
:
)
unless
[
:to
,
:from
].
include?
(
direction
)
raise
Standard
Error
,
"Invalid direction `
#{
direction
}
`"
raise
Argument
Error
,
"Invalid direction `
#{
direction
}
`"
end
cross_reference
=
cross_project_reference
(
noteable_ref
.
project
,
noteable_ref
)
cross_reference
=
noteable_ref
.
to_reference
(
project
)
body
=
"Moved
#{
direction
}
#{
cross_reference
}
"
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
...
...
app/views/shared/issuable/_form.html.haml
View file @
5e3c9475
...
...
@@ -70,7 +70,7 @@
-
if
issuable
.
is_a?
(
Issue
)
&&
can?
(
current_user
,
:admin_issue
,
issuable
.
project
)
%hr
.form-group
=
f
.
label
:move_to_project_id
,
'Move'
,
class:
'control-label'
=
label_tag
:move_to_project_id
,
'Move'
,
class:
'control-label'
.col-sm-10
-
projects
=
project_options
(
issuable
,
current_user
,
ability: :admin_issue
)
=
select_tag
(
:move_to_project_id
,
projects
,
include_blank:
true
,
...
...
lib/gitlab/gfm/reference_unfolder.rb
View file @
5e3c9475
module
Gitlab
module
Gfm
##
# Class tha
n
unfolds local references in text.
# Class tha
t
unfolds local references in text.
#
# The initializer takes text in Markdown and project this text is valid
# in context of.
#
# `unfold` method tries to find all local references and unfold each of
# those local references to cross reference format.
#
# Examples:
#
# 'Hello, this issue is related to #123 and
# other issues labeled with ~"label"', will be converted to:
#
# 'Hello, this issue is related to gitlab-org/gitlab-ce#123 and
# other issue labeled with gitlab-org/gitlab-ce~"label"'.
#
# It does respect markdown lexical rules, so text in code block will not be
# replaced, see another example:
#
# 'Merge request for issue #1234, see also link:
# http://gitlab.com/some/link/#1234, and code `puts #1234`' =>
#
# 'Merge request for issue gitlab-org/gitlab-ce#1234, se also link:
# http://gitlab.com/some/link/#1234, and code `puts #1234`'
#
class
ReferenceUnfolder
def
initialize
(
text
,
project
)
...
...
@@ -66,8 +88,7 @@ module Gitlab
end
def
markdown
(
text
)
helper
=
Class
.
new
.
extend
(
GitlabMarkdownHelper
)
helper
.
markdown
(
text
,
project:
@project
,
no_original_data:
true
)
Banzai
.
render
(
text
,
project:
@project
,
no_original_data:
true
)
end
end
end
...
...
spec/services/system_note_service_spec.rb
View file @
5e3c9475
...
...
@@ -446,7 +446,7 @@ describe SystemNoteService, services: true do
let
(
:new_noteable
)
{
create
(
:issue
,
project:
new_project
)
}
subject
do
described_class
.
noteable_moved
(
direction
,
noteable
,
project
,
new_noteable
,
author
)
described_class
.
noteable_moved
(
noteable
,
project
,
new_noteable
,
author
,
direction:
direction
)
end
shared_examples
'cross project mentionable'
do
...
...
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