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
f82a9c95
Commit
f82a9c95
authored
Apr 06, 2021
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add service to perform some of the issue after creation tasks
parent
55456542
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
0 deletions
+126
-0
app/services/issues/after_create_service.rb
app/services/issues/after_create_service.rb
+13
-0
ee/app/services/ee/issues/after_create_service.rb
ee/app/services/ee/issues/after_create_service.rb
+24
-0
ee/spec/services/ee/issues/after_create_service_spec.rb
ee/spec/services/ee/issues/after_create_service_spec.rb
+37
-0
spec/services/issues/after_create_service_spec.rb
spec/services/issues/after_create_service_spec.rb
+52
-0
No files found.
app/services/issues/after_create_service.rb
0 → 100644
View file @
f82a9c95
# frozen_string_literal: true
module
Issues
class
AfterCreateService
<
Issues
::
BaseService
def
execute
(
issue
)
todo_service
.
new_issue
(
issue
,
current_user
)
delete_milestone_total_issue_counter_cache
(
issue
.
milestone
)
track_incident_action
(
current_user
,
issue
,
:incident_created
)
end
end
end
Issues
::
AfterCreateService
.
prepend_ee_mod
ee/app/services/ee/issues/after_create_service.rb
0 → 100644
View file @
f82a9c95
# frozen_string_literal: true
module
EE
module
Issues
module
AfterCreateService
extend
::
Gitlab
::
Utils
::
Override
override
:execute
def
execute
(
issue
)
super
add_issue_sla
(
issue
)
end
private
def
add_issue_sla
(
issue
)
return
unless
issue
.
sla_available?
::
IncidentManagement
::
Incidents
::
CreateSlaService
.
new
(
issue
,
current_user
).
execute
end
end
end
end
ee/spec/services/ee/issues/after_create_service_spec.rb
0 → 100644
View file @
f82a9c95
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Issues
::
AfterCreateService
do
include
AfterNextHelpers
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
current_user
)
}
subject
(
:after_create_service
)
{
described_class
.
new
(
project
,
current_user
)
}
describe
'#execute'
do
context
'when issue sla is available'
do
it
'calls IncidentManagement::Incidents::CreateSlaService'
do
allow
(
issue
).
to
receive
(
:sla_available?
).
and_return
(
true
)
expect_next
(
::
IncidentManagement
::
Incidents
::
CreateSlaService
,
issue
,
current_user
)
.
to
receive
(
:execute
)
after_create_service
.
execute
(
issue
)
end
end
context
'when issue sla is not available'
do
it
'does not call IncidentManagement::Incidents::CreateSlaService'
do
allow
(
issue
).
to
receive
(
:sla_available?
).
and_return
(
false
)
expect
(
::
IncidentManagement
::
Incidents
::
CreateSlaService
)
.
not_to
receive
(
:new
)
after_create_service
.
execute
(
issue
)
end
end
end
end
spec/services/issues/after_create_service_spec.rb
0 → 100644
View file @
f82a9c95
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Issues
::
AfterCreateService
do
include
AfterNextHelpers
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:assignee
)
{
create
(
:user
)
}
let_it_be
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let_it_be
(
:issue
)
{
create
(
:issue
,
project:
project
,
author:
current_user
,
milestone:
milestone
,
assignee_ids:
[
assignee
.
id
])
}
subject
(
:after_create_service
)
{
described_class
.
new
(
project
,
current_user
)
}
describe
'#execute'
do
it
'creates a pending todo for new assignee'
do
attributes
=
{
project:
project
,
author:
current_user
,
user:
assignee
,
target_id:
issue
.
id
,
target_type:
issue
.
class
.
name
,
action:
Todo
::
ASSIGNED
,
state: :pending
}
expect
{
after_create_service
.
execute
(
issue
)
}.
to
change
{
Todo
.
where
(
attributes
).
count
}.
by
(
1
)
end
it
'deletes milestone issues count cache'
do
expect_next
(
Milestones
::
IssuesCountService
,
milestone
)
.
to
receive
(
:delete_cache
).
and_call_original
after_create_service
.
execute
(
issue
)
end
context
'with a regular issue'
do
it_behaves_like
'does not track incident management event'
,
:incident_management_incident_created
do
subject
{
after_create_service
.
execute
(
issue
)
}
end
end
context
'with an incident issue'
do
let
(
:issue
)
{
create
(
:issue
,
:incident
,
project:
project
,
author:
current_user
)
}
it_behaves_like
'an incident management tracked event'
,
:incident_management_incident_created
do
subject
{
after_create_service
.
execute
(
issue
)
}
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