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
Boxiang Sun
gitlab-ce
Commits
3bc5f711
Commit
3bc5f711
authored
Aug 20, 2018
by
Steve Azzopardi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add deployment information in job API
closes
https://gitlab.com/gitlab-org/gitlab-ce/issues/50460
parent
c7d1eef6
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
245 additions
and
47 deletions
+245
-47
app/models/ci/build.rb
app/models/ci/build.rb
+23
-0
app/serializers/build_details_entity.rb
app/serializers/build_details_entity.rb
+14
-0
changelogs/unreleased/21307-send-deployment-information-in-job-api.yml
...released/21307-send-deployment-information-in-job-api.yml
+5
-0
spec/controllers/projects/jobs_controller_spec.rb
spec/controllers/projects/jobs_controller_spec.rb
+24
-1
spec/fixtures/api/schemas/deployment.json
spec/fixtures/api/schemas/deployment.json
+28
-42
spec/fixtures/api/schemas/entities/commit.json
spec/fixtures/api/schemas/entities/commit.json
+27
-0
spec/fixtures/api/schemas/entities/user.json
spec/fixtures/api/schemas/entities/user.json
+9
-3
spec/fixtures/api/schemas/environment.json
spec/fixtures/api/schemas/environment.json
+38
-0
spec/fixtures/api/schemas/job/deployment_status.json
spec/fixtures/api/schemas/job/deployment_status.json
+27
-0
spec/fixtures/api/schemas/job/job_details.json
spec/fixtures/api/schemas/job/job_details.json
+2
-1
spec/fixtures/api/schemas/types/nullable_string.json
spec/fixtures/api/schemas/types/nullable_string.json
+6
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+42
-0
No files found.
app/models/ci/build.rb
View file @
3bc5f711
...
@@ -654,8 +654,31 @@ module Ci
...
@@ -654,8 +654,31 @@ module Ci
end
end
end
end
# Virtual deployment status depending on the environment status.
def
deployment_status
return
nil
unless
starts_environment?
if
success?
return
successful_deployment_status
elsif
complete?
&&
!
success?
return
:failed
end
:creating
end
private
private
def
successful_deployment_status
if
success?
&&
last_deployment
&
.
last?
return
:last
elsif
success?
&&
last_deployment
.
present?
return
:out_of_date
end
:creating
end
def
each_test_report
def
each_test_report
Ci
::
JobArtifact
::
TEST_REPORT_FILE_TYPES
.
each
do
|
file_type
|
Ci
::
JobArtifact
::
TEST_REPORT_FILE_TYPES
.
each
do
|
file_type
|
public_send
(
"job_artifacts_
#{
file_type
}
"
).
each_blob
do
|
blob
|
# rubocop:disable GitlabSecurity/PublicSend
public_send
(
"job_artifacts_
#{
file_type
}
"
).
each_blob
do
|
blob
|
# rubocop:disable GitlabSecurity/PublicSend
...
...
app/serializers/build_details_entity.rb
View file @
3bc5f711
# frozen_string_literal: true
# frozen_string_literal: true
class
BuildDetailsEntity
<
JobEntity
class
BuildDetailsEntity
<
JobEntity
include
EnvironmentHelper
include
RequestAwareEntity
include
CiStatusHelper
expose
:coverage
,
:erased_at
,
:duration
expose
:coverage
,
:erased_at
,
:duration
expose
:tag_list
,
as: :tags
expose
:tag_list
,
as: :tags
expose
:user
,
using:
UserEntity
expose
:user
,
using:
UserEntity
expose
:runner
,
using:
RunnerEntity
expose
:runner
,
using:
RunnerEntity
expose
:pipeline
,
using:
PipelineEntity
expose
:pipeline
,
using:
PipelineEntity
expose
:deployment_status
,
if:
->
(
*
)
{
build
.
has_environment?
}
do
expose
:deployment_status
,
as: :status
expose
:icon
do
|
build
|
ci_label_for_status
(
build
.
status
)
end
expose
:persisted_environment
,
as: :environment
,
with:
EnvironmentEntity
end
expose
:metadata
,
using:
BuildMetadataEntity
expose
:metadata
,
using:
BuildMetadataEntity
expose
:artifact
,
if:
->
(
*
)
{
can?
(
current_user
,
:read_build
,
build
)
}
do
expose
:artifact
,
if:
->
(
*
)
{
can?
(
current_user
,
:read_build
,
build
)
}
do
...
...
changelogs/unreleased/21307-send-deployment-information-in-job-api.yml
0 → 100644
View file @
3bc5f711
---
title
:
Send deployment information in job API
merge_request
:
21307
author
:
type
:
other
spec/controllers/projects/jobs_controller_spec.rb
View file @
3bc5f711
...
@@ -206,6 +206,29 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
...
@@ -206,6 +206,29 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
expect
(
json_response
[
'status'
][
'illustration'
]).
to
have_key
(
'title'
)
expect
(
json_response
[
'status'
][
'illustration'
]).
to
have_key
(
'title'
)
end
end
end
end
context
'with no deployment'
do
let
(
:job
)
{
create
(
:ci_build
,
:success
,
pipeline:
pipeline
)
}
it
'does not exposes the deployment information'
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'deployment_status'
]).
to
be_nil
end
end
context
'with deployment'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'staging'
,
state: :available
)
}
let
(
:job
)
{
create
(
:ci_build
,
:success
,
environment:
environment
.
name
,
pipeline:
pipeline
)
}
it
'exposes the deployment information'
do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
match_schema
(
'job/job_details'
)
expect
(
json_response
[
'deployment_status'
][
"status"
]).
to
eq
'creating'
expect
(
json_response
[
'deployment_status'
][
"icon"
]).
to
eq
'passed'
expect
(
json_response
[
'deployment_status'
][
"environment"
]).
not_to
be_nil
end
end
end
end
context
'when requesting JSON job is triggered'
do
context
'when requesting JSON job is triggered'
do
...
...
spec/fixtures/api/schemas/deployment.json
View file @
3bc5f711
{
{
"additionalProperties"
:
false
,
"type"
:
"object"
,
"properties"
:
{
"created_at"
:
{
"type"
:
"string"
},
"id"
:
{
"type"
:
"integer"
},
"iid"
:
{
"type"
:
"integer"
},
"last?"
:
{
"type"
:
"boolean"
},
"ref"
:
{
"additionalProperties"
:
false
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
}
},
"required"
:
[
"name"
],
"type"
:
"object"
},
"sha"
:
{
"type"
:
"string"
},
"tag"
:
{
"type"
:
"boolean"
}
},
"required"
:
[
"required"
:
[
"sha"
,
"sha"
,
"created_at"
,
"created_at"
,
...
@@ -41,5 +9,23 @@
...
@@ -41,5 +9,23 @@
"ref"
,
"ref"
,
"id"
"id"
],
],
"type"
:
"object"
"properties"
:
{
"created_at"
:
{
"type"
:
"string"
},
"id"
:
{
"type"
:
"integer"
},
"iid"
:
{
"type"
:
"integer"
},
"last?"
:
{
"type"
:
"boolean"
},
"ref"
:
{
"type"
:
"object"
,
"required"
:
[
"name"
],
"properties"
:
{
"name"
:
{
"type"
:
"string"
}
},
"additionalProperties"
:
false
},
"sha"
:
{
"type"
:
"string"
},
"tag"
:
{
"type"
:
"boolean"
}
},
"additionalProperties"
:
false
}
}
spec/fixtures/api/schemas/entities/commit.json
0 → 100644
View file @
3bc5f711
{
"type"
:
"object"
,
"allOf"
:
[
{
"$ref"
:
"../public_api/v4/commit/basic.json"
},
{
"type"
:
"object"
,
"required"
:
[
"author_gravatar_url"
,
"commit_url"
,
"commit_path"
,
"author"
],
"properties"
:
{
"author_gravatar_url"
:
{
"type"
:
"string"
},
"commit_url"
:
{
"type"
:
"string"
},
"commit_path"
:
{
"type"
:
"string"
},
"author"
:
{
"oneOf"
:
[
{
"type"
:
"null"
},
{
"type"
:
"user.json"
}
]
}
},
"additionalProperties"
:
false
}
]
}
spec/fixtures/api/schemas/entities/user.json
View file @
3bc5f711
...
@@ -5,13 +5,19 @@
...
@@ -5,13 +5,19 @@
"state"
,
"state"
,
"avatar_url"
,
"avatar_url"
,
"web_url"
,
"web_url"
,
"path"
"path"
,
"name"
,
"username"
],
],
"properties"
:
{
"properties"
:
{
"id"
:
{
"type"
:
"integer"
},
"id"
:
{
"type"
:
"integer"
},
"state"
:
{
"type"
:
"string"
},
"state"
:
{
"type"
:
"string"
},
"avatar_url"
:
{
"type"
:
"string"
},
"avatar_url"
:
{
"type"
:
"string"
},
"web_url"
:
{
"type"
:
"string"
},
"web_url"
:
{
"type"
:
"string"
},
"path"
:
{
"type"
:
"string"
}
"path"
:
{
"type"
:
"string"
},
}
"name"
:
{
"type"
:
"string"
},
"username"
:
{
"type"
:
"string"
},
"status_tooltip_html"
:
{
"$ref"
:
"../types/nullable_string.json"
}
},
"additionalProperties"
:
false
}
}
spec/fixtures/api/schemas/environment.json
0 → 100644
View file @
3bc5f711
{
"type"
:
"object"
,
"required"
:
[
"id"
,
"name"
,
"state"
,
"external_url"
,
"environment_type"
,
"has_stop_action"
,
"environment_path"
,
"stop_path"
,
"folder_path"
,
"created_at"
,
"updated_at"
,
"can_stop"
],
"properties"
:
{
"id"
:
{
"type"
:
"integer"
},
"name"
:
{
"type"
:
"string"
},
"state"
:
{
"type"
:
"string"
},
"external_url"
:
{
"$ref"
:
"types/nullable_string.json"
},
"environment_type"
:
{
"$ref"
:
"types/nullable_string.json"
},
"has_stop_action"
:
{
"type"
:
"boolean"
},
"environment_path"
:
{
"type"
:
"string"
},
"stop_path"
:
{
"type"
:
"string"
},
"folder_path"
:
{
"type"
:
"string"
},
"created_at"
:
{
"type"
:
"string"
,
"format"
:
"date-time"
},
"updated_at"
:
{
"type"
:
"string"
,
"format"
:
"date-time"
},
"can_stop"
:
{
"type"
:
"boolean"
},
"last_deployment"
:
{
"oneOf"
:
[
{
"type"
:
"null"
},
{
"$ref"
:
"deployment.json"
}
]
}
},
"additionalProperties"
:
false
}
spec/fixtures/api/schemas/job/deployment_status.json
0 → 100644
View file @
3bc5f711
{
"type"
:
"object"
,
"required"
:
[
"status"
,
"icon"
,
"environment"
],
"properties"
:
{
"status"
:
{
"oneOf"
:
[
{
"type"
:
"string"
,
"enum"
:
[
"last"
,
"creating"
,
"failed"
,
"out_of_date"
]
},
{
"type"
:
"null"
}
]
},
"icon"
:
{
"type"
:
"string"
},
"environment"
:
{
"$ref"
:
"../environment.json"
}
},
"additionalProperties"
:
false
}
spec/fixtures/api/schemas/job/job_details.json
View file @
3bc5f711
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
"properties"
:
{
"properties"
:
{
"artifact"
:
{
"$ref"
:
"artifact.json"
},
"artifact"
:
{
"$ref"
:
"artifact.json"
},
"terminal_path"
:
{
"type"
:
"string"
},
"terminal_path"
:
{
"type"
:
"string"
},
"trigger"
:
{
"$ref"
:
"trigger.json"
}
"trigger"
:
{
"$ref"
:
"trigger.json"
},
"deployment_status"
:
{
"$ref"
:
"deployment_status.json"
}
}
}
}
}
spec/fixtures/api/schemas/types/nullable_string.json
0 → 100644
View file @
3bc5f711
{
"oneOf"
:
[
{
"type"
:
"null"
},
{
"type"
:
"string"
}
]
}
spec/models/ci/build_spec.rb
View file @
3bc5f711
...
@@ -2981,4 +2981,46 @@ describe Ci::Build do
...
@@ -2981,4 +2981,46 @@ describe Ci::Build do
end
end
end
end
end
end
describe
'#deployment_status'
do
context
'when build is a last deployment'
do
let
(
:build
)
{
create
(
:ci_build
,
:success
,
environment:
'production'
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
build
.
project
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
deployable:
build
)
}
it
{
expect
(
build
.
deployment_status
).
to
eq
(
:last
)
}
end
context
'when there is a newer build with deployment'
do
let
(
:build
)
{
create
(
:ci_build
,
:success
,
environment:
'production'
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
build
.
project
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
deployable:
build
)
}
let!
(
:last_deployment
)
{
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
)
}
it
{
expect
(
build
.
deployment_status
).
to
eq
(
:out_of_date
)
}
end
context
'when build with deployment has failed'
do
let
(
:build
)
{
create
(
:ci_build
,
:failed
,
environment:
'production'
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
build
.
project
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
deployable:
build
)
}
it
{
expect
(
build
.
deployment_status
).
to
eq
(
:failed
)
}
end
context
'when build with deployment is running'
do
let
(
:build
)
{
create
(
:ci_build
,
environment:
'production'
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
build
.
project
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
,
project:
environment
.
project
,
deployable:
build
)
}
it
{
expect
(
build
.
deployment_status
).
to
eq
(
:creating
)
}
end
context
'when build is successful but deployment is not ready yet'
do
let
(
:build
)
{
create
(
:ci_build
,
:success
,
environment:
'production'
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
build
.
project
)
}
it
{
expect
(
build
.
deployment_status
).
to
eq
(
:creating
)
}
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