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
2d1c67c2
Commit
2d1c67c2
authored
May 20, 2019
by
Shinya Maeda
Committed by
Ash McKenzie
Jun 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose merge train information
Exposed data will be rendered in merge request widgets
parent
4eb4ff3e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
3 deletions
+94
-3
ee/app/models/merge_train.rb
ee/app/models/merge_train.rb
+8
-0
ee/app/serializers/ee/merge_request_widget_entity.rb
ee/app/serializers/ee/merge_request_widget_entity.rb
+13
-1
ee/spec/models/merge_train_spec.rb
ee/spec/models/merge_train_spec.rb
+42
-0
ee/spec/serializers/merge_request_widget_entity_spec.rb
ee/spec/serializers/merge_request_widget_entity_spec.rb
+31
-2
No files found.
ee/app/models/merge_train.rb
View file @
2d1c67c2
...
@@ -14,6 +14,10 @@ class MergeTrain < ApplicationRecord
...
@@ -14,6 +14,10 @@ class MergeTrain < ApplicationRecord
all_in_train
(
merge_request
).
first
all_in_train
(
merge_request
).
first
end
end
def
total_count_in_train
(
merge_request
)
all_in_train
(
merge_request
).
count
end
def
joined_merge_requests
(
merge_request
)
def
joined_merge_requests
(
merge_request
)
MergeRequest
.
joins
(
:merge_train
)
MergeRequest
.
joins
(
:merge_train
)
.
where
(
'merge_requests.target_project_id = ?'
,
merge_request
.
target_project_id
)
.
where
(
'merge_requests.target_project_id = ?'
,
merge_request
.
target_project_id
)
...
@@ -25,6 +29,10 @@ class MergeTrain < ApplicationRecord
...
@@ -25,6 +29,10 @@ class MergeTrain < ApplicationRecord
self
.
class
.
all_in_train
(
merge_request
).
where
(
'merge_trains.id > ?'
,
id
)
self
.
class
.
all_in_train
(
merge_request
).
where
(
'merge_trains.id > ?'
,
id
)
end
end
def
index
self
.
class
.
all_in_train
(
merge_request
).
where
(
'merge_trains.id < ?'
,
id
).
count
end
def
first_in_train?
def
first_in_train?
!
follower_in_train?
!
follower_in_train?
end
end
...
...
ee/app/serializers/ee/merge_request_widget_entity.rb
View file @
2d1c67c2
...
@@ -136,7 +136,15 @@ module EE
...
@@ -136,7 +136,15 @@ module EE
end
end
expose
:merge_trains_enabled?
,
as: :merge_trains_enabled
do
|
merge_request
|
expose
:merge_trains_enabled?
,
as: :merge_trains_enabled
do
|
merge_request
|
merge_request
.
target_project
.
merge_trains_enabled?
merge_trains_enabled?
end
expose
:merge_trains_count
,
if:
->
(
*
)
{
merge_trains_enabled?
}
do
|
merge_request
|
MergeTrain
.
total_count_in_train
(
merge_request
)
end
expose
:merge_train_index
,
if:
->
(
merge_request
)
{
merge_request
.
on_train?
}
do
|
merge_request
|
merge_request
.
merge_train
.
index
end
end
expose
:can_push_to_source_branch
do
|
merge_request
|
expose
:can_push_to_source_branch
do
|
merge_request
|
...
@@ -176,5 +184,9 @@ module EE
...
@@ -176,5 +184,9 @@ module EE
object
.
base_pipeline
&
.
present
(
current_user:
current_user
)
object
.
base_pipeline
&
.
present
(
current_user:
current_user
)
&
.
downloadable_path_for_report_type
(
file_type
)
&
.
downloadable_path_for_report_type
(
file_type
)
end
end
def
merge_trains_enabled?
object
.
target_project
.
merge_trains_enabled?
end
end
end
end
end
ee/spec/models/merge_train_spec.rb
View file @
2d1c67c2
...
@@ -63,6 +63,32 @@ describe MergeTrain do
...
@@ -63,6 +63,32 @@ describe MergeTrain do
end
end
end
end
describe
'.total_count_in_train'
do
subject
{
described_class
.
total_count_in_train
(
merge_request
)
}
let!
(
:merge_request
)
{
create_merge_request_on_train
}
it
'returns the merge request'
do
is_expected
.
to
eq
(
1
)
end
context
'when the other merge request is on the merge train'
do
let!
(
:merge_request_2
)
{
create_merge_request_on_train
(
source_branch:
'improve/awesome'
)
}
it
'returns the merge request'
do
is_expected
.
to
eq
(
2
)
end
end
context
'when the merge request is not on merge train'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
'returns empty array'
do
is_expected
.
to
be
(
0
)
end
end
end
describe
'#all_next'
do
describe
'#all_next'
do
subject
{
merge_train
.
all_next
}
subject
{
merge_train
.
all_next
}
...
@@ -114,6 +140,22 @@ describe MergeTrain do
...
@@ -114,6 +140,22 @@ describe MergeTrain do
end
end
end
end
describe
'#index'
do
subject
{
merge_train
.
index
}
let
(
:merge_train
)
{
merge_request
.
merge_train
}
let!
(
:merge_request
)
{
create_merge_request_on_train
}
it
{
is_expected
.
to
eq
(
0
)
}
context
'when the merge train is at the second queue'
do
let
(
:merge_train
)
{
merge_request_2
.
merge_train
}
let!
(
:merge_request_2
)
{
create_merge_request_on_train
(
source_branch:
'improve/awesome'
)
}
it
{
is_expected
.
to
eq
(
1
)
}
end
end
def
create_merge_request_on_train
(
target_project:
project
,
target_branch:
'master'
,
source_project:
project
,
source_branch:
'feature'
)
def
create_merge_request_on_train
(
target_project:
project
,
target_branch:
'master'
,
source_project:
project
,
source_branch:
'feature'
)
create
(
:merge_request
,
create
(
:merge_request
,
:on_train
,
:on_train
,
...
...
ee/spec/serializers/merge_request_widget_entity_spec.rb
View file @
2d1c67c2
...
@@ -195,7 +195,36 @@ describe MergeRequestWidgetEntity do
...
@@ -195,7 +195,36 @@ describe MergeRequestWidgetEntity do
expect
(
subject
.
as_json
).
to
include
(
:pipeline_id
)
expect
(
subject
.
as_json
).
to
include
(
:pipeline_id
)
end
end
it
'has merge trains flag'
do
describe
'Merge Trains'
do
let!
(
:merge_train
)
{
create
(
:merge_train
,
merge_request:
merge_request
)
}
before
do
stub_licensed_features
(
merge_pipelines:
true
,
merge_trains:
true
)
project
.
update!
(
merge_trains_enabled:
true
,
merge_pipelines_enabled:
true
)
end
it
'has merge train entity'
do
expect
(
subject
.
as_json
).
to
include
(
:merge_trains_enabled
)
expect
(
subject
.
as_json
).
to
include
(
:merge_trains_enabled
)
expect
(
subject
.
as_json
).
to
include
(
:merge_trains_count
)
expect
(
subject
.
as_json
).
to
include
(
:merge_train_index
)
end
context
'when the merge train feature is disabled'
do
before
do
project
.
update!
(
merge_trains_enabled:
false
)
end
it
'does not have merge trains count'
do
expect
(
subject
.
as_json
).
not_to
include
(
:merge_trains_count
)
end
end
context
'when the merge request is not on a merge train'
do
let!
(
:merge_train
)
{
}
it
'does not have merge train index'
do
expect
(
subject
.
as_json
).
not_to
include
(
:merge_train_index
)
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