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
7fbb8e8d
Commit
7fbb8e8d
authored
Jun 04, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
a72e3410
0b864208
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
8 deletions
+93
-8
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-0
app/workers/all_queues.yml
app/workers/all_queues.yml
+2
-0
app/workers/auto_merge_process_worker.rb
app/workers/auto_merge_process_worker.rb
+14
-0
app/workers/pipeline_success_worker.rb
app/workers/pipeline_success_worker.rb
+1
-8
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+34
-0
spec/workers/auto_merge_process_worker_spec.rb
spec/workers/auto_merge_process_worker_spec.rb
+31
-0
No files found.
app/models/ci/pipeline.rb
View file @
7fbb8e8d
...
@@ -166,6 +166,16 @@ module Ci
...
@@ -166,6 +166,16 @@ module Ci
end
end
end
end
after_transition
any
=>
::
Ci
::
Pipeline
.
completed_statuses
do
|
pipeline
|
pipeline
.
run_after_commit
do
pipeline
.
all_merge_requests
.
each
do
|
merge_request
|
next
unless
merge_request
.
auto_merge_enabled?
AutoMergeProcessWorker
.
perform_async
(
merge_request
.
id
)
end
end
end
after_transition
any
=>
[
:success
,
:failed
]
do
|
pipeline
|
after_transition
any
=>
[
:success
,
:failed
]
do
|
pipeline
|
pipeline
.
run_after_commit
do
pipeline
.
run_after_commit
do
PipelineNotificationWorker
.
perform_async
(
pipeline
.
id
)
PipelineNotificationWorker
.
perform_async
(
pipeline
.
id
)
...
...
app/workers/all_queues.yml
View file @
7fbb8e8d
---
---
-
auto_devops:auto_devops_disable
-
auto_devops:auto_devops_disable
-
auto_merge:auto_merge_process
-
cronjob:admin_email
-
cronjob:admin_email
-
cronjob:expire_build_artifacts
-
cronjob:expire_build_artifacts
-
cronjob:gitlab_usage_ping
-
cronjob:gitlab_usage_ping
...
...
app/workers/auto_merge_process_worker.rb
0 → 100644
View file @
7fbb8e8d
# frozen_string_literal: true
class
AutoMergeProcessWorker
include
ApplicationWorker
queue_namespace
:auto_merge
def
perform
(
merge_request_id
)
MergeRequest
.
find_by_id
(
merge_request_id
).
try
do
|
merge_request
|
AutoMergeService
.
new
(
merge_request
.
project
,
merge_request
.
merge_user
)
.
process
(
merge_request
)
end
end
end
app/workers/pipeline_success_worker.rb
View file @
7fbb8e8d
...
@@ -6,14 +6,7 @@ class PipelineSuccessWorker
...
@@ -6,14 +6,7 @@ class PipelineSuccessWorker
queue_namespace
:pipeline_processing
queue_namespace
:pipeline_processing
# rubocop: disable CodeReuse/ActiveRecord
def
perform
(
pipeline_id
)
def
perform
(
pipeline_id
)
Ci
::
Pipeline
.
find_by
(
id:
pipeline_id
).
try
do
|
pipeline
|
# no-op
pipeline
.
all_merge_requests
.
preload
(
:merge_user
).
each
do
|
merge_request
|
AutoMergeService
.
new
(
pipeline
.
project
,
merge_request
.
merge_user
)
.
process
(
merge_request
)
end
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
config/sidekiq_queues.yml
View file @
7fbb8e8d
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
- [pipeline_default, 3]
- [pipeline_default, 3]
- [pipeline_cache, 3]
- [pipeline_cache, 3]
- [deployment, 3]
- [deployment, 3]
- [auto_merge, 3]
- [pipeline_hooks, 2]
- [pipeline_hooks, 2]
- [gitlab_shell, 2]
- [gitlab_shell, 2]
- [email_receiver, 2]
- [email_receiver, 2]
...
...
spec/models/ci/pipeline_spec.rb
View file @
7fbb8e8d
...
@@ -1381,6 +1381,40 @@ describe Ci::Pipeline, :mailer do
...
@@ -1381,6 +1381,40 @@ describe Ci::Pipeline, :mailer do
end
end
end
end
describe
'auto merge'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:merge_when_pipeline_succeeds
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
:running
,
project:
merge_request
.
source_project
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
end
before
do
merge_request
.
update_head_pipeline
end
%w[succeed! drop! cancel! skip!]
.
each
do
|
action
|
context
"when the pipeline recieved
#{
action
}
event"
do
it
'performs AutoMergeProcessWorker'
do
expect
(
AutoMergeProcessWorker
).
to
receive
(
:perform_async
).
with
(
merge_request
.
id
)
pipeline
.
public_send
(
action
)
end
end
end
context
'when auto merge is not enabled in the merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
'performs AutoMergeProcessWorker'
do
expect
(
AutoMergeProcessWorker
).
not_to
receive
(
:perform_async
)
pipeline
.
succeed!
end
end
end
def
create_build
(
name
,
*
traits
,
queued_at:
current
,
started_from:
0
,
**
opts
)
def
create_build
(
name
,
*
traits
,
queued_at:
current
,
started_from:
0
,
**
opts
)
create
(
:ci_build
,
*
traits
,
create
(
:ci_build
,
*
traits
,
name:
name
,
name:
name
,
...
...
spec/workers/
pipeline_suc
cess_worker_spec.rb
→
spec/workers/
auto_merge_pro
cess_worker_spec.rb
View file @
7fbb8e8d
...
@@ -2,25 +2,29 @@
...
@@ -2,25 +2,29 @@
require
'spec_helper'
require
'spec_helper'
describe
PipelineSuc
cessWorker
do
describe
AutoMergePro
cessWorker
do
describe
'#perform'
do
describe
'#perform'
do
context
'when pipeline exists'
do
subject
{
described_class
.
new
.
perform
(
merge_request
&
.
id
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
status:
'success'
,
ref:
merge_request
.
source_branch
,
project:
merge_request
.
source_project
)
}
context
'when merge request is found'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
'
performs "merge when pipeline succeeds"
'
do
it
'
executes AutoMergeService
'
do
expect_next_instance_of
(
AutoMergeService
)
do
|
auto_merge
|
expect_next_instance_of
(
AutoMergeService
)
do
|
auto_merge
|
expect
(
auto_merge
).
to
receive
(
:process
)
expect
(
auto_merge
).
to
receive
(
:process
)
end
end
described_class
.
new
.
perform
(
pipeline
.
id
)
subject
end
end
end
end
context
'when pipeline does not exist'
do
context
'when merge request is not found'
do
it
'does not raise exception'
do
let
(
:merge_request
)
{
nil
}
expect
{
described_class
.
new
.
perform
(
123
)
}
.
not_to
raise_error
it
'does not execute AutoMergeService'
do
expect
(
AutoMergeService
).
not_to
receive
(
:new
)
subject
end
end
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