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
921c2be4
Commit
921c2be4
authored
May 19, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add transient head_pipeline_of to pipeline factories
parent
9d29eb7e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
50 additions
and
52 deletions
+50
-52
features/steps/project/merge_requests.rb
features/steps/project/merge_requests.rb
+8
-2
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+3
-4
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+9
-0
spec/features/cycle_analytics_spec.rb
spec/features/cycle_analytics_spec.rb
+1
-2
spec/features/merge_requests/merge_when_pipeline_succeeds_spec.rb
...tures/merge_requests/merge_when_pipeline_succeeds_spec.rb
+2
-2
spec/features/merge_requests/only_allow_merge_if_build_succeeds_spec.rb
...merge_requests/only_allow_merge_if_build_succeeds_spec.rb
+1
-3
spec/features/merge_requests/widget_spec.rb
spec/features/merge_requests/widget_spec.rb
+7
-11
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+4
-6
spec/models/cycle_analytics/test_spec.rb
spec/models/cycle_analytics/test_spec.rb
+1
-2
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+3
-5
spec/requests/projects/cycle_analytics_events_spec.rb
spec/requests/projects/cycle_analytics_events_spec.rb
+1
-2
spec/services/merge_requests/merge_when_pipeline_succeeds_service_spec.rb
...rge_requests/merge_when_pipeline_succeeds_service_spec.rb
+4
-8
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+6
-5
No files found.
features/steps/project/merge_requests.rb
View file @
921c2be4
...
@@ -556,8 +556,14 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
...
@@ -556,8 +556,14 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
step
'"Bug NS-05" has CI status'
do
step
'"Bug NS-05" has CI status'
do
project
=
merge_request
.
source_project
project
=
merge_request
.
source_project
project
.
enable_ci
project
.
enable_ci
pipeline
=
create
:ci_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
merge_request
.
update
(
head_pipeline:
pipeline
)
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
head_pipeline_of:
merge_request
)
create
:ci_build
,
pipeline:
pipeline
create
:ci_build
,
pipeline:
pipeline
end
end
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
921c2be4
...
@@ -345,8 +345,7 @@ describe Projects::MergeRequestsController do
...
@@ -345,8 +345,7 @@ describe Projects::MergeRequestsController do
end
end
before
do
before
do
pipeline
=
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
)
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
head_pipeline_of:
merge_request
)
merge_request
.
update
(
head_pipeline:
pipeline
)
end
end
it
'returns :merge_when_pipeline_succeeds'
do
it
'returns :merge_when_pipeline_succeeds'
do
...
@@ -1161,13 +1160,13 @@ describe Projects::MergeRequestsController do
...
@@ -1161,13 +1160,13 @@ describe Projects::MergeRequestsController do
let!
(
:pipeline
)
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
merge_request
.
source_project
,
create
(
:ci_pipeline
,
project:
merge_request
.
source_project
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
sha:
merge_request
.
diff_head_sha
,
head_pipeline_of:
merge_request
)
end
end
let
(
:status
)
{
pipeline
.
detailed_status
(
double
(
'user'
))
}
let
(
:status
)
{
pipeline
.
detailed_status
(
double
(
'user'
))
}
before
do
before
do
merge_request
.
update
(
head_pipeline:
pipeline
)
get_pipeline_status
get_pipeline_status
end
end
...
...
spec/factories/ci/pipelines.rb
View file @
921c2be4
...
@@ -20,6 +20,15 @@ FactoryGirl.define do
...
@@ -20,6 +20,15 @@ FactoryGirl.define do
end
end
end
end
# Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references
transient
{
head_pipeline_of
nil
}
after
(
:create
)
do
|
pipeline
,
evaluator
|
merge_request
=
evaluator
.
head_pipeline_of
merge_request
&
.
update
(
head_pipeline:
pipeline
)
end
factory
:ci_pipeline
do
factory
:ci_pipeline
do
transient
{
config
nil
}
transient
{
config
nil
}
...
...
spec/features/cycle_analytics_spec.rb
View file @
921c2be4
...
@@ -7,7 +7,7 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -7,7 +7,7 @@ feature 'Cycle Analytics', feature: true, js: true do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let
(
:mr
)
{
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
}
let
(
:mr
)
{
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
,
head_pipeline_of:
mr
)
}
context
'as an allowed user'
do
context
'as an allowed user'
do
context
'when project is new'
do
context
'when project is new'
do
...
@@ -33,7 +33,6 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -33,7 +33,6 @@ feature 'Cycle Analytics', feature: true, js: true do
context
"when there's cycle analytics data"
do
context
"when there's cycle analytics data"
do
before
do
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
mr
.
update
(
head_pipeline:
pipeline
)
project
.
add_master
(
user
)
project
.
add_master
(
user
)
create_cycle
create_cycle
...
...
spec/features/merge_requests/merge_when_pipeline_succeeds_spec.rb
View file @
921c2be4
...
@@ -13,12 +13,12 @@ feature 'Merge When Pipeline Succeeds', :feature, :js do
...
@@ -13,12 +13,12 @@ feature 'Merge When Pipeline Succeeds', :feature, :js do
let
(
:pipeline
)
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
create
(
:ci_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
)
ref:
merge_request
.
source_branch
,
head_pipeline_of:
merge_request
)
end
end
before
do
before
do
project
.
add_master
(
user
)
project
.
add_master
(
user
)
merge_request
.
update
(
head_pipeline_id:
pipeline
.
id
)
end
end
context
'when there is active pipeline for merge request'
do
context
'when there is active pipeline for merge request'
do
...
...
spec/features/merge_requests/only_allow_merge_if_build_succeeds_spec.rb
View file @
921c2be4
...
@@ -28,11 +28,9 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', featu
...
@@ -28,11 +28,9 @@ feature 'Only allow merge requests to be merged if the pipeline succeeds', featu
project:
project
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
status:
status
)
status:
status
,
head_pipeline_of:
merge_request
)
end
end
before
{
merge_request
.
update
(
head_pipeline:
pipeline
)
}
context
'when merge requests can only be merged if the pipeline succeeds'
do
context
'when merge requests can only be merged if the pipeline succeeds'
do
before
do
before
do
project
.
update_attribute
(
:only_allow_merge_if_pipeline_succeeds
,
true
)
project
.
update_attribute
(
:only_allow_merge_if_pipeline_succeeds
,
true
)
...
...
spec/features/merge_requests/widget_spec.rb
View file @
921c2be4
...
@@ -88,11 +88,10 @@ describe 'Merge request', :feature, :js do
...
@@ -88,11 +88,10 @@ describe 'Merge request', :feature, :js do
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
status:
'failed'
,
status:
'failed'
,
statuses:
[
commit_status
])
statuses:
[
commit_status
],
head_pipeline_of:
merge_request
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
end
end
...
@@ -105,15 +104,13 @@ describe 'Merge request', :feature, :js do
...
@@ -105,15 +104,13 @@ describe 'Merge request', :feature, :js do
context
'when merge request is in the blocked pipeline state'
do
context
'when merge request is in the blocked pipeline state'
do
before
do
before
do
pipeline
=
create
(
create
(
:ci_pipeline
,
:ci_pipeline
,
project:
project
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
status: :manual
status: :manual
,
)
head_pipeline_of:
merge_request
)
merge_request
.
update
(
head_pipeline:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
project
,
...
@@ -135,11 +132,10 @@ describe 'Merge request', :feature, :js do
...
@@ -135,11 +132,10 @@ describe 'Merge request', :feature, :js do
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
status:
'pending'
,
status:
'pending'
,
statuses:
[
commit_status
])
statuses:
[
commit_status
],
head_pipeline_of:
merge_request
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
end
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
921c2be4
...
@@ -126,12 +126,11 @@ describe 'cycle analytics events' do
...
@@ -126,12 +126,11 @@ describe 'cycle analytics events' do
create
(
:ci_pipeline
,
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
project:
context
.
project
,
head_pipeline_of:
merge_request
)
end
end
before
do
before
do
merge_request
.
update
(
head_pipeline:
pipeline
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
...
@@ -224,12 +223,11 @@ describe 'cycle analytics events' do
...
@@ -224,12 +223,11 @@ describe 'cycle analytics events' do
create
(
:ci_pipeline
,
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
project:
context
.
project
,
head_pipeline_of:
merge_request
)
end
end
before
do
before
do
merge_request
.
update
(
head_pipeline:
pipeline
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
...
...
spec/models/cycle_analytics/test_spec.rb
View file @
921c2be4
...
@@ -13,8 +13,7 @@ describe 'CycleAnalytics#test', feature: true do
...
@@ -13,8 +13,7 @@ describe 'CycleAnalytics#test', feature: true do
data_fn:
lambda
do
|
context
|
data_fn:
lambda
do
|
context
|
issue
=
context
.
create
(
:issue
,
project:
context
.
project
)
issue
=
context
.
create
(
:issue
,
project:
context
.
project
)
merge_request
=
context
.
create_merge_request_closing_issue
(
issue
)
merge_request
=
context
.
create_merge_request_closing_issue
(
issue
)
pipeline
=
context
.
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
pipeline
=
context
.
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
,
head_pipeline_of:
merge_request
)
merge_request
.
update
(
head_pipeline:
pipeline
)
{
pipeline:
pipeline
,
issue:
issue
}
{
pipeline:
pipeline
,
issue:
issue
}
end
,
end
,
start_time_conditions:
[[
"pipeline is started"
,
->
(
context
,
data
)
{
data
[
:pipeline
].
run!
}]],
start_time_conditions:
[[
"pipeline is started"
,
->
(
context
,
data
)
{
data
[
:pipeline
].
run!
}]],
...
...
spec/models/merge_request_spec.rb
View file @
921c2be4
...
@@ -718,8 +718,7 @@ describe MergeRequest, models: true do
...
@@ -718,8 +718,7 @@ describe MergeRequest, models: true do
describe
'#head_pipeline'
do
describe
'#head_pipeline'
do
describe
'when the source project exists'
do
describe
'when the source project exists'
do
it
'returns the latest pipeline'
do
it
'returns the latest pipeline'
do
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
"123abc"
)
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
"123abc"
,
head_pipeline_of:
subject
)
subject
.
update
(
head_pipeline:
pipeline
)
expect
(
subject
.
head_pipeline
).
to
eq
(
pipeline
)
expect
(
subject
.
head_pipeline
).
to
eq
(
pipeline
)
end
end
...
@@ -1396,9 +1395,8 @@ describe MergeRequest, models: true do
...
@@ -1396,9 +1395,8 @@ describe MergeRequest, models: true do
project:
project
,
project:
project
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
sha:
merge_request
.
diff_head_sha
,
status:
status
)
status:
status
,
head_pipeline_of:
merge_request
)
merge_request
.
update
(
head_pipeline:
pipeline
)
pipeline
pipeline
end
end
...
...
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
921c2be4
...
@@ -121,8 +121,7 @@ describe 'cycle analytics events', api: true do
...
@@ -121,8 +121,7 @@ describe 'cycle analytics events', api: true do
issue
.
update
(
milestone:
milestone
)
issue
.
update
(
milestone:
milestone
)
mr
=
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
mr
=
create_merge_request_closing_issue
(
issue
,
commit_message:
"References
#{
issue
.
to_reference
}
"
)
pipeline
=
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
)
pipeline
=
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
,
head_pipeline_of:
mr
)
mr
.
update
(
head_pipeline_id:
pipeline
.
id
)
pipeline
.
run
pipeline
.
run
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
create
(
:ci_build
,
pipeline:
pipeline
,
status: :success
,
author:
user
)
...
...
spec/services/merge_requests/merge_when_pipeline_succeeds_service_spec.rb
View file @
921c2be4
...
@@ -79,11 +79,8 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
...
@@ -79,11 +79,8 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
context
'when triggered by pipeline with valid ref and sha'
do
context
'when triggered by pipeline with valid ref and sha'
do
let
(
:triggering_pipeline
)
do
let
(
:triggering_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
merge_request_ref
,
create
(
:ci_pipeline
,
project:
project
,
ref:
merge_request_ref
,
sha:
merge_request_head
,
status:
'success'
)
sha:
merge_request_head
,
status:
'success'
,
end
head_pipeline_of:
mr_merge_if_green_enabled
)
before
do
mr_merge_if_green_enabled
.
update
(
head_pipeline:
triggering_pipeline
)
end
end
it
"merges all merge requests with merge when the pipeline succeeds enabled"
do
it
"merges all merge requests with merge when the pipeline succeeds enabled"
do
...
@@ -125,11 +122,10 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
...
@@ -125,11 +122,10 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
let
(
:conflict_pipeline
)
do
let
(
:conflict_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
mr_conflict
.
source_branch
,
create
(
:ci_pipeline
,
project:
project
,
ref:
mr_conflict
.
source_branch
,
sha:
mr_conflict
.
diff_head_sha
,
status:
'success'
)
sha:
mr_conflict
.
diff_head_sha
,
status:
'success'
,
head_pipeline_of:
mr_conflict
)
end
end
before
{
mr_conflict
.
update
(
head_pipeline:
conflict_pipeline
)
}
it
'does not merge the merge request'
do
it
'does not merge the merge request'
do
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
921c2be4
...
@@ -180,12 +180,13 @@ describe MergeRequests::UpdateService, services: true do
...
@@ -180,12 +180,13 @@ describe MergeRequests::UpdateService, services: true do
context
'with active pipeline'
do
context
'with active pipeline'
do
before
do
before
do
service_mock
=
double
service_mock
=
double
pipeline
=
create
(
:ci_pipeline_with_one_job
,
create
(
:ci_pipeline_with_one_job
,
project:
project
,
project:
project
,
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
sha:
merge_request
.
diff_head_sha
,
head_pipeline_of:
merge_request
merge_request
.
update
(
head_pipeline:
pipeline
)
)
expect
(
MergeRequests
::
MergeWhenPipelineSucceedsService
).
to
receive
(
:new
).
with
(
project
,
user
).
expect
(
MergeRequests
::
MergeWhenPipelineSucceedsService
).
to
receive
(
:new
).
with
(
project
,
user
).
and_return
(
service_mock
)
and_return
(
service_mock
)
...
...
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