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
573921cb
Commit
573921cb
authored
Nov 03, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement entities needed for environments folders
parent
f1e9c97d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
93 additions
and
27 deletions
+93
-27
app/serializers/base_serializer.rb
app/serializers/base_serializer.rb
+6
-6
app/serializers/build_entity.rb
app/serializers/build_entity.rb
+20
-0
app/serializers/commit_entity.rb
app/serializers/commit_entity.rb
+10
-0
app/serializers/deployment_entity.rb
app/serializers/deployment_entity.rb
+27
-0
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+9
-13
app/serializers/request_aware_entity.rb
app/serializers/request_aware_entity.rb
+7
-3
spec/factories/deployments.rb
spec/factories/deployments.rb
+2
-2
spec/serializers/environment_serializer_spec.rb
spec/serializers/environment_serializer_spec.rb
+12
-3
No files found.
app/serializers/base_serializer.rb
View file @
573921cb
class
BaseSerializer
def
initialize
(
request
=
{})
@request
=
EntityRequest
.
new
(
request
)
def
initialize
(
parameters
=
{})
@entity
=
self
.
class
.
entity_class
@request
=
EntityRequest
.
new
(
parameters
)
@opts
=
{
request:
@request
}
end
def
set
(
opt
s
)
@request
.
merge!
(
opt
s
)
def
set
(
parameter
s
)
@request
.
merge!
(
parameter
s
)
self
end
def
represent
(
resource
,
opts
=
{})
self
.
class
.
entity_class
.
represent
(
resource
,
@opts
.
reverse_merge
(
opts
))
@entity
.
represent
(
resource
,
@opts
.
reverse_merge
(
opts
))
end
def
self
.
entity
(
entity_class
)
...
...
app/serializers/build_entity.rb
0 → 100644
View file @
573921cb
class
BuildEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:name
expose
:build_url
do
|
build
|
@urls
.
namespace_project_build_url
(
build
.
project
.
namespace
,
build
.
project
,
build
)
end
expose
:retry_url
do
|
build
|
@urls
.
retry_namespace_project_build_url
(
build
.
project
.
namespace
,
build
.
project
,
build
)
end
end
app/serializers/commit_entity.rb
0 → 100644
View file @
573921cb
class
CommitEntity
<
API
::
Entities
::
RepoCommit
include
RequestAwareEntity
expose
:commit_url
do
|
commit
|
@urls
.
namespace_project_tree_url
(
@request
.
project
.
namespace
,
@request
.
project
,
id:
commit
.
id
)
end
end
app/serializers/deployment_entity.rb
0 → 100644
View file @
573921cb
class
DeploymentEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:iid
expose
:sha
expose
:ref
do
expose
:name
do
|
deployment
|
deployment
.
ref
end
expose
:ref_url
do
|
deployment
|
@urls
.
namespace_project_tree_url
(
deployment
.
project
.
namespace
,
deployment
.
project
,
id:
deployment
.
ref
)
end
end
expose
:tag
expose
:last?
expose
:user
,
using:
API
::
Entities
::
UserBasic
expose
:commit
,
using:
CommitEntity
expose
:deployable
,
using:
BuildEntity
expose
:manual_actions
end
app/serializers/environment_entity.rb
View file @
573921cb
class
EnvironmentEntity
<
Grape
::
Entity
include
RequestAwareEntity
include
Gitlab
::
Routing
.
url_helpers
expose
:id
expose
:name
expose
:state
expose
:external_url
expose
:environment_type
expose
:project
,
with:
ProjectEntity
expose
:last_deployment
,
as: :deployment
,
using:
API
::
Entities
::
Deployment
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stoppable?
expose
:
gitlab_path
do
|
environment
|
namespace_project_environment_path
(
expose
:
environmenturl
do
|
environment
|
@urls
.
namespace_project_environment_url
(
environment
.
project
.
namespace
,
environment
.
project
,
environment
)
environment
)
end
expose
:can_read?
def
can_read?
Ability
.
allowed?
(
request
.
user
,
:read_environment
,
@object
)
end
expose
:created_at
,
:updated_at
end
app/serializers/request_aware_entity.rb
View file @
573921cb
module
RequestAwareEntity
def
request
options
[
:request
]
||
raise
(
StandardError
,
'Request not set!!'
)
attr_reader
:request
def
initialize
(
object
,
options
=
{})
super
(
object
,
options
)
@request
=
options
.
fetch
(
:request
)
@urls
=
Gitlab
::
Routing
.
url_helpers
end
end
spec/factories/deployments.rb
View file @
573921cb
FactoryGirl
.
define
do
factory
:deployment
,
class:
Deployment
do
sha
'
97de212e80737a608d939f648d959671fb0a0142
'
sha
'
b83d6e391c22777fca1ed3012fce84f633d7fed0
'
ref
'master'
tag
false
project
nil
project
environment
factory: :environment
...
...
spec/serializers/environment_serializer_spec.rb
View file @
573921cb
...
...
@@ -2,17 +2,25 @@ require 'spec_helper'
describe
EnvironmentSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
path:
'some path'
,
user:
user
)
described_class
.
new
(
user:
user
,
project:
project
)
.
represent
(
resource
)
end
let
(
:user
)
{
create
(
:user
)
}
context
'when there is a single object provided'
do
let
(
:resource
)
{
create
(
:environment
)
}
let
(
:deployment
)
do
create
(
:deployment
,
deployable:
deployable
,
user:
user
)
end
let
(
:deployable
)
{
create
(
:ci_build
)
}
let
(
:project
)
{
deployment
.
project
}
let
(
:resource
)
{
deployment
.
environment
}
it
'shows json'
do
p
uts
serializer
.
as_json
p
p
serializer
.
as_json
end
it
'it generates payload for single object'
do
...
...
@@ -21,6 +29,7 @@ describe EnvironmentSerializer do
end
context
'when there is a collection of objects provided'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:resource
)
{
create_list
(
:environment
,
2
)
}
it
'shows json'
do
...
...
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