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
8a9a62e3
Commit
8a9a62e3
authored
May 29, 2017
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate review
parent
68569584
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
106 additions
and
34 deletions
+106
-34
app/models/ci/build.rb
app/models/ci/build.rb
+3
-3
app/serializers/build_artifact_entity.rb
app/serializers/build_artifact_entity.rb
+28
-3
app/serializers/build_details_entity.rb
app/serializers/build_details_entity.rb
+13
-2
app/serializers/build_serializer.rb
app/serializers/build_serializer.rb
+1
-1
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+1
-1
app/serializers/pipeline_details_entity.rb
app/serializers/pipeline_details_entity.rb
+0
-14
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+17
-0
app/serializers/runner_entity.rb
app/serializers/runner_entity.rb
+4
-2
spec/controllers/projects/jobs_controller_spec.rb
spec/controllers/projects/jobs_controller_spec.rb
+1
-1
spec/serializers/build_artifact_entity_spec.rb
spec/serializers/build_artifact_entity_spec.rb
+12
-2
spec/serializers/build_details_entity_spec.rb
spec/serializers/build_details_entity_spec.rb
+23
-2
spec/serializers/merge_request_entity_spec.rb
spec/serializers/merge_request_entity_spec.rb
+1
-1
spec/serializers/runner_entity_spec.rb
spec/serializers/runner_entity_spec.rb
+2
-2
No files found.
app/models/ci/build.rb
View file @
8a9a62e3
...
@@ -205,13 +205,13 @@ module Ci
...
@@ -205,13 +205,13 @@ module Ci
def
merge_request
def
merge_request
return
@merge_request
if
defined?
(
@merge_request
)
return
@merge_request
if
defined?
(
@merge_request
)
@merge_request
||=
@merge_request
||=
begin
begin
merge_requests
=
MergeRequest
.
includes
(
:merge_request_diff
)
merge_requests
=
MergeRequest
.
includes
(
:merge_request_diff
)
.
where
(
source_branch:
ref
,
.
where
(
source_branch:
ref
,
source_project:
pipeline
.
project
)
source_project:
pipeline
.
project
)
.
reorder
(
iid: :
a
sc
)
.
reorder
(
iid: :
de
sc
)
merge_requests
.
find
do
|
merge_request
|
merge_requests
.
find
do
|
merge_request
|
merge_request
.
commits_sha
.
include?
(
pipeline
.
sha
)
merge_request
.
commits_sha
.
include?
(
pipeline
.
sha
)
...
@@ -372,7 +372,7 @@ module Ci
...
@@ -372,7 +372,7 @@ module Ci
end
end
def
has_expiring_artifacts?
def
has_expiring_artifacts?
artifacts_expire_at
.
present?
artifacts_expire_at
.
present?
&&
artifacts_expire_at
>
Time
.
now
end
end
def
keep_artifacts!
def
keep_artifacts!
...
...
app/serializers/build_artifact_entity.rb
View file @
8a9a62e3
class
BuildArtifactEntity
<
Grape
::
Entity
class
BuildArtifactEntity
<
Grape
::
Entity
include
RequestAwareEntity
include
RequestAwareEntity
expose
:name
do
|
build
|
expose
:name
do
|
job
|
build
.
name
job
.
name
end
end
expose
:path
do
|
build
|
expose
:artifacts_expired?
,
as: :expired
expose
:artifacts_expire_at
,
as: :expire_at
expose
:path
do
|
job
|
download_namespace_project_job_artifacts_path
(
download_namespace_project_job_artifacts_path
(
build
.
project
.
namespace
,
build
.
project
.
namespace
,
build
.
project
,
build
.
project
,
build
)
build
)
end
end
expose
:keep_path
,
if:
->
(
*
)
{
job
.
has_expiring_artifacts?
}
do
|
job
|
keep_namespace_project_job_artifacts_path
(
project
.
namespace
,
project
,
build
)
end
expose
:browse_path
do
|
job
|
browse_namespace_project_job_artifacts_path
(
project
.
namespace
,
project
,
job
)
end
private
alias_method
:job
,
:object
def
project
job
.
project
end
end
end
app/serializers/build_details_entity.rb
View file @
8a9a62e3
...
@@ -2,12 +2,23 @@ class BuildDetailsEntity < BuildEntity
...
@@ -2,12 +2,23 @@ class BuildDetailsEntity < BuildEntity
expose
:coverage
,
:erased_at
,
:duration
expose
:coverage
,
:erased_at
,
:duration
expose
:tag_list
,
as: :tags
expose
:tag_list
,
as: :tags
expose
:erased_by
,
if:
->
(
*
)
{
build
.
erased?
},
using:
UserEntity
expose
:erase_path
,
if:
->
(
*
)
{
build
.
erasable?
&&
can?
(
current_user
,
:update_build
,
project
)
}
do
|
build
|
erase_namespace_project_build_path
(
project
.
namespace
,
project
,
build
)
end
expose
:artifacts
,
using:
BuildArtifactEntity
expose
:artifacts
,
using:
BuildArtifactEntity
expose
:runner
,
using:
RunnerEntity
expose
:runner
,
using:
RunnerEntity
expose
:pipeline
,
using:
PipelineEntity
expose
:pipeline
,
using:
PipelineEntity
expose
:merge_request_path
,
if:
->
(
*
)
{
can?
(
current_user
,
:read_merge_request
,
project
)
}
do
|
build
|
expose
:merge_request
,
if:
->
(
*
)
{
can?
(
current_user
,
:read_merge_request
,
project
)
}
do
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
build
.
merge_request
)
expose
:iid
do
|
build
|
build
.
merge_request
.
iid
end
expose
:path
do
|
build
|
namespace_project_merge_request_path
(
project
.
namespace
,
project
,
build
.
merge_request
)
end
end
end
expose
:new_issue_path
,
if:
->
(
*
)
{
can?
(
request
.
current_user
,
:create_issue
,
project
)
}
do
|
build
|
expose
:new_issue_path
,
if:
->
(
*
)
{
can?
(
request
.
current_user
,
:create_issue
,
project
)
}
do
|
build
|
...
...
app/serializers/build_serializer.rb
View file @
8a9a62e3
class
BuildSerializer
<
BaseSerializer
class
BuildSerializer
<
BaseSerializer
entity
BuildEntity
entity
BuildEntity
def
represent_status
(
resource
,
opts
=
{},
entity_class
=
nil
)
def
represent_status
(
resource
)
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
=
represent
(
resource
,
{
only:
[
:status
]
})
data
.
fetch
(
:status
,
{})
data
.
fetch
(
:status
,
{})
end
end
...
...
app/serializers/merge_request_entity.rb
View file @
8a9a62e3
...
@@ -29,7 +29,7 @@ class MergeRequestEntity < IssuableEntity
...
@@ -29,7 +29,7 @@ class MergeRequestEntity < IssuableEntity
expose
:merge_commit_sha
expose
:merge_commit_sha
expose
:merge_commit_message
expose
:merge_commit_message
expose
:head_pipeline
,
with:
PipelineEntity
,
as: :pipeline
expose
:head_pipeline
,
with:
Pipeline
Details
Entity
,
as: :pipeline
# Booleans
# Booleans
expose
:work_in_progress?
,
as: :work_in_progress
expose
:work_in_progress?
,
as: :work_in_progress
...
...
app/serializers/pipeline_details_entity.rb
View file @
8a9a62e3
class
PipelineDetailsEntity
<
PipelineEntity
class
PipelineDetailsEntity
<
PipelineEntity
expose
:yaml_errors
,
if:
->
(
pipeline
,
_
)
{
pipeline
.
has_yaml_errors?
}
expose
:details
do
expose
:details
do
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
expose
:duration
expose
:finished_at
expose
:stages
,
using:
StageEntity
expose
:stages
,
using:
StageEntity
expose
:artifacts
,
using:
BuildArtifactEntity
expose
:artifacts
,
using:
BuildArtifactEntity
expose
:manual_actions
,
using:
BuildActionEntity
expose
:manual_actions
,
using:
BuildActionEntity
end
end
expose
:flags
do
expose
:latest?
,
as: :latest
expose
:triggered?
,
as: :triggered
expose
:stuck?
,
as: :stuck
expose
:has_yaml_errors?
,
as: :yaml_errors
expose
:can_retry?
,
as: :retryable
expose
:can_cancel?
,
as: :cancelable
end
end
end
app/serializers/pipeline_entity.rb
View file @
8a9a62e3
...
@@ -15,6 +15,21 @@ class PipelineEntity < Grape::Entity
...
@@ -15,6 +15,21 @@ class PipelineEntity < Grape::Entity
pipeline
)
pipeline
)
end
end
expose
:flags
do
expose
:latest?
,
as: :latest
expose
:triggered?
,
as: :triggered
expose
:stuck?
,
as: :stuck
expose
:has_yaml_errors?
,
as: :yaml_errors
expose
:can_retry?
,
as: :retryable
expose
:can_cancel?
,
as: :cancelable
end
expose
:details
do
expose
:detailed_status
,
as: :status
,
with:
StatusEntity
expose
:duration
expose
:finished_at
end
expose
:ref
do
expose
:ref
do
expose
:name
do
|
pipeline
|
expose
:name
do
|
pipeline
|
pipeline
.
ref
pipeline
.
ref
...
@@ -44,6 +59,8 @@ class PipelineEntity < Grape::Entity
...
@@ -44,6 +59,8 @@ class PipelineEntity < Grape::Entity
pipeline
.
id
)
pipeline
.
id
)
end
end
expose
:yaml_errors
,
if:
->
(
pipeline
,
_
)
{
pipeline
.
has_yaml_errors?
}
private
private
alias_method
:pipeline
,
:object
alias_method
:pipeline
,
:object
...
...
app/serializers/runner_entity.rb
View file @
8a9a62e3
...
@@ -3,13 +3,15 @@ class RunnerEntity < Grape::Entity
...
@@ -3,13 +3,15 @@ class RunnerEntity < Grape::Entity
expose
:id
,
:description
expose
:id
,
:description
expose
:edit_
runner_
path
,
expose
:edit_path
,
if:
->
(
*
)
{
can?
(
request
.
current_user
,
:admin_build
,
project
)
}
do
|
runner
|
if:
->
(
*
)
{
can?
(
request
.
current_user
,
:admin_build
,
project
)
&&
runner
.
specific?
}
do
|
runner
|
edit_namespace_project_runner_path
(
project
.
namespace
,
project
,
runner
)
edit_namespace_project_runner_path
(
project
.
namespace
,
project
,
runner
)
end
end
private
private
alias_method
:runner
,
:object
def
project
def
project
request
.
project
request
.
project
end
end
...
...
spec/controllers/projects/jobs_controller_spec.rb
View file @
8a9a62e3
...
@@ -142,7 +142,7 @@ describe Projects::JobsController do
...
@@ -142,7 +142,7 @@ describe Projects::JobsController do
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
json_response
[
'new_issue_path'
]).
to
end_with
(
'/issues/new'
)
expect
(
json_response
[
'new_issue_path'
]).
to
end_with
(
'/issues/new'
)
expect
(
json_response
[
'raw_path'
]).
to
match
(
/builds\/\d+\/raw\z/
)
expect
(
json_response
[
'raw_path'
]).
to
match
(
/builds\/\d+\/raw\z/
)
expect
(
json_response
[
'merge_request_path'
]
).
to
match
(
/merge_requests\/\d+\z/
)
expect
(
json_response
.
dig
(
'merge_request'
,
'path'
)
).
to
match
(
/merge_requests\/\d+\z/
)
end
end
end
end
...
...
spec/serializers/build_artifact_entity_spec.rb
View file @
8a9a62e3
require
'spec_helper'
require
'spec_helper'
describe
BuildArtifactEntity
do
describe
BuildArtifactEntity
do
let
(
:job
)
{
create
(
:ci_build
,
name:
'test:job'
)
}
let
(
:job
)
{
create
(
:ci_build
,
name:
'test:job'
,
artifacts_expire_at:
1
.
hour
.
from_now
)
}
let
(
:entity
)
do
let
(
:entity
)
do
described_class
.
new
(
job
,
request:
double
)
described_class
.
new
(
job
,
request:
double
)
...
@@ -14,9 +14,19 @@ describe BuildArtifactEntity do
...
@@ -14,9 +14,19 @@ describe BuildArtifactEntity do
expect
(
subject
[
:name
]).
to
eq
'test:job'
expect
(
subject
[
:name
]).
to
eq
'test:job'
end
end
it
'contains path to the artifacts'
do
it
'exposes information about expiration of artifacts'
do
expect
(
subject
).
to
include
(
:expired
,
:expire_at
)
end
it
'contains paths to the artifacts'
do
expect
(
subject
[
:path
])
expect
(
subject
[
:path
])
.
to
include
"jobs/
#{
job
.
id
}
/artifacts/download"
.
to
include
"jobs/
#{
job
.
id
}
/artifacts/download"
expect
(
subject
[
:keep_path
])
.
to
include
"jobs/
#{
build
.
id
}
/artifacts/keep"
expect
(
subject
[
:browse_path
])
.
to
include
"jobs/
#{
build
.
id
}
/artifacts/browse"
end
end
end
end
end
end
spec/serializers/build_details_entity_spec.rb
View file @
8a9a62e3
require
'spec_helper'
require
'spec_helper'
describe
BuildDetailsEntity
do
describe
BuildDetailsEntity
do
set
(
:user
)
{
create
(
:admin
)
}
it
'inherits from BuildEntity'
do
it
'inherits from BuildEntity'
do
expect
(
described_class
).
to
be
<
BuildEntity
expect
(
described_class
).
to
be
<
BuildEntity
end
end
...
@@ -17,7 +19,6 @@ describe BuildDetailsEntity do
...
@@ -17,7 +19,6 @@ describe BuildDetailsEntity do
end
end
context
'when the user has access to issues and merge requests'
do
context
'when the user has access to issues and merge requests'
do
let
(
:user
)
{
create
(
:admin
)
}
let!
(
:merge_request
)
do
let!
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
build
.
ref
)
create
(
:merge_request
,
source_project:
project
,
source_branch:
build
.
ref
)
end
end
...
@@ -29,7 +30,27 @@ describe BuildDetailsEntity do
...
@@ -29,7 +30,27 @@ describe BuildDetailsEntity do
it
'contains the needed key value pairs'
do
it
'contains the needed key value pairs'
do
expect
(
subject
).
to
include
(
:coverage
,
:erased_at
,
:duration
)
expect
(
subject
).
to
include
(
:coverage
,
:erased_at
,
:duration
)
expect
(
subject
).
to
include
(
:artifacts
,
:runner
,
:pipeline
)
expect
(
subject
).
to
include
(
:artifacts
,
:runner
,
:pipeline
)
expect
(
subject
).
to
include
(
:raw_path
,
:merge_request_path
,
:new_issue_path
)
expect
(
subject
).
to
include
(
:raw_path
,
:merge_request
,
:new_issue_path
)
end
it
'exposes details of the merge request'
do
expect
(
subject
[
:merge_request
]).
to
include
(
:iid
,
:path
)
end
context
'when the build has been erased'
do
let!
(
:build
)
{
create
(
:ci_build
,
:erasable
,
project:
project
)
}
it
'exposes the user whom erased the build'
do
expect
(
subject
).
to
include
(
:erase_path
)
end
end
context
'when the build has been erased'
do
let!
(
:build
)
{
create
(
:ci_build
,
erased_at:
Time
.
now
,
project:
project
,
erased_by:
user
)
}
it
'exposes the user whom erased the build'
do
expect
(
subject
).
to
include
(
:erased_by
)
end
end
end
end
end
...
...
spec/serializers/merge_request_entity_spec.rb
View file @
8a9a62e3
...
@@ -26,7 +26,7 @@ describe MergeRequestEntity do
...
@@ -26,7 +26,7 @@ describe MergeRequestEntity do
pipeline
=
build_stubbed
(
:ci_pipeline
)
pipeline
=
build_stubbed
(
:ci_pipeline
)
allow
(
resource
).
to
receive
(
:head_pipeline
).
and_return
(
pipeline
)
allow
(
resource
).
to
receive
(
:head_pipeline
).
and_return
(
pipeline
)
pipeline_payload
=
PipelineEntity
pipeline_payload
=
Pipeline
Details
Entity
.
represent
(
pipeline
,
request:
req
)
.
represent
(
pipeline
,
request:
req
)
.
as_json
.
as_json
...
...
spec/serializers/runner_entity_spec.rb
View file @
8a9a62e3
require
'spec_helper'
require
'spec_helper'
describe
RunnerEntity
do
describe
RunnerEntity
do
let
(
:runner
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:specific
)
}
let
(
:entity
)
{
described_class
.
new
(
runner
,
request:
request
,
current_user:
user
)
}
let
(
:entity
)
{
described_class
.
new
(
runner
,
request:
request
,
current_user:
user
)
}
let
(
:request
)
{
double
(
'request'
)
}
let
(
:request
)
{
double
(
'request'
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
...
@@ -17,7 +17,7 @@ describe RunnerEntity do
...
@@ -17,7 +17,7 @@ describe RunnerEntity do
it
'contains required fields'
do
it
'contains required fields'
do
expect
(
subject
).
to
include
(
:id
,
:description
)
expect
(
subject
).
to
include
(
:id
,
:description
)
expect
(
subject
).
to
include
(
:edit_
runner_
path
)
expect
(
subject
).
to
include
(
:edit_path
)
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