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
2eea8e1b
Commit
2eea8e1b
authored
Mar 06, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
af13f9a9
81a0cc25
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
151 additions
and
0 deletions
+151
-0
app/presenters/merge_request_presenter.rb
app/presenters/merge_request_presenter.rb
+6
-0
app/serializers/merge_request_for_pipeline_entity.rb
app/serializers/merge_request_for_pipeline_entity.rb
+17
-0
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+10
-0
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+1
-0
changelogs/unreleased/expose-merge-request-entity-for-pipelines.yml
.../unreleased/expose-merge-request-entity-for-pipelines.yml
+5
-0
spec/serializers/merge_request_for_pipeline_entity_spec.rb
spec/serializers/merge_request_for_pipeline_entity_spec.rb
+29
-0
spec/serializers/pipeline_entity_spec.rb
spec/serializers/pipeline_entity_spec.rb
+45
-0
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+38
-0
No files found.
app/presenters/merge_request_presenter.rb
View file @
2eea8e1b
...
...
@@ -98,6 +98,12 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end
end
def
target_branch_path
if
target_branch_exists?
project_branch_path
(
project
,
target_branch
)
end
end
def
source_branch_path
if
source_branch_exists?
project_branch_path
(
source_project
,
source_branch
)
...
...
app/serializers/merge_request_for_pipeline_entity.rb
0 → 100644
View file @
2eea8e1b
# frozen_string_literal: true
class
MergeRequestForPipelineEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:iid
expose
:path
do
|
merge_request
|
project_merge_request_path
(
merge_request
.
project
,
merge_request
)
end
expose
:title
expose
:source_branch
expose
:source_branch_path
expose
:target_branch
expose
:target_branch_path
end
app/serializers/pipeline_entity.rb
View file @
2eea8e1b
...
...
@@ -28,6 +28,7 @@ class PipelineEntity < Grape::Entity
expose
:can_retry?
,
as: :retryable
expose
:can_cancel?
,
as: :cancelable
expose
:failure_reason?
,
as: :failure_reason
expose
:detached_merge_request_pipeline?
,
as: :detached
end
expose
:details
do
...
...
@@ -36,6 +37,10 @@ class PipelineEntity < Grape::Entity
expose
:finished_at
end
expose
:merge_request
,
if:
->
(
*
)
{
has_presentable_merge_request?
},
with:
MergeRequestForPipelineEntity
do
|
pipeline
|
pipeline
.
merge_request
.
present
(
current_user:
request
.
current_user
)
end
expose
:ref
do
expose
:name
do
|
pipeline
|
pipeline
.
ref
...
...
@@ -81,6 +86,11 @@ class PipelineEntity < Grape::Entity
pipeline
.
cancelable?
end
def
has_presentable_merge_request?
pipeline
.
triggered_by_merge_request?
&&
can?
(
request
.
current_user
,
:read_merge_request
,
pipeline
.
merge_request
)
end
def
detailed_status
pipeline
.
detailed_status
(
request
.
current_user
)
end
...
...
app/serializers/pipeline_serializer.rb
View file @
2eea8e1b
...
...
@@ -17,6 +17,7 @@ class PipelineSerializer < BaseSerializer
:manual_actions
,
:scheduled_actions
,
:artifacts
,
:merge_request
,
{
pending_builds: :project
,
project:
[
:route
,
{
namespace: :route
}],
...
...
changelogs/unreleased/expose-merge-request-entity-for-pipelines.yml
0 → 100644
View file @
2eea8e1b
---
title
:
Expose merge request entity for pipelines
merge_request
:
25679
author
:
type
:
added
spec/serializers/merge_request_for_pipeline_entity_spec.rb
0 → 100644
View file @
2eea8e1b
require
'spec_helper'
describe
MergeRequestForPipelineEntity
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
EntityRequest
.
new
(
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
target_project:
project
,
source_project:
project
)
}
let
(
:presenter
)
{
MergeRequestPresenter
.
new
(
merge_request
,
current_user:
user
)
}
let
(
:entity
)
do
described_class
.
new
(
presenter
,
request:
request
)
end
before
do
project
.
add_developer
(
user
)
end
context
'as json'
do
subject
{
entity
.
as_json
}
it
'exposes needed attributes'
do
expect
(
subject
).
to
include
(
:iid
,
:path
,
:title
,
:source_branch
,
:source_branch_path
,
:target_branch
,
:target_branch_path
)
end
end
end
spec/serializers/pipeline_entity_spec.rb
View file @
2eea8e1b
require
'spec_helper'
describe
PipelineEntity
do
include
Gitlab
::
Routing
set
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
double
(
'request'
)
}
...
...
@@ -128,5 +130,48 @@ describe PipelineEntity do
.
to
eq
'CI/CD YAML configuration error!'
end
end
context
'when pipeline is detached merge request pipeline'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:with_merge_request_pipeline
)
}
let
(
:project
)
{
merge_request
.
target_project
}
let
(
:pipeline
)
{
merge_request
.
merge_request_pipelines
.
first
}
it
'makes detached flag true'
do
expect
(
subject
[
:flags
][
:detached
]).
to
be_truthy
end
context
'when user is a developer'
do
before
do
project
.
add_developer
(
user
)
end
it
'has merge request information'
do
expect
(
subject
[
:merge_request
][
:iid
]).
to
eq
(
merge_request
.
iid
)
expect
(
project_merge_request_path
(
project
,
merge_request
))
.
to
include
(
subject
[
:merge_request
][
:path
])
expect
(
subject
[
:merge_request
][
:title
]).
to
eq
(
merge_request
.
title
)
expect
(
subject
[
:merge_request
][
:source_branch
])
.
to
eq
(
merge_request
.
source_branch
)
expect
(
project_branch_path
(
project
,
merge_request
.
source_branch
))
.
to
include
(
subject
[
:merge_request
][
:source_branch_path
])
expect
(
subject
[
:merge_request
][
:target_branch
])
.
to
eq
(
merge_request
.
target_branch
)
expect
(
project_branch_path
(
project
,
merge_request
.
target_branch
))
.
to
include
(
subject
[
:merge_request
][
:target_branch_path
])
end
end
context
'when user is an external user'
do
it
'has no merge request information'
do
expect
(
subject
[
:merge_request
]).
to
be_nil
end
end
end
end
end
spec/serializers/pipeline_serializer_spec.rb
View file @
2eea8e1b
...
...
@@ -97,6 +97,44 @@ describe PipelineSerializer do
end
end
context
'when there are pipelines for merge requests'
do
let
(
:resource
)
{
Ci
::
Pipeline
.
all
}
let!
(
:merge_request_1
)
do
create
(
:merge_request
,
:with_merge_request_pipeline
,
target_project:
project
,
target_branch:
'master'
,
source_project:
project
,
source_branch:
'feature-1'
)
end
let!
(
:merge_request_2
)
do
create
(
:merge_request
,
:with_merge_request_pipeline
,
target_project:
project
,
target_branch:
'master'
,
source_project:
project
,
source_branch:
'feature-2'
)
end
before
do
project
.
add_developer
(
user
)
end
it
'includes merge requests information'
do
expect
(
subject
.
all?
{
|
entry
|
entry
[
:merge_request
].
present?
}).
to
be_truthy
end
it
'preloads related merge requests'
,
:postgresql
do
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
subject
}
expect
(
recorded
.
log
)
.
to
include
(
"SELECT
\"
merge_requests
\"
.* FROM
\"
merge_requests
\"
"
\
"WHERE
\"
merge_requests
\"
.
\"
id
\"
IN (
#{
merge_request_1
.
id
}
,
#{
merge_request_2
.
id
}
)"
)
end
end
describe
'number of queries when preloaded'
do
subject
{
serializer
.
represent
(
resource
,
preload:
true
)
}
let
(
:resource
)
{
Ci
::
Pipeline
.
all
}
...
...
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