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
250c1855
Commit
250c1855
authored
Feb 28, 2020
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move NewMergeRequestWorker methods to a service
This makes it easier to refactor in future commits.
parent
ed76ea7d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
13 deletions
+65
-13
app/services/merge_requests/after_create_service.rb
app/services/merge_requests/after_create_service.rb
+13
-0
app/services/merge_requests/create_service.rb
app/services/merge_requests/create_service.rb
+4
-8
app/workers/new_merge_request_worker.rb
app/workers/new_merge_request_worker.rb
+3
-5
spec/services/merge_requests/after_create_service_spec.rb
spec/services/merge_requests/after_create_service_spec.rb
+45
-0
No files found.
app/services/merge_requests/after_create_service.rb
0 → 100644
View file @
250c1855
# frozen_string_literal: true
module
MergeRequests
class
AfterCreateService
<
MergeRequests
::
BaseService
def
execute
(
merge_request
)
event_service
.
open_mr
(
merge_request
,
current_user
)
notification_service
.
new_merge_request
(
merge_request
,
current_user
)
merge_request
.
diffs
(
include_stats:
false
).
write_cache
merge_request
.
create_cross_references!
(
current_user
)
end
end
end
app/services/merge_requests/create_service.rb
View file @
250c1855
...
@@ -13,15 +13,11 @@ module MergeRequests
...
@@ -13,15 +13,11 @@ module MergeRequests
create
(
merge_request
)
create
(
merge_request
)
end
end
def
before_create
(
merge_request
)
# current_user (defined in BaseService) is not available within run_after_commit block
user
=
current_user
merge_request
.
run_after_commit
do
NewMergeRequestWorker
.
perform_async
(
merge_request
.
id
,
user
.
id
)
end
end
def
after_create
(
issuable
)
def
after_create
(
issuable
)
# Add new items to MergeRequests::AfterCreateService if they can
# be performed in Sidekiq
NewMergeRequestWorker
.
perform_async
(
issuable
.
id
,
current_user
.
id
)
todo_service
.
new_merge_request
(
issuable
,
current_user
)
todo_service
.
new_merge_request
(
issuable
,
current_user
)
issuable
.
cache_merge_request_closes_issues!
(
current_user
)
issuable
.
cache_merge_request_closes_issues!
(
current_user
)
create_pipeline_for
(
issuable
,
current_user
)
create_pipeline_for
(
issuable
,
current_user
)
...
...
app/workers/new_merge_request_worker.rb
View file @
250c1855
...
@@ -12,11 +12,9 @@ class NewMergeRequestWorker # rubocop:disable Scalability/IdempotentWorker
...
@@ -12,11 +12,9 @@ class NewMergeRequestWorker # rubocop:disable Scalability/IdempotentWorker
def
perform
(
merge_request_id
,
user_id
)
def
perform
(
merge_request_id
,
user_id
)
return
unless
objects_found?
(
merge_request_id
,
user_id
)
return
unless
objects_found?
(
merge_request_id
,
user_id
)
EventCreateService
.
new
.
open_mr
(
issuable
,
user
)
MergeRequests
::
AfterCreateService
NotificationService
.
new
.
new_merge_request
(
issuable
,
user
)
.
new
(
issuable
.
target_project
,
user
)
.
execute
(
issuable
)
issuable
.
diffs
(
include_stats:
false
).
write_cache
issuable
.
create_cross_references!
(
user
)
end
end
def
issuable_class
def
issuable_class
...
...
spec/services/merge_requests/after_create_service_spec.rb
0 → 100644
View file @
250c1855
# frozen_string_literal: true
require
'spec_helper'
describe
MergeRequests
::
AfterCreateService
do
let_it_be
(
:merge_request
)
{
create
(
:merge_request
)
}
subject
(
:after_create_service
)
do
described_class
.
new
(
merge_request
.
target_project
,
merge_request
.
author
)
end
describe
'#execute'
do
let
(
:event_service
)
{
instance_double
(
'EventCreateService'
,
open_mr:
true
)
}
let
(
:notification_service
)
{
instance_double
(
'NotificationService'
,
new_merge_request:
true
)
}
before
do
allow
(
after_create_service
).
to
receive
(
:event_service
).
and_return
(
event_service
)
allow
(
after_create_service
).
to
receive
(
:notification_service
).
and_return
(
notification_service
)
end
it
'creates a merge request open event'
do
expect
(
event_service
).
to
receive
(
:open_mr
).
with
(
merge_request
,
merge_request
.
author
)
after_create_service
.
execute
(
merge_request
)
end
it
'creates a new merge request notification'
do
expect
(
notification_service
).
to
receive
(
:new_merge_request
).
with
(
merge_request
,
merge_request
.
author
)
after_create_service
.
execute
(
merge_request
)
end
it
'writes diffs to the cache'
do
expect
(
merge_request
).
to
receive_message_chain
(
:diffs
,
:write_cache
)
after_create_service
.
execute
(
merge_request
)
end
it
'creates cross references'
do
expect
(
merge_request
).
to
receive
(
:create_cross_references!
).
with
(
merge_request
.
author
)
after_create_service
.
execute
(
merge_request
)
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