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
ecab5398
Commit
ecab5398
authored
Apr 30, 2018
by
Chantal Rollison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add system note for weight change, closes #1481
parent
c89c7b6c
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
192 additions
and
35 deletions
+192
-35
app/controllers/concerns/issuable_actions.rb
app/controllers/concerns/issuable_actions.rb
+0
-1
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+7
-4
app/services/issuable/common_system_notes_service.rb
app/services/issuable/common_system_notes_service.rb
+1
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+1
-0
ee/app/models/ee/system_note_metadata.rb
ee/app/models/ee/system_note_metadata.rb
+16
-0
ee/app/services/ee/issuable/common_system_notes_service.rb
ee/app/services/ee/issuable/common_system_notes_service.rb
+26
-0
ee/app/services/ee/system_note_service.rb
ee/app/services/ee/system_note_service.rb
+28
-0
ee/changelogs/unreleased/ccr-weight-change-note.yml
ee/changelogs/unreleased/ccr-weight-change-note.yml
+4
-0
ee/spec/requests/api/issues_spec.rb
ee/spec/requests/api/issues_spec.rb
+9
-0
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
.../services/ee/issuable/common_system_notes_service_spec.rb
+11
-0
ee/spec/services/system_note_service_spec.rb
ee/spec/services/system_note_service_spec.rb
+60
-0
spec/lib/gitlab/incoming_email_spec.rb
spec/lib/gitlab/incoming_email_spec.rb
+2
-2
spec/services/issuable/common_system_notes_service_spec.rb
spec/services/issuable/common_system_notes_service_spec.rb
+0
-28
spec/support/shared_examples/services/common_system_notes_examples.rb
.../shared_examples/services/common_system_notes_examples.rb
+27
-0
No files found.
app/controllers/concerns/issuable_actions.rb
View file @
ecab5398
...
@@ -18,7 +18,6 @@ module IssuableActions
...
@@ -18,7 +18,6 @@ module IssuableActions
def
update
def
update
@issuable
=
update_service
.
execute
(
issuable
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@issuable
=
update_service
.
execute
(
issuable
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
recaptcha_check_if_spammable
{
render
:edit
}
recaptcha_check_if_spammable
{
render
:edit
}
...
...
app/models/system_note_metadata.rb
View file @
ecab5398
class
SystemNoteMetadata
<
ActiveRecord
::
Base
class
SystemNoteMetadata
<
ActiveRecord
::
Base
prepend
EE
::
SystemNoteMetadata
# These notes's action text might contain a reference that is external.
# These notes's action text might contain a reference that is external.
# We should always force a deep validation upon references that are found
# We should always force a deep validation upon references that are found
# in this note type.
# in this note type.
...
@@ -15,13 +17,14 @@ class SystemNoteMetadata < ActiveRecord::Base
...
@@ -15,13 +17,14 @@ class SystemNoteMetadata < ActiveRecord::Base
title time_tracking branch milestone discussion task moved
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked
opened closed merged duplicate locked unlocked
outdated
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
]
.
freeze
validates
:note
,
presence:
true
validates
:note
,
presence:
true
validates
:action
,
inclusion:
ICON_TYPES
,
allow_nil:
true
validates
:action
,
inclusion:
{
in: :icon_types
}
,
allow_nil:
true
belongs_to
:note
belongs_to
:note
def
icon_types
ICON_TYPES
end
end
end
app/services/issuable/common_system_notes_service.rb
View file @
ecab5398
module
Issuable
module
Issuable
class
CommonSystemNotesService
<
::
BaseService
class
CommonSystemNotesService
<
::
BaseService
prepend
EE
::
Issuable
::
CommonSystemNotesService
attr_reader
:issuable
attr_reader
:issuable
def
execute
(
issuable
,
old_labels
)
def
execute
(
issuable
,
old_labels
)
...
...
app/services/system_note_service.rb
View file @
ecab5398
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
# Used for creating system notes (e.g., when a user references a merge request
# 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.)
# from an issue, an issue's assignee changes, an issue is closed, etc.)
module
SystemNoteService
module
SystemNoteService
prepend
EE
::
SystemNoteService
extend
self
extend
self
# Called when commits are added to a Merge Request
# Called when commits are added to a Merge Request
...
...
ee/app/models/ee/system_note_metadata.rb
0 → 100644
View file @
ecab5398
module
EE
module
SystemNoteMetadata
extend
::
Gitlab
::
Utils
::
Override
EE_ICON_TYPES
=
%w[
weight 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
override
:icon_types
def
icon_types
@icon_types
||=
(
super
+
EE_ICON_TYPES
).
freeze
end
end
end
ee/app/services/ee/issuable/common_system_notes_service.rb
0 → 100644
View file @
ecab5398
module
EE
module
Issuable
module
CommonSystemNotesService
extend
::
Gitlab
::
Utils
::
Override
attr_reader
:issuable
override
:execute
def
execute
(
_issuable
,
_old_labels
)
super
handle_weight_change_note
end
private
def
handle_weight_change_note
if
issuable
.
previous_changes
.
include?
(
'weight'
)
create_weight_change_note
end
end
def
create_weight_change_note
::
SystemNoteService
.
change_weight_note
(
issuable
,
issuable
.
project
,
current_user
)
end
end
end
end
ee/app/services/ee/system_note_service.rb
0 → 100644
View file @
ecab5398
# SystemNoteService
#
# 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.
module
EE
module
SystemNoteService
extend
self
# Called when the weight of a Noteable is changed
#
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
#
# Example Note text:
#
# "removed the weight"
#
# "changed weight to 4"
#
# Returns the created Note object
def
change_weight_note
(
noteable
,
project
,
author
)
body
=
noteable
.
weight
?
"changed weight to **
#{
noteable
.
weight
}
**,"
:
'removed the weight'
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'weight'
))
end
end
end
ee/changelogs/unreleased/ccr-weight-change-note.yml
0 → 100644
View file @
ecab5398
---
title
:
Add system note for weight change
merge_request
:
!5531
type
:
added
ee/spec/requests/api/issues_spec.rb
View file @
ecab5398
...
@@ -87,6 +87,15 @@ describe API::Issues, :mailer do
...
@@ -87,6 +87,15 @@ describe API::Issues, :mailer do
expect
(
json_response
[
'error'
]).
to
eq
(
'weight does not have a valid value'
)
expect
(
json_response
[
'error'
]).
to
eq
(
'weight does not have a valid value'
)
end
end
it
'adds a note when the weight is changed'
do
expect
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
"
,
user
),
weight:
9
end
.
to
change
{
Note
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'weight'
]).
to
eq
(
9
)
end
context
'issuable weights unlicensed'
do
context
'issuable weights unlicensed'
do
before
do
before
do
stub_licensed_features
(
issue_weights:
false
)
stub_licensed_features
(
issue_weights:
false
)
...
...
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
0 → 100644
View file @
ecab5398
require
'spec_helper'
describe
Issuable
::
CommonSystemNotesService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issuable
)
{
create
(
:issue
)
}
describe
'#execute'
do
it_behaves_like
'system note creation'
,
{
weight:
5
},
'changed weight to **5**,'
end
end
ee/spec/services/system_note_service_spec.rb
0 → 100644
View file @
ecab5398
require
'spec_helper'
describe
SystemNoteService
do
include
ProjectForksHelper
include
Gitlab
::
Routing
include
RepoHelpers
set
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
group:
group
)
}
set
(
:author
)
{
create
(
:user
)
}
let
(
:noteable
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
noteable
}
let
(
:epic
)
{
create
(
:epic
)
}
shared_examples_for
'a system note'
do
let
(
:expected_noteable
)
{
noteable
}
let
(
:commit_count
)
{
nil
}
it
'has the correct attributes'
,
:aggregate_failures
do
expect
(
subject
).
to
be_valid
expect
(
subject
).
to
be_system
expect
(
subject
.
noteable
).
to
eq
expected_noteable
expect
(
subject
.
project
).
to
eq
project
expect
(
subject
.
author
).
to
eq
author
expect
(
subject
.
system_note_metadata
.
action
).
to
eq
(
action
)
expect
(
subject
.
system_note_metadata
.
commit_count
).
to
eq
(
commit_count
)
end
end
describe
'.change_weight_note'
do
context
'when weight changed'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
,
weight:
4
)
}
subject
{
described_class
.
change_weight_note
(
noteable
,
project
,
author
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'weight'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"changed weight to **4**,"
end
end
context
'when weight removed'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
,
weight:
nil
)
}
subject
{
described_class
.
change_weight_note
(
noteable
,
project
,
author
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'weight'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
'removed the weight'
end
end
end
end
spec/lib/gitlab/incoming_email_spec.rb
View file @
ecab5398
...
@@ -24,7 +24,7 @@ describe Gitlab::IncomingEmail do
...
@@ -24,7 +24,7 @@ describe Gitlab::IncomingEmail do
end
end
describe
'self.supports_wildcard?'
do
describe
'self.supports_wildcard?'
do
context
'address contains the wildard placeholder'
do
context
'address contains the wild
c
ard placeholder'
do
before
do
before
do
stub_incoming_email_setting
(
address:
'replies+%{key}@example.com'
)
stub_incoming_email_setting
(
address:
'replies+%{key}@example.com'
)
end
end
...
@@ -49,7 +49,7 @@ describe Gitlab::IncomingEmail do
...
@@ -49,7 +49,7 @@ describe Gitlab::IncomingEmail do
stub_incoming_email_setting
(
address:
nil
)
stub_incoming_email_setting
(
address:
nil
)
end
end
it
'returns that wildard is not supported'
do
it
'returns that wild
c
ard is not supported'
do
expect
(
described_class
.
supports_wildcard?
).
to
be_falsey
expect
(
described_class
.
supports_wildcard?
).
to
be_falsey
end
end
end
end
...
...
spec/services/issuable/common_system_notes_service_spec.rb
View file @
ecab5398
...
@@ -5,34 +5,6 @@ describe Issuable::CommonSystemNotesService do
...
@@ -5,34 +5,6 @@ describe Issuable::CommonSystemNotesService do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:issuable
)
{
create
(
:issue
)
}
let
(
:issuable
)
{
create
(
:issue
)
}
shared_examples
'system note creation'
do
|
update_params
,
note_text
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])}
before
do
issuable
.
assign_attributes
(
update_params
)
issuable
.
save
end
it
'creates 1 system note with the correct content'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
1
)
note
=
Note
.
last
expect
(
note
.
note
).
to
match
(
note_text
)
expect
(
note
.
noteable_type
).
to
eq
(
issuable
.
class
.
name
)
end
end
shared_examples
'WIP notes creation'
do
|
wip_action
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
}
it
'creates WIP toggle and title change notes'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
2
)
expect
(
Note
.
first
.
note
).
to
match
(
"
#{
wip_action
}
as a **Work In Progress**"
)
expect
(
Note
.
second
.
note
).
to
match
(
'changed title'
)
end
end
describe
'#execute'
do
describe
'#execute'
do
it_behaves_like
'system note creation'
,
{
title:
'New title'
},
'changed title'
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'
,
{
description:
'New description'
},
'changed the description'
...
...
spec/support/shared_examples/services/common_system_notes_examples.rb
0 → 100644
View file @
ecab5398
shared_examples
'system note creation'
do
|
update_params
,
note_text
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])}
before
do
issuable
.
assign_attributes
(
update_params
)
issuable
.
save
end
it
'creates 1 system note with the correct content'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
1
)
note
=
Note
.
last
expect
(
note
.
note
).
to
match
(
note_text
)
expect
(
note
.
noteable_type
).
to
eq
(
issuable
.
class
.
name
)
end
end
shared_examples
'WIP notes creation'
do
|
wip_action
|
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
[])
}
it
'creates WIP toggle and title change notes'
do
expect
{
subject
}.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
2
)
expect
(
Note
.
first
.
note
).
to
match
(
"
#{
wip_action
}
as a **Work In Progress**"
)
expect
(
Note
.
second
.
note
).
to
match
(
'changed title'
)
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