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
d9bebd89
Commit
d9bebd89
authored
Mar 28, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs 2
parent
1bf2dacf
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
41 additions
and
36 deletions
+41
-36
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-8
db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb
...0170428170547_add_head_pipeline_for_each_merge_request.rb
+14
-12
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+4
-1
spec/features/cycle_analytics_spec.rb
spec/features/cycle_analytics_spec.rb
+8
-5
spec/features/merge_requests/widget_spec.rb
spec/features/merge_requests/widget_spec.rb
+3
-3
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+2
-2
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+3
-1
spec/services/merge_requests/merge_when_pipeline_succeeds_service_spec.rb
...rge_requests/merge_when_pipeline_succeeds_service_spec.rb
+1
-1
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+1
-1
spec/workers/pipeline_metrics_worker_spec.rb
spec/workers/pipeline_metrics_worker_spec.rb
+1
-1
No files found.
app/models/ci/pipeline.rb
View file @
d9bebd89
...
@@ -17,6 +17,9 @@ module Ci
...
@@ -17,6 +17,9 @@ module Ci
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
has_many
:builds
,
foreign_key: :commit_id
has_many
:builds
,
foreign_key: :commit_id
has_many
:trigger_requests
,
dependent: :destroy
,
foreign_key: :commit_id
has_many
:trigger_requests
,
dependent: :destroy
,
foreign_key: :commit_id
# Merge requests for which the current pipeline is running against
# the merge request's latest commit.
has_many
:merge_requests
,
foreign_key:
"head_pipeline_id"
has_many
:merge_requests
,
foreign_key:
"head_pipeline_id"
has_many
:pending_builds
,
->
{
pending
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
has_many
:pending_builds
,
->
{
pending
},
foreign_key: :commit_id
,
class_name:
'Ci::Build'
...
@@ -382,14 +385,6 @@ module Ci
...
@@ -382,14 +385,6 @@ module Ci
project
.
execute_services
(
data
,
:pipeline_hooks
)
project
.
execute_services
(
data
,
:pipeline_hooks
)
end
end
# Merge requests for which the current pipeline is running against
# the merge request's latest commit.
def
merge_requests
@merge_requests
||=
project
.
merge_requests
.
where
(
source_branch:
self
.
ref
)
.
select
{
|
merge_request
|
merge_request
.
head_pipeline
.
try
(
:id
)
==
self
.
id
}
end
# All the merge requests for which the current pipeline runs/ran against
# All the merge requests for which the current pipeline runs/ran against
def
all_merge_requests
def
all_merge_requests
@all_merge_requests
||=
project
.
merge_requests
.
where
(
source_branch:
ref
)
@all_merge_requests
||=
project
.
merge_requests
.
where
(
source_branch:
ref
)
...
...
db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb
View file @
d9bebd89
class
AddHeadPipelineForEachMergeRequest
<
ActiveRecord
::
Migration
class
AddHeadPipelineForEachMergeRequest
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
class
Pipeline
<
ActiveRecord
::
Base
def
up
self
.
table_name
=
"ci_pipelines"
disable_statement_timeout
def
self
.
last_per_branch
pipelines
=
Arel
::
Table
.
new
(
:ci_pipelines
)
select
(
'ref, MAX(id) as head_id, project_id'
).
group
(
:ref
).
group
(
:project_id
)
merge_requests
=
Arel
::
Table
.
new
(
:merge_requests
)
end
end
class
MergeRequest
<
ActiveRecord
::
Base
;
end
head_id
=
pipelines
.
project
(
Arel
::
Nodes
::
NamedFunction
.
new
(
'max'
,
[
pipelines
[
:id
]])).
from
(
pipelines
).
where
(
pipelines
[
:ref
].
eq
(
merge_requests
[
:source_branch
])).
where
(
pipelines
[
:project_id
].
eq
(
merge_requests
[
:source_project_id
]))
def
up
sub_query
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
Arel
::
Nodes
::
Grouping
.
new
(
head_id
).
to_sql
)
Pipeline
.
last_per_branch
.
each
do
|
pipeline
|
mrs
=
MergeRequest
.
where
(
source_branch:
pipeline
.
ref
,
source_project_id:
pipeline
.
project_id
)
update_column_in_batches
(
:merge_requests
,
:head_pipeline_id
,
sub_query
)
mrs
.
update_all
(
head_pipeline_id:
pipeline
.
head_id
)
end
end
end
def
down
def
down
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
d9bebd89
...
@@ -1200,7 +1200,10 @@ describe Projects::MergeRequestsController do
...
@@ -1200,7 +1200,10 @@ describe Projects::MergeRequestsController do
let
(
:status
)
{
pipeline
.
detailed_status
(
double
(
'user'
))
}
let
(
:status
)
{
pipeline
.
detailed_status
(
double
(
'user'
))
}
before
{
get_pipeline_status
}
before
do
merge_request
.
update
(
head_pipeline:
pipeline
)
get_pipeline_status
end
it
'return a detailed head_pipeline status in json'
do
it
'return a detailed head_pipeline status in json'
do
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_http_status
(
:ok
)
...
...
spec/features/cycle_analytics_spec.rb
View file @
d9bebd89
...
@@ -9,14 +9,17 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -9,14 +9,17 @@ feature 'Cycle Analytics', feature: true, js: true do
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
)
}
before
{
mr
.
update
(
head_pipeline:
pipeline
)
}
before
do
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
end
context
'as an allowed user'
do
context
'as an allowed user'
do
context
'when project is new'
do
context
'when project is new'
do
before
do
before
do
project
.
add_master
(
user
)
project
.
add_master
(
user
)
mr
.
update
(
head_pipeline_id:
pipeline
.
id
)
login_as
(
user
)
login_as
(
user
)
visit
namespace_project_cycle_analytics_path
(
project
.
namespace
,
project
)
visit
namespace_project_cycle_analytics_path
(
project
.
namespace
,
project
)
wait_for_ajax
wait_for_ajax
end
end
...
@@ -33,8 +36,8 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -33,8 +36,8 @@ 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
project
.
team
<<
[
user
,
:master
]
mr
.
update
(
head_pipeline:
pipeline
)
project
.
add_master
(
user
)
create_cycle
create_cycle
deploy_master
deploy_master
...
@@ -87,7 +90,7 @@ feature 'Cycle Analytics', feature: true, js: true do
...
@@ -87,7 +90,7 @@ feature 'Cycle Analytics', feature: true, js: true do
context
"as a guest"
do
context
"as a guest"
do
before
do
before
do
project
.
team
<<
[
guest
,
:guest
]
project
.
add_guest
(
guest
)
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
allow_any_instance_of
(
Gitlab
::
ReferenceExtractor
).
to
receive
(
:issues
).
and_return
([
issue
])
create_cycle
create_cycle
...
...
spec/features/merge_requests/widget_spec.rb
View file @
d9bebd89
...
@@ -89,7 +89,7 @@ describe 'Merge request', :feature, :js do
...
@@ -89,7 +89,7 @@ describe 'Merge request', :feature, :js do
statuses:
[
commit_status
])
statuses:
[
commit_status
])
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
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
...
@@ -111,7 +111,7 @@ describe 'Merge request', :feature, :js do
...
@@ -111,7 +111,7 @@ describe 'Merge request', :feature, :js do
status: :manual
status: :manual
)
)
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
merge_request
.
update
(
head_pipeline
:
pipeline
)
visit
namespace_project_merge_request_path
(
project
.
namespace
,
visit
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
project
,
...
@@ -136,7 +136,7 @@ describe 'Merge request', :feature, :js do
...
@@ -136,7 +136,7 @@ describe 'Merge request', :feature, :js do
statuses:
[
commit_status
])
statuses:
[
commit_status
])
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
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 @
d9bebd89
...
@@ -130,7 +130,7 @@ describe 'cycle analytics events' do
...
@@ -130,7 +130,7 @@ describe 'cycle analytics events' do
end
end
before
do
before
do
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
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
)
...
@@ -228,7 +228,7 @@ describe 'cycle analytics events' do
...
@@ -228,7 +228,7 @@ describe 'cycle analytics events' do
end
end
before
do
before
do
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
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/ci/pipeline_spec.rb
View file @
d9bebd89
...
@@ -1045,7 +1045,7 @@ describe Ci::Pipeline, models: true do
...
@@ -1045,7 +1045,7 @@ describe Ci::Pipeline, models: true do
it
"returns merge requests whose `diff_head_sha` matches the pipeline's SHA"
do
it
"returns merge requests whose `diff_head_sha` matches the pipeline's SHA"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:diff_head_sha
)
{
'a288a022a53a5a944fae87bcec6efc87b7061808'
}
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:diff_head_sha
)
{
'a288a022a53a5a944fae87bcec6efc87b7061808'
}
merge_request
=
create
(
:merge_request
,
source_project:
project
,
head_pipeline:
pipeline
,
,
source_branch:
pipeline
.
ref
)
merge_request
=
create
(
:merge_request
,
source_project:
project
,
head_pipeline:
pipeline
,
source_branch:
pipeline
.
ref
)
expect
(
pipeline
.
merge_requests
).
to
eq
([
merge_request
])
expect
(
pipeline
.
merge_requests
).
to
eq
([
merge_request
])
end
end
...
...
spec/models/merge_request_spec.rb
View file @
d9bebd89
...
@@ -1507,6 +1507,8 @@ describe MergeRequest, models: true do
...
@@ -1507,6 +1507,8 @@ describe MergeRequest, models: true do
status:
status
)
status:
status
)
merge_request
.
update
(
head_pipeline:
pipeline
)
merge_request
.
update
(
head_pipeline:
pipeline
)
pipeline
end
end
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
only_allow_merge_if_pipeline_succeeds:
true
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
,
only_allow_merge_if_pipeline_succeeds:
true
)
}
...
@@ -1592,7 +1594,7 @@ describe MergeRequest, models: true do
...
@@ -1592,7 +1594,7 @@ describe MergeRequest, models: true do
context
'with running pipeline'
do
context
'with running pipeline'
do
before
do
before
do
merge_request
.
update
(
head_pipeline:
create_pipeline
(
:running
)
)
create_pipeline
(
:running
)
end
end
it
'is mergeable'
do
it
'is mergeable'
do
...
...
spec/services/merge_requests/merge_when_pipeline_succeeds_service_spec.rb
View file @
d9bebd89
...
@@ -128,7 +128,7 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
...
@@ -128,7 +128,7 @@ describe MergeRequests::MergeWhenPipelineSucceedsService do
sha:
mr_conflict
.
diff_head_sha
,
status:
'success'
)
sha:
mr_conflict
.
diff_head_sha
,
status:
'success'
)
end
end
before
{
mr_conflict
.
update
(
head_pipeline
_id:
conflict_pipeline
.
id
)
}
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 @
d9bebd89
...
@@ -179,7 +179,7 @@ describe MergeRequests::UpdateService, services: true do
...
@@ -179,7 +179,7 @@ describe MergeRequests::UpdateService, services: true do
ref:
merge_request
.
source_branch
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
)
sha:
merge_request
.
diff_head_sha
)
merge_request
.
update
(
head_pipeline
_id:
pipeline
.
id
)
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
)
...
...
spec/workers/pipeline_metrics_worker_spec.rb
View file @
d9bebd89
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
PipelineMetricsWorker
do
describe
PipelineMetricsWorker
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
,
head_pipeline
_id:
pipeline
.
id
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
,
head_pipeline
:
pipeline
)
}
let
(
:pipeline
)
do
let
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
create
(
:ci_empty_pipeline
,
...
...
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