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
Tatuya Kamada
gitlab-ce
Commits
c8b16068
Commit
c8b16068
authored
Dec 21, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for pipeline entity and improve factory
[ci skip]
parent
9f47d317
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
26 deletions
+184
-26
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+4
-0
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+30
-18
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+8
-8
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+4
-0
spec/serializers/pipeline_entity_spec.rb
spec/serializers/pipeline_entity_spec.rb
+138
-0
No files found.
app/models/ci/pipeline.rb
View file @
c8b16068
...
...
@@ -290,6 +290,10 @@ module Ci
end
end
def
has_yaml_errors?
yaml_errors
.
present?
end
def
environments
builds
.
where
.
not
(
environment:
nil
).
success
.
pluck
(
:environment
).
uniq
end
...
...
app/serializers/pipeline_entity.rb
View file @
c8b16068
...
...
@@ -28,12 +28,10 @@ class PipelineEntity < Grape::Entity
expose
:flags
do
expose
:latest?
,
as: :latest
expose
:triggered?
,
as: :triggered
expose
:yaml_errors?
,
as: :yaml_errors
do
|
pipeline
|
pipeline
.
yaml_errors
.
present?
end
expose
:stuck?
,
as: :stuck
expose
:has_yaml_errors?
,
as: :yaml_errors
expose
:can_retry?
,
as: :retryable
expose
:can_cancel?
,
as: :cancelable
end
expose
:ref
do
...
...
@@ -41,31 +39,45 @@ class PipelineEntity < Grape::Entity
pipeline
.
ref
end
expose
:
url
do
|
pipeline
|
namespace_project_tree_
url
(
expose
:
path
do
|
pipeline
|
namespace_project_tree_
path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
id:
pipeline
.
ref
)
end
expose
:tag?
expose
:tag?
,
as: :tag
expose
:branch?
,
as: :branch
end
expose
:commit
,
using:
CommitEntity
expose
:yaml_errors
,
if:
->
(
pipeline
,
_
)
{
pipeline
.
has_yaml_errors?
}
expose
:retry_url
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
retryable?
&&
expose
:retry_path
,
if:
proc
{
can_retry?
}
do
|
pipeline
|
retry_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
pipeline
.
project
,
pipeline
.
id
)
end
expose
:cancel_url
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
cancelable?
&&
expose
:cancel_path
,
if:
proc
{
can_cancel?
}
do
|
pipeline
|
cancel_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
pipeline
.
project
,
pipeline
.
id
)
end
expose
:created_at
,
:updated_at
private
alias_method
:pipeline
,
:object
def
can_retry?
pipeline
.
retryable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
end
def
can_cancel?
pipeline
.
cancelable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
end
end
app/serializers/pipeline_serializer.rb
View file @
c8b16068
...
...
@@ -3,14 +3,6 @@ class PipelineSerializer < BaseSerializer
include
API
::
Helpers
::
Pagination
Struct
.
new
(
'Pagination'
,
:request
,
:response
)
def
with_pagination
(
request
,
response
)
tap
{
@pagination
=
Struct
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginate?
defined?
(
@pagination
)
end
def
represent
(
resource
,
opts
=
{})
if
paginate?
super
(
paginate
(
resource
),
opts
)
...
...
@@ -19,6 +11,14 @@ class PipelineSerializer < BaseSerializer
end
end
def
paginate?
defined?
(
@pagination
)
end
def
with_pagination
(
request
,
response
)
tap
{
@pagination
=
Struct
::
Pagination
.
new
(
request
,
response
)
}
end
private
# Methods needed by `API::Helpers::Pagination`
...
...
spec/factories/ci/pipelines.rb
View file @
c8b16068
...
...
@@ -31,6 +31,10 @@ FactoryGirl.define do
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
end
# Populates pipeline with errors
#
pipeline
.
config_processor
if
evaluator
.
config
end
end
end
...
...
spec/serializers/pipeline_entity_spec.rb
0 → 100644
View file @
c8b16068
require
'spec_helper'
describe
PipelineEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
double
(
'request'
)
}
before
do
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
let
(
:entity
)
do
described_class
.
represent
(
pipeline
,
request:
request
)
end
describe
'#as_json'
do
subject
{
entity
.
as_json
}
context
'when pipeline is empty'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
it
'contains required fields'
do
expect
(
subject
).
to
include
:id
,
:user
,
:path
expect
(
subject
).
to
include
:ref
,
:commit
expect
(
subject
).
to
include
:updated_at
,
:created_at
end
it
'contains details'
do
expect
(
subject
).
to
include
:details
expect
(
subject
[
:details
])
.
to
include
:duration
,
:finished_at
expect
(
subject
[
:details
])
.
to
include
:stages
,
:artifacts
,
:manual_actions
expect
(
subject
[
:details
][
:status
]).
to
include
:icon
,
:text
,
:label
end
it
'contains flags'
do
expect
(
subject
).
to
include
:flags
expect
(
subject
[
:flags
])
.
to
include
:latest
,
:triggered
,
:stuck
,
:yaml_errors
,
:retryable
,
:cancelable
end
end
context
'when pipeline is retryable'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
status: :success
,
project:
project
)
end
before
do
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
)
end
context
'user has ability to retry pipeline'
do
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'retryable flag is true'
do
expect
(
subject
[
:flags
][
:retryable
]).
to
eq
true
end
it
'contains retry path'
do
expect
(
subject
[
:retry_path
]).
to
be_present
end
end
context
'user does not have ability to retry pipeline'
do
it
'retryable flag is false'
do
expect
(
subject
[
:flags
][
:retryable
]).
to
eq
false
end
it
'does not contain retry path'
do
expect
(
subject
).
not_to
have_key
(
:retry_path
)
end
end
end
context
'when pipeline is cancelable'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
status: :running
,
project:
project
)
end
before
do
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
end
context
'user has ability to cancel pipeline'
do
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'cancelable flag is true'
do
expect
(
subject
[
:flags
][
:cancelable
]).
to
eq
true
end
it
'contains cancel path'
do
expect
(
subject
[
:cancel_path
]).
to
be_present
end
end
context
'user does not have ability to cancel pipeline'
do
it
'cancelable flag is false'
do
expect
(
subject
[
:flags
][
:cancelable
]).
to
eq
false
end
it
'does not contain cancel path'
do
expect
(
subject
).
not_to
have_key
(
:cancel_path
)
end
end
end
context
'when pipeline has YAML errors'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
config:
{
rspec:
{
invalid: :value
}
})
end
it
'contains flag that indicates there are errors'
do
expect
(
subject
[
:flags
][
:yaml_errors
]).
to
be
true
end
it
'contains information about error'
do
expect
(
subject
[
:yaml_errors
]).
to
be_present
end
end
context
'when pipeline does not have YAML errors'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
it
'contains flag that indicates there are no errors'
do
expect
(
subject
[
:flags
][
:yaml_errors
]).
to
be
false
end
it
'does not contain field that normally holds an error'
do
expect
(
subject
).
not_to
have_key
(
:yaml_errors
)
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