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
3afd7d89
Commit
3afd7d89
authored
Dec 02, 2021
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename BuildSerializer to JobSerliazer
* Rename the object in JobEntity to BuildEntity
parent
24946c7e
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
126 additions
and
120 deletions
+126
-120
app/controllers/projects/jobs_controller.rb
app/controllers/projects/jobs_controller.rb
+2
-2
app/serializers/build_details_entity.rb
app/serializers/build_details_entity.rb
+3
-1
app/serializers/build_serializer.rb
app/serializers/build_serializer.rb
+0
-10
app/serializers/ci/job_entity.rb
app/serializers/ci/job_entity.rb
+96
-0
app/serializers/ci/job_serializer.rb
app/serializers/ci/job_serializer.rb
+12
-0
app/serializers/ci/pipeline_entity.rb
app/serializers/ci/pipeline_entity.rb
+1
-1
app/serializers/deployment_entity.rb
app/serializers/deployment_entity.rb
+4
-4
app/serializers/job_entity.rb
app/serializers/job_entity.rb
+0
-94
app/serializers/job_group_entity.rb
app/serializers/job_group_entity.rb
+1
-1
app/serializers/stage_entity.rb
app/serializers/stage_entity.rb
+2
-2
ee/spec/serializers/ee/ci/job_entity_spec.rb
ee/spec/serializers/ee/ci/job_entity_spec.rb
+1
-1
spec/serializers/build_details_entity_spec.rb
spec/serializers/build_details_entity_spec.rb
+2
-2
spec/serializers/ci/job_entity_spec.rb
spec/serializers/ci/job_entity_spec.rb
+1
-1
spec/serializers/ci/job_serializer_spec.rb
spec/serializers/ci/job_serializer_spec.rb
+1
-1
No files found.
app/controllers/projects/jobs_controller.rb
View file @
3afd7d89
...
...
@@ -42,7 +42,7 @@ class Projects::JobsController < Projects::ApplicationController
format
.
json
do
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
10_000
)
render
json:
Build
Serializer
render
json:
Ci
::
Job
Serializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
represent
(
@build
.
present
(
current_user:
current_user
),
{},
BuildDetailsEntity
)
end
...
...
@@ -118,7 +118,7 @@ class Projects::JobsController < Projects::ApplicationController
end
def
status
render
json:
Build
Serializer
render
json:
Ci
::
Job
Serializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
represent_status
(
@build
.
present
(
current_user:
current_user
))
end
...
...
app/serializers/build_details_entity.rb
View file @
3afd7d89
# frozen_string_literal: true
class
BuildDetailsEntity
<
JobEntity
class
BuildDetailsEntity
<
Ci
::
JobEntity
expose
:coverage
,
:erased_at
,
:duration
expose
:tag_list
,
as: :tags
expose
:has_trace?
,
as: :has_trace
...
...
@@ -109,6 +109,8 @@ class BuildDetailsEntity < JobEntity
private
alias_method
:build
,
:object
def
build_failed_issue_options
{
title:
"Job Failed #
#{
build
.
id
}
"
,
description:
"Job [#
#{
build
.
id
}
](
#{
project_job_url
(
project
,
build
)
}
) failed for
#{
build
.
sha
}
:
\n
"
}
...
...
app/serializers/build_serializer.rb
deleted
100644 → 0
View file @
24946c7e
# frozen_string_literal: true
class
BuildSerializer
<
BaseSerializer
entity
JobEntity
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
.
fetch
(
:status
,
{})
end
end
app/serializers/ci/job_entity.rb
0 → 100644
View file @
3afd7d89
# frozen_string_literal: true
module
Ci
class
JobEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:name
expose
:started?
,
as: :started
expose
:complete?
,
as: :complete
expose
:archived?
,
as: :archived
# bridge jobs don't have build details pages
expose
:build_path
,
if:
->
(
job
)
{
!
job
.
is_a?
(
Ci
::
Bridge
)
}
do
|
job
|
job_path
(
job
)
end
expose
:retry_path
,
if:
->
(
*
)
{
retryable?
}
do
|
job
|
path_to
(
:retry_namespace_project_job
,
job
)
end
expose
:cancel_path
,
if:
->
(
*
)
{
cancelable?
}
do
|
job
|
path_to
(
:cancel_namespace_project_job
,
job
,
{
continue:
{
to:
job_path
(
job
)
}
}
)
end
expose
:play_path
,
if:
->
(
*
)
{
playable?
}
do
|
job
|
path_to
(
:play_namespace_project_job
,
job
)
end
expose
:unschedule_path
,
if:
->
(
*
)
{
scheduled?
}
do
|
job
|
path_to
(
:unschedule_namespace_project_job
,
job
)
end
expose
:playable?
,
as: :playable
expose
:scheduled?
,
as: :scheduled
expose
:scheduled_at
,
if:
->
(
*
)
{
scheduled?
}
expose
:created_at
expose
:updated_at
expose
:detailed_status
,
as: :status
,
with:
DetailedStatusEntity
expose
:callout_message
,
if:
->
(
*
)
{
failed?
&&
!
job
.
script_failure?
}
expose
:recoverable
,
if:
->
(
*
)
{
failed?
}
private
alias_method
:job
,
:object
def
cancelable?
job
.
cancelable?
&&
can?
(
request
.
current_user
,
:update_build
,
job
)
end
def
retryable?
job
.
retryable?
&&
can?
(
request
.
current_user
,
:update_build
,
job
)
end
def
playable?
job
.
playable?
&&
can?
(
request
.
current_user
,
:update_build
,
job
)
end
def
scheduled?
job
.
scheduled?
end
def
detailed_status
job
.
detailed_status
(
request
.
current_user
)
end
def
path_to
(
route
,
job
,
params
=
{})
send
(
"
#{
route
}
_path"
,
job
.
project
.
namespace
,
job
.
project
,
job
,
params
)
# rubocop:disable GitlabSecurity/PublicSend
end
def
job_path
(
job
)
job
.
target_url
||
path_to
(
:namespace_project_job
,
job
)
end
def
failed?
job
.
failed?
end
def
callout_message
job_presenter
.
callout_failure_message
end
def
recoverable
job_presenter
.
recoverable?
end
def
job_presenter
@job_presenter
||=
job
.
present
end
end
end
app/serializers/ci/job_serializer.rb
0 → 100644
View file @
3afd7d89
# frozen_string_literal: true
module
Ci
class
JobSerializer
<
BaseSerializer
entity
Ci
::
JobEntity
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
.
fetch
(
:status
,
{})
end
end
end
app/serializers/ci/pipeline_entity.rb
View file @
3afd7d89
...
...
@@ -82,7 +82,7 @@ class Ci::PipelineEntity < Grape::Entity
project_pipeline_path
(
pipeline
.
project
,
pipeline
)
end
expose
:failed_builds
,
if:
->
(
*
)
{
can_retry?
},
using:
JobEntity
do
|
pipeline
|
expose
:failed_builds
,
if:
->
(
*
)
{
can_retry?
},
using:
Ci
::
JobEntity
do
|
pipeline
|
pipeline
.
failed_builds
.
each
do
|
build
|
build
.
project
=
pipeline
.
project
end
...
...
app/serializers/deployment_entity.rb
View file @
3afd7d89
...
...
@@ -27,7 +27,7 @@ class DeploymentEntity < Grape::Entity
expose
:deployable
,
if:
->
(
deployment
)
{
deployment
.
deployable
.
present?
}
do
|
deployment
,
opts
|
deployment
.
deployable
.
yield_self
do
|
deployable
|
if
include_details?
JobEntity
.
represent
(
deployable
,
opts
)
Ci
::
JobEntity
.
represent
(
deployable
,
opts
)
elsif
can_read_deployables?
{
name:
deployable
.
name
,
build_path:
project_job_path
(
deployable
.
project
,
deployable
)
}
...
...
@@ -36,10 +36,10 @@ class DeploymentEntity < Grape::Entity
end
expose
:commit
,
using:
CommitEntity
,
if:
->
(
*
)
{
include_details?
}
expose
:manual_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:scheduled_actions
,
using:
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:manual_actions
,
using:
Ci
::
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:scheduled_actions
,
using:
Ci
::
JobEntity
,
if:
->
(
*
)
{
include_details?
&&
can_create_deployment?
}
expose
:playable_build
,
if:
->
(
deployment
)
{
include_details?
&&
can_create_deployment?
&&
deployment
.
playable_build
}
do
|
deployment
,
options
|
JobEntity
.
represent
(
deployment
.
playable_build
,
options
.
merge
(
only:
[
:play_path
,
:retry_path
]))
Ci
::
JobEntity
.
represent
(
deployment
.
playable_build
,
options
.
merge
(
only:
[
:play_path
,
:retry_path
]))
end
expose
:cluster
do
|
deployment
,
options
|
...
...
app/serializers/job_entity.rb
deleted
100644 → 0
View file @
24946c7e
# frozen_string_literal: true
class
JobEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
expose
:name
expose
:started?
,
as: :started
expose
:complete?
,
as: :complete
expose
:archived?
,
as: :archived
# bridge jobs don't have build detail pages
expose
:build_path
,
if:
->
(
build
)
{
!
build
.
is_a?
(
Ci
::
Bridge
)
}
do
|
build
|
build_path
(
build
)
end
expose
:retry_path
,
if:
->
(
*
)
{
retryable?
}
do
|
build
|
path_to
(
:retry_namespace_project_job
,
build
)
end
expose
:cancel_path
,
if:
->
(
*
)
{
cancelable?
}
do
|
build
|
path_to
(
:cancel_namespace_project_job
,
build
,
{
continue:
{
to:
build_path
(
build
)
}
}
)
end
expose
:play_path
,
if:
->
(
*
)
{
playable?
}
do
|
build
|
path_to
(
:play_namespace_project_job
,
build
)
end
expose
:unschedule_path
,
if:
->
(
*
)
{
scheduled?
}
do
|
build
|
path_to
(
:unschedule_namespace_project_job
,
build
)
end
expose
:playable?
,
as: :playable
expose
:scheduled?
,
as: :scheduled
expose
:scheduled_at
,
if:
->
(
*
)
{
scheduled?
}
expose
:created_at
expose
:updated_at
expose
:detailed_status
,
as: :status
,
with:
DetailedStatusEntity
expose
:callout_message
,
if:
->
(
*
)
{
failed?
&&
!
build
.
script_failure?
}
expose
:recoverable
,
if:
->
(
*
)
{
failed?
}
private
alias_method
:build
,
:object
def
cancelable?
build
.
cancelable?
&&
can?
(
request
.
current_user
,
:update_build
,
build
)
end
def
retryable?
build
.
retryable?
&&
can?
(
request
.
current_user
,
:update_build
,
build
)
end
def
playable?
build
.
playable?
&&
can?
(
request
.
current_user
,
:update_build
,
build
)
end
def
scheduled?
build
.
scheduled?
end
def
detailed_status
build
.
detailed_status
(
request
.
current_user
)
end
def
path_to
(
route
,
build
,
params
=
{})
send
(
"
#{
route
}
_path"
,
build
.
project
.
namespace
,
build
.
project
,
build
,
params
)
# rubocop:disable GitlabSecurity/PublicSend
end
def
build_path
(
build
)
build
.
target_url
||
path_to
(
:namespace_project_job
,
build
)
end
def
failed?
build
.
failed?
end
def
callout_message
build_presenter
.
callout_failure_message
end
def
recoverable
build_presenter
.
recoverable?
end
def
build_presenter
@build_presenter
||=
build
.
present
end
end
app/serializers/job_group_entity.rb
View file @
3afd7d89
...
...
@@ -6,7 +6,7 @@ class JobGroupEntity < Grape::Entity
expose
:name
expose
:size
expose
:detailed_status
,
as: :status
,
with:
DetailedStatusEntity
expose
:jobs
,
with:
JobEntity
expose
:jobs
,
with:
Ci
::
JobEntity
private
...
...
app/serializers/stage_entity.rb
View file @
3afd7d89
...
...
@@ -15,13 +15,13 @@ class StageEntity < Grape::Entity
expose
:latest_statuses
,
if:
->
(
_
,
opts
)
{
opts
[
:details
]
},
with:
JobEntity
do
|
stage
|
with:
Ci
::
JobEntity
do
|
stage
|
latest_statuses
end
expose
:retried
,
if:
->
(
_
,
opts
)
{
opts
[
:retried
]
},
with:
JobEntity
do
|
stage
|
with:
Ci
::
JobEntity
do
|
stage
|
retried_statuses
end
...
...
ee/spec/serializers/ee/job_entity_spec.rb
→
ee/spec/serializers/ee/
ci/
job_entity_spec.rb
View file @
3afd7d89
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
JobEntity
do
RSpec
.
describe
Ci
::
JobEntity
do
using
RSpec
::
Parameterized
::
TableSyntax
let_it_be
(
:group
)
{
create
(
:group
)
}
...
...
spec/serializers/build_details_entity_spec.rb
View file @
3afd7d89
...
...
@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec
.
describe
BuildDetailsEntity
do
include
ProjectForksHelper
it
'inherits from JobEntity'
do
expect
(
described_class
).
to
be
<
JobEntity
it
'inherits from
Ci::
JobEntity'
do
expect
(
described_class
).
to
be
<
Ci
::
JobEntity
end
describe
'#as_json'
do
...
...
spec/serializers/job_entity_spec.rb
→
spec/serializers/
ci/
job_entity_spec.rb
View file @
3afd7d89
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
JobEntity
do
RSpec
.
describe
Ci
::
JobEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:job
)
{
create
(
:ci_build
)
}
let
(
:project
)
{
job
.
project
}
...
...
spec/serializers/
build
_serializer_spec.rb
→
spec/serializers/
ci/job
_serializer_spec.rb
View file @
3afd7d89
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Build
Serializer
do
RSpec
.
describe
Ci
::
Job
Serializer
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:serializer
)
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