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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
74946c19
Commit
74946c19
authored
Jan 28, 2019
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move validation logic to service layer
parent
ba0509ed
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
26 additions
and
30 deletions
+26
-30
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+0
-7
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+1
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+3
-10
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+1
-1
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+0
-9
spec/services/merge_requests/create_service_spec.rb
spec/services/merge_requests/create_service_spec.rb
+18
-0
spec/services/merge_requests/refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+3
-3
No files found.
app/models/ci/pipeline.rb
View file @
74946c19
...
...
@@ -54,7 +54,6 @@ module Ci
validates
:ref
,
presence:
{
unless: :importing?
}
validates
:merge_request
,
presence:
{
if: :merge_request?
}
validates
:merge_request
,
absence:
{
unless: :merge_request?
}
validate
:presence_of_commits_in_merge_request
,
if: :merge_request?
validates
:tag
,
inclusion:
{
in:
[
false
],
if: :merge_request?
}
validates
:status
,
presence:
{
unless: :importing?
}
validate
:valid_commit_sha
,
unless: :importing?
...
...
@@ -751,11 +750,5 @@ module Ci
project
.
repository
.
keep_around
(
self
.
sha
,
self
.
before_sha
)
end
def
presence_of_commits_in_merge_request
if
merge_request
&
.
has_no_commits?
errors
.
add
(
:merge_request
,
"must have commits"
)
end
end
end
end
app/services/merge_requests/base_service.rb
View file @
74946c19
...
...
@@ -63,6 +63,7 @@ module MergeRequests
# UpdateMergeRequestsWorker could be retried by an exception.
# MR pipelines should not be recreated in such case.
return
if
merge_request
.
merge_request_pipeline_exists?
return
if
merge_request
.
has_no_commits?
Ci
::
CreatePipelineService
.
new
(
merge_request
.
source_project
,
user
,
ref:
merge_request
.
source_branch
)
...
...
spec/models/ci/pipeline_spec.rb
View file @
74946c19
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Ci
::
Pipeline
,
:mailer
do
let
(
:user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
status: :created
,
project:
project
)
...
...
@@ -131,18 +131,12 @@ describe Ci::Pipeline, :mailer do
context
'when source is merge request'
do
let
(
:source
)
{
:merge_request
}
context
'when merge request
with commits
is specified'
do
context
'when merge request is specified'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'feature'
,
target_project:
project
,
target_branch:
'master'
)
}
it
{
expect
(
pipeline
).
to
be_valid
}
end
context
'when merge request without commits is specified'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'not-merged-branch'
,
target_project:
project
,
target_branch:
'master'
)
}
it
{
expect
(
pipeline
).
not_to
be_valid
}
end
context
'when merge request is empty'
do
let
(
:merge_request
)
{
nil
}
...
...
@@ -1042,8 +1036,6 @@ describe Ci::Pipeline, :mailer do
end
context
'when repository does not exist'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
)
end
...
...
@@ -2079,6 +2071,7 @@ describe Ci::Pipeline, :mailer do
end
describe
"#all_merge_requests"
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
)
}
it
"returns all merge requests having the same source branch"
do
...
...
spec/models/merge_request_spec.rb
View file @
74946c19
...
...
@@ -1378,7 +1378,7 @@ describe MergeRequest do
source_project:
project
,
source_branch:
source_ref
,
target_project:
project
,
target_branch:
'
merge-test
'
)
target_branch:
'
stable
'
)
end
before
do
...
...
spec/services/ci/create_pipeline_service_spec.rb
View file @
74946c19
...
...
@@ -736,15 +736,6 @@ describe Ci::CreatePipelineService do
end
end
context
'when there are no commits between source branch and target branch'
do
let
(
:ref_name
)
{
'refs/heads/not-merged-branch'
}
it
'does not create a merge request pipeline'
do
expect
(
pipeline
).
not_to
be_persisted
expect
(
pipeline
.
errors
[
:merge_request
]).
to
eq
([
"must have commits"
])
end
end
context
'when merge request is created from a forked project'
do
let
(
:merge_request
)
do
create
(
:merge_request
,
...
...
spec/services/merge_requests/create_service_spec.rb
View file @
74946c19
...
...
@@ -226,6 +226,24 @@ describe MergeRequests::CreateService do
end
end
context
'when there are no commits between source branch and target branch'
do
let
(
:opts
)
do
{
title:
'Awesome merge_request'
,
description:
'please fix'
,
source_branch:
'not-merged-branch'
,
target_branch:
'master'
}
end
it
'does not create a merge request pipeline'
do
expect
(
merge_request
).
to
be_persisted
merge_request
.
reload
expect
(
merge_request
.
merge_request_pipelines
.
count
).
to
eq
(
0
)
end
end
context
"when .gitlab-ci.yml does not have merge_requests keywords"
do
let
(
:config
)
do
{
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
74946c19
...
...
@@ -156,9 +156,9 @@ describe MergeRequests::RefreshService do
.
and
change
{
@fork_merge_request
.
merge_request_pipelines
.
count
}.
by
(
1
)
.
and
change
{
@another_merge_request
.
merge_request_pipelines
.
count
}.
by
(
0
)
expect
(
@merge_request
.
has_commits?
).
to
be
true
expect
(
@fork_merge_request
.
has_commits?
).
to
be
true
expect
(
@another_merge_request
.
has_commits?
).
to
be
false
expect
(
@merge_request
.
has_commits?
).
to
be
_truthy
expect
(
@fork_merge_request
.
has_commits?
).
to
be
_truthy
expect
(
@another_merge_request
.
has_commits?
).
to
be
_falsy
end
context
"when branch pipeline was created before a merge request pipline has been created"
do
...
...
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