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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a9ebacb2
Commit
a9ebacb2
authored
Jan 09, 2018
by
Jarka Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add system notes when moving issues between epics
parent
94092647
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
11 deletions
+83
-11
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+1
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+21
-0
changelogs/unreleased-ee/4261-moving-issue-note.yml
changelogs/unreleased-ee/4261-moving-issue-note.yml
+5
-0
ee/app/services/epic_issues/create_service.rb
ee/app/services/epic_issues/create_service.rb
+18
-4
ee/app/services/issuable_links/create_service.rb
ee/app/services/issuable_links/create_service.rb
+3
-5
ee/app/services/issue_links/create_service.rb
ee/app/services/issue_links/create_service.rb
+4
-2
spec/ee/spec/services/epic_issues/create_service_spec.rb
spec/ee/spec/services/epic_issues/create_service_spec.rb
+31
-0
No files found.
app/models/system_note_metadata.rb
View file @
a9ebacb2
...
...
@@ -17,6 +17,7 @@ class SystemNoteMetadata < ActiveRecord::Base
outdated
approved unapproved relate unrelate
epic_issue_added issue_added_to_epic epic_issue_removed issue_removed_from_epic
epic_issue_moved issue_changed_epic
]
.
freeze
validates
:note
,
presence:
true
...
...
app/services/system_note_service.rb
View file @
a9ebacb2
...
...
@@ -576,6 +576,20 @@ module SystemNoteService
create_note
(
NoteSummary
.
new
(
epic
,
nil
,
user
,
body
,
action:
action
))
end
def
epic_issue_moved
(
from_epic
,
issue
,
to_epic
,
user
)
epic_issue_moved_act
(
from_epic
,
issue
,
to_epic
,
user
,
verb:
'added'
,
direction:
'from'
)
epic_issue_moved_act
(
to_epic
,
issue
,
from_epic
,
user
,
verb:
'moved'
,
direction:
'to'
)
end
def
epic_issue_moved_act
(
subject_epic
,
issue
,
object_epic
,
user
,
verb
:,
direction
:)
action
=
'epic_issue_moved'
body
=
"
#{
verb
}
issue
#{
issue
.
to_reference
(
subject_epic
.
group
)
}
#{
direction
}
"
\
" epic
#{
subject_epic
.
to_reference
(
object_epic
.
group
)
}
"
create_note
(
NoteSummary
.
new
(
object_epic
,
nil
,
user
,
body
,
action:
action
))
end
def
issue_on_epic
(
issue
,
epic
,
user
,
type
)
return
unless
validate_epic_issue_action_type
(
type
)
...
...
@@ -592,6 +606,13 @@ module SystemNoteService
create_note
(
NoteSummary
.
new
(
issue
,
issue
.
project
,
user
,
body
,
action:
action
))
end
def
issue_epic_change
(
issue
,
epic
,
user
)
body
=
"changed epic to
#{
epic
.
to_reference
(
issue
.
project
)
}
"
action
=
'issue_changed_epic'
create_note
(
NoteSummary
.
new
(
issue
,
issue
.
project
,
user
,
body
,
action:
action
))
end
def
validate_epic_issue_action_type
(
type
)
[
:added
,
:removed
].
include?
(
type
)
end
...
...
changelogs/unreleased-ee/4261-moving-issue-note.yml
0 → 100644
View file @
a9ebacb2
---
title
:
Add system notes when moving issues between epics
merge_request
:
author
:
type
:
added
ee/app/services/epic_issues/create_service.rb
View file @
a9ebacb2
...
...
@@ -4,16 +4,30 @@ module EpicIssues
def
relate_issues
(
referenced_issue
)
link
=
EpicIssue
.
find_or_initialize_by
(
issue:
referenced_issue
)
params
=
if
link
.
persisted?
{
issue_moved:
true
,
original_epic:
link
.
epic
}
else
{}
end
link
.
epic
=
issuable
link
.
move_to_start
link
.
save!
link
yield
params
end
def
create_notes
(
referenced_issue
)
SystemNoteService
.
epic_issue
(
issuable
,
referenced_issue
,
current_user
,
:added
)
SystemNoteService
.
issue_on_epic
(
referenced_issue
,
issuable
,
current_user
,
:added
)
def
create_notes
(
referenced_issue
,
params
)
if
params
[
:issue_moved
]
SystemNoteService
.
epic_issue_moved
(
params
[
:original_epic
],
referenced_issue
,
issuable
,
current_user
)
SystemNoteService
.
issue_epic_change
(
referenced_issue
,
issuable
,
current_user
)
else
SystemNoteService
.
epic_issue
(
issuable
,
referenced_issue
,
current_user
,
:added
)
SystemNoteService
.
issue_on_epic
(
referenced_issue
,
issuable
,
current_user
,
:added
)
end
end
def
extractor_context
...
...
ee/app/services/issuable_links/create_service.rb
View file @
a9ebacb2
...
...
@@ -19,11 +19,9 @@ module IssuableLinks
def
create_issue_links
referenced_issues
.
each
do
|
referenced_issue
|
link
=
relate_issues
(
referenced_issue
)
next
unless
link
.
persisted?
create_notes
(
referenced_issue
)
relate_issues
(
referenced_issue
)
do
|
params
|
create_notes
(
referenced_issue
,
params
)
end
end
end
...
...
ee/app/services/issue_links/create_service.rb
View file @
a9ebacb2
module
IssueLinks
class
CreateService
<
IssuableLinks
::
CreateService
def
relate_issues
(
referenced_issue
)
IssueLink
.
create
(
source:
issuable
,
target:
referenced_issue
)
link
=
IssueLink
.
create
(
source:
issuable
,
target:
referenced_issue
)
yield
if
link
.
persisted?
end
def
linkable_issues
(
issues
)
issues
.
select
{
|
issue
|
can?
(
current_user
,
:admin_issue_link
,
issue
)
}
end
def
create_notes
(
referenced_issue
)
def
create_notes
(
referenced_issue
,
params
)
SystemNoteService
.
relate_issue
(
issuable
,
referenced_issue
,
current_user
)
SystemNoteService
.
relate_issue
(
referenced_issue
,
issuable
,
current_user
)
end
...
...
spec/ee/spec/services/epic_issues/create_service_spec.rb
View file @
a9ebacb2
...
...
@@ -223,6 +223,37 @@ describe EpicIssues::CreateService do
it
'returns success status'
do
is_expected
.
to
eq
(
status: :success
)
end
it
'creates 3 system notes'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
3
)
end
it
'creates a note correctly for the original epic'
do
subject
note
=
Note
.
find_by
(
system:
true
,
noteable_type:
'Epic'
,
noteable_id:
epic
.
id
)
expect
(
note
.
note
).
to
eq
(
"moved issue
#{
issue
.
to_reference
(
epic
.
group
)
}
to epic
#{
another_epic
.
to_reference
(
epic
.
group
)
}
"
)
expect
(
note
.
system_note_metadata
.
action
).
to
eq
(
'epic_issue_moved'
)
end
it
'creates a note correctly for the new epic'
do
subject
note
=
Note
.
find_by
(
system:
true
,
noteable_type:
'Epic'
,
noteable_id:
another_epic
.
id
)
expect
(
note
.
note
).
to
eq
(
"added issue
#{
issue
.
to_reference
(
epic
.
group
)
}
from epic
#{
epic
.
to_reference
(
epic
.
group
)
}
"
)
expect
(
note
.
system_note_metadata
.
action
).
to
eq
(
'epic_issue_moved'
)
end
it
'creates a note correctly for the issue'
do
subject
note
=
Note
.
find_by
(
system:
true
,
noteable_type:
'Issue'
,
noteable_id:
issue
.
id
)
expect
(
note
.
note
).
to
eq
(
"changed epic to
#{
another_epic
.
to_reference
(
issue
.
project
)
}
"
)
expect
(
note
.
system_note_metadata
.
action
).
to
eq
(
'issue_changed_epic'
)
end
end
context
'when issue from non group project is given'
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