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
1ae7ea1e
Commit
1ae7ea1e
authored
Dec 17, 2018
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE port of 51485-new-issue-labels-note
Adds system notes for weight on issue creation
parent
d15c6b83
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
88 additions
and
18 deletions
+88
-18
app/services/issuable/common_system_notes_service.rb
app/services/issuable/common_system_notes_service.rb
+12
-9
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+5
-1
changelogs/unreleased/51485-new-issue-labels-note.yml
changelogs/unreleased/51485-new-issue-labels-note.yml
+5
-0
ee/app/services/ee/issuable/common_system_notes_service.rb
ee/app/services/ee/issuable/common_system_notes_service.rb
+3
-2
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
.../services/ee/issuable/common_system_notes_service_spec.rb
+16
-2
spec/services/issuable/common_system_notes_service_spec.rb
spec/services/issuable/common_system_notes_service_spec.rb
+45
-2
spec/support/shared_examples/common_system_notes_examples.rb
spec/support/shared_examples/common_system_notes_examples.rb
+2
-2
No files found.
app/services/issuable/common_system_notes_service.rb
View file @
1ae7ea1e
...
...
@@ -4,20 +4,23 @@ module Issuable
class
CommonSystemNotesService
<
::
BaseService
attr_reader
:issuable
def
execute
(
issuable
,
old_labels
)
def
execute
(
issuable
,
old_labels
:
[],
is_update:
true
)
@issuable
=
issuable
if
issuable
.
previous_changes
.
include?
(
'title'
)
create_title_change_note
(
issuable
.
previous_changes
[
'title'
].
first
)
end
if
is_update
if
issuable
.
previous_changes
.
include?
(
'title'
)
create_title_change_note
(
issuable
.
previous_changes
[
'title'
].
first
)
end
handle_description_change_note
handle_description_change_note
handle_time_tracking_note
if
issuable
.
is_a?
(
TimeTrackable
)
create_discussion_lock_note
if
issuable
.
previous_changes
.
include?
(
'discussion_locked'
)
end
handle_time_tracking_note
if
issuable
.
is_a?
(
TimeTrackable
)
create_labels_note
(
old_labels
)
if
issuable
.
labels
!=
old_labels
create_discussion_lock_note
if
issuable
.
previous_changes
.
include?
(
'discussion_locked'
)
create_milestone_note
if
issuable
.
previous_changes
.
include?
(
'milestone_id'
)
create_due_date_note
if
issuable
.
previous_changes
.
include?
(
'due_date'
)
create_milestone_note
if
issuable
.
previous_changes
.
include?
(
'milestone_id'
)
create_labels_note
(
old_labels
)
if
issuable
.
labels
!=
old_labels
end
private
...
...
app/services/issuable_base_service.rb
View file @
1ae7ea1e
...
...
@@ -154,6 +154,10 @@ class IssuableBaseService < BaseService
before_create
(
issuable
)
if
issuable
.
save
ActiveRecord
::
Base
.
no_touching
do
Issuable
::
CommonSystemNotesService
.
new
(
project
,
current_user
).
execute
(
issuable
,
is_update:
false
)
end
after_create
(
issuable
)
execute_hooks
(
issuable
)
invalidate_cache_counts
(
issuable
,
users:
issuable
.
assignees
)
...
...
@@ -209,7 +213,7 @@ class IssuableBaseService < BaseService
if
issuable
.
with_transaction_returning_status
{
issuable
.
save
}
# We do not touch as it will affect a update on updated_at field
ActiveRecord
::
Base
.
no_touching
do
Issuable
::
CommonSystemNotesService
.
new
(
project
,
current_user
).
execute
(
issuable
,
old_associations
[
:labels
])
Issuable
::
CommonSystemNotesService
.
new
(
project
,
current_user
).
execute
(
issuable
,
old_
labels:
old_
associations
[
:labels
])
end
handle_changes
(
issuable
,
old_associations:
old_associations
)
...
...
changelogs/unreleased/51485-new-issue-labels-note.yml
0 → 100644
View file @
1ae7ea1e
---
title
:
Create system notes on issue / MR creation when labels, milestone, or due date is set
merge_request
:
23859
author
:
type
:
added
ee/app/services/ee/issuable/common_system_notes_service.rb
View file @
1ae7ea1e
...
...
@@ -7,10 +7,11 @@ module EE
attr_reader
:issuable
override
:execute
def
execute
(
_issuable
,
_old_labels
)
def
execute
(
_issuable
,
old_labels:
[],
is_update:
true
)
super
handle_weight_change_note
handle_date_change_note
handle_date_change_note
if
is_update
end
private
...
...
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
View file @
1ae7ea1e
...
...
@@ -5,14 +5,14 @@ describe Issuable::CommonSystemNotesService do
let
(
:project
)
{
create
(
:project
)
}
let
(
:issuable
)
{
create
(
:issue
)
}
describe
'#execu
te'
do
context
'on issuable upda
te'
do
it_behaves_like
'system note creation'
,
{
weight:
5
},
'changed weight to **5**'
context
'when issuable is an epic'
do
let
(
:timestamp
)
{
Time
.
now
}
let
(
:issuable
)
{
create
(
:epic
,
end_date:
timestamp
)
}
subject
{
described_class
.
new
(
nil
,
user
).
execute
(
issuable
,
[])
}
subject
{
described_class
.
new
(
nil
,
user
).
execute
(
issuable
,
old_labels:
[])
}
before
do
issuable
.
assign_attributes
(
start_date:
timestamp
,
end_date:
nil
)
...
...
@@ -27,4 +27,18 @@ describe Issuable::CommonSystemNotesService do
end
end
end
context
'on issuable create'
do
let
(
:issuable
)
{
build
(
:issue
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[],
is_update:
false
)
}
it
'creates a system note for weight'
do
issuable
.
weight
=
5
issuable
.
save
expect
{
subject
}.
to
change
{
issuable
.
notes
.
count
}.
from
(
0
).
to
(
1
)
expect
(
issuable
.
notes
.
last
.
note
).
to
match
(
'changed weight'
)
end
end
end
spec/services/issuable/common_system_notes_service_spec.rb
View file @
1ae7ea1e
...
...
@@ -5,7 +5,7 @@ describe Issuable::CommonSystemNotesService do
let
(
:project
)
{
create
(
:project
)
}
let
(
:issuable
)
{
create
(
:issue
)
}
describe
'#execu
te'
do
context
'on issuable upda
te'
do
it_behaves_like
'system note creation'
,
{
title:
'New title'
},
'changed title'
it_behaves_like
'system note creation'
,
{
description:
'New description'
},
'changed the description'
it_behaves_like
'system note creation'
,
{
discussion_locked:
true
},
'locked this issue'
...
...
@@ -20,7 +20,7 @@ describe Issuable::CommonSystemNotesService do
end
it
'creates a resource label event'
do
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[])
event
=
issuable
.
reload
.
resource_label_events
.
last
expect
(
event
).
not_to
be_nil
...
...
@@ -68,4 +68,47 @@ describe Issuable::CommonSystemNotesService do
end
end
end
context
'on issuable create'
do
let
(
:issuable
)
{
build
(
:issue
)
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[],
is_update:
false
)
}
it
'does not create system note for title and description'
do
issuable
.
save
expect
{
subject
}.
not_to
change
{
issuable
.
notes
.
count
}
end
it
'creates a resource label event for labels added'
do
label
=
create
(
:label
,
project:
project
)
issuable
.
labels
<<
label
issuable
.
save
expect
{
subject
}.
to
change
{
issuable
.
resource_label_events
.
count
}.
from
(
0
).
to
(
1
)
event
=
issuable
.
reload
.
resource_label_events
.
last
expect
(
event
).
not_to
be_nil
expect
(
event
.
label_id
).
to
eq
label
.
id
expect
(
event
.
user_id
).
to
eq
user
.
id
end
it
'creates a system note for milestone set'
do
issuable
.
milestone
=
create
(
:milestone
,
project:
project
)
issuable
.
save
expect
{
subject
}.
to
change
{
issuable
.
notes
.
count
}.
from
(
0
).
to
(
1
)
expect
(
issuable
.
notes
.
last
.
note
).
to
match
(
'changed milestone'
)
end
it
'creates a system note for due_date set'
do
issuable
.
due_date
=
Date
.
today
issuable
.
save
expect
{
subject
}.
to
change
{
issuable
.
notes
.
count
}.
from
(
0
).
to
(
1
)
expect
(
issuable
.
notes
.
last
.
note
).
to
match
(
'changed due date'
)
end
end
end
spec/support/shared_examples/common_system_notes_examples.rb
View file @
1ae7ea1e
shared_examples
'system note creation'
do
|
update_params
,
note_text
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[])
}
before
do
issuable
.
assign_attributes
(
update_params
)
...
...
@@ -16,7 +16,7 @@ shared_examples 'system note creation' do |update_params, note_text|
end
shared_examples
'WIP notes creation'
do
|
wip_action
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
}
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[])
}
it
'creates WIP toggle and title change notes'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
2
)
...
...
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