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
Jérome Perrin
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
step
'"Bug NS-05" has CI status'
do
project
=
merge_request
.
source_project
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
end
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
921c2be4
...
...
@@ -345,8 +345,7 @@ describe Projects::MergeRequestsController do
end
before
do
pipeline
=
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
)
merge_request
.
update
(
head_pipeline:
pipeline
)
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
head_pipeline_of:
merge_request
)
end
it
'returns :merge_when_pipeline_succeeds'
do
...
...
@@ -1161,13 +1160,13 @@ describe Projects::MergeRequestsController do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
merge_request
.
source_project
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
sha:
merge_request
.
diff_head_sha
,
head_pipeline_of:
merge_request
)
end
let
(
:status
)
{
pipeline
.
detailed_status
(
double
(
'user'
))
}
before
do
merge_request
.
update
(
head_pipeline:
pipeline
)
get_pipeline_status
end
...
...
spec/factories/ci/pipelines.rb
View file @
921c2be4
...
...
@@ -20,6 +20,15 @@ FactoryGirl.define do
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
transient
{
config
nil
}
...
...
spec/features/cycle_analytics_spec.rb
View file @
921c2be4
...
...
@@ -7,7 +7,7 @@ feature 'Cycle Analytics', feature: true, js: true do
let
(
:issue
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
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
'when project is new'
do
...
...
@@ -33,7 +33,6 @@ feature 'Cycle Analytics', feature: true, js: true do
context
"when there's cycle analytics data"
do
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
mr
.
update
(
head_pipeline:
pipeline
)
project
.
add_master
(
user
)
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
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
)
ref:
merge_request
.
source_branch
,
head_pipeline_of:
merge_request
)
end
before
do
project
.
add_master
(
user
)
merge_request
.
update
(
head_pipeline_id:
pipeline
.
id
)
end
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
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
status:
status
)
status:
status
,
head_pipeline_of:
merge_request
)
end
before
{
merge_request
.
update
(
head_pipeline:
pipeline
)
}
context
'when merge requests can only be merged if the pipeline succeeds'
do
before
do
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
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
status:
'failed'
,
statuses:
[
commit_status
])
statuses:
[
commit_status
],
head_pipeline_of:
merge_request
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
end
...
...
@@ -105,15 +104,13 @@ describe 'Merge request', :feature, :js do
context
'when merge request is in the blocked pipeline state'
do
before
do
pipeline
=
create
(
create
(
:ci_pipeline
,
project:
project
,
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
status: :manual
)
merge_request
.
update
(
head_pipeline:
pipeline
)
status: :manual
,
head_pipeline_of:
merge_request
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
...
...
@@ -135,11 +132,10 @@ describe 'Merge request', :feature, :js do
sha:
merge_request
.
diff_head_sha
,
ref:
merge_request
.
source_branch
,
status:
'pending'
,
statuses:
[
commit_status
])
statuses:
[
commit_status
],
head_pipeline_of:
merge_request
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
)
end
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
921c2be4
...
...
@@ -126,12 +126,11 @@ describe 'cycle analytics events' do
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
project:
context
.
project
,
head_pipeline_of:
merge_request
)
end
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
)
...
...
@@ -224,12 +223,11 @@ describe 'cycle analytics events' do
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
project:
context
.
project
,
head_pipeline_of:
merge_request
)
end
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
)
...
...
spec/models/cycle_analytics/test_spec.rb
View file @
921c2be4
...
...
@@ -13,8 +13,7 @@ describe 'CycleAnalytics#test', feature: true do
data_fn:
lambda
do
|
context
|
issue
=
context
.
create
(
:issue
,
project:
context
.
project
)
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
)
merge_request
.
update
(
head_pipeline:
pipeline
)
pipeline
=
context
.
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
,
head_pipeline_of:
merge_request
)
{
pipeline:
pipeline
,
issue:
issue
}
end
,
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
describe
'#head_pipeline'
do
describe
'when the source project exists'
do
it
'returns the latest pipeline'
do
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
"123abc"
)
subject
.
update
(
head_pipeline:
pipeline
)
pipeline
=
create
(
:ci_empty_pipeline
,
project:
subject
.
source_project
,
ref:
'master'
,
status:
'running'
,
sha:
"123abc"
,
head_pipeline_of:
subject
)
expect
(
subject
.
head_pipeline
).
to
eq
(
pipeline
)
end
...
...
@@ -1396,9 +1395,8 @@ describe MergeRequest, models: true do
project:
project
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
status:
status
)
merge_request
.
update
(
head_pipeline:
pipeline
)
status:
status
,
head_pipeline_of:
merge_request
)
pipeline
end
...
...
spec/requests/projects/cycle_analytics_events_spec.rb
View file @
921c2be4
...
...
@@ -121,8 +121,7 @@ describe 'cycle analytics events', api: true do
issue
.
update
(
milestone:
milestone
)
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
)
mr
.
update
(
head_pipeline_id:
pipeline
.
id
)
pipeline
=
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
mr
.
source_branch
,
sha:
mr
.
source_branch_sha
,
head_pipeline_of:
mr
)
pipeline
.
run
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
context
'when triggered by pipeline with valid ref and sha'
do
let
(
:triggering_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
merge_request_ref
,
sha:
merge_request_head
,
status:
'success'
)
end
before
do
mr_merge_if_green_enabled
.
update
(
head_pipeline:
triggering_pipeline
)
sha:
merge_request_head
,
status:
'success'
,
head_pipeline_of:
mr_merge_if_green_enabled
)
end
it
"merges all merge requests with merge when the pipeline succeeds enabled"
do
...
...
@@ -125,11 +122,10 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
let
(
:conflict_pipeline
)
do
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
before
{
mr_conflict
.
update
(
head_pipeline:
conflict_pipeline
)
}
it
'does not merge the merge request'
do
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
context
'with active pipeline'
do
before
do
service_mock
=
double
pipeline
=
create
(
:ci_pipeline_with_one_job
,
create
(
:ci_pipeline_with_one_job
,
project:
project
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
merge_request
.
update
(
head_pipeline:
pipeline
)
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
head_pipeline_of:
merge_request
)
expect
(
MergeRequests
::
MergeWhenPipelineSucceedsService
).
to
receive
(
:new
).
with
(
project
,
user
).
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