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
4ddf9636
Commit
4ddf9636
authored
Nov 25, 2020
by
Avielle Wolfe
Committed by
Kerri Miller
Nov 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set up JobArtifactType with a dummy download_path
And add artifacts field to JobType
parent
3274b67d
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
734 additions
and
36 deletions
+734
-36
app/graphql/types/ci/job_artifact_file_type_enum.rb
app/graphql/types/ci/job_artifact_file_type_enum.rb
+13
-0
app/graphql/types/ci/job_artifact_type.rb
app/graphql/types/ci/job_artifact_type.rb
+24
-0
app/graphql/types/ci/job_type.rb
app/graphql/types/ci/job_type.rb
+13
-0
changelogs/unreleased/251015-artifact-download.yml
changelogs/unreleased/251015-artifact-download.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+102
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+379
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+40
-0
spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb
spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb
+11
-0
spec/graphql/types/ci/job_artifact_type_spec.rb
spec/graphql/types/ci/job_artifact_type_spec.rb
+11
-0
spec/graphql/types/ci/job_type_spec.rb
spec/graphql/types/ci/job_type_spec.rb
+1
-0
spec/requests/api/graphql/ci/job_artifacts_spec.rb
spec/requests/api/graphql/ci/job_artifacts_spec.rb
+52
-0
spec/requests/api/graphql/ci/jobs_spec.rb
spec/requests/api/graphql/ci/jobs_spec.rb
+83
-36
No files found.
app/graphql/types/ci/job_artifact_file_type_enum.rb
0 → 100644
View file @
4ddf9636
# frozen_string_literal: true
module
Types
module
Ci
class
JobArtifactFileTypeEnum
<
BaseEnum
graphql_name
'JobArtifactFileType'
::
Ci
::
JobArtifact
::
TYPE_AND_FORMAT_PAIRS
.
keys
.
each
do
|
file_type
|
value
file_type
.
to_s
.
upcase
,
value:
file_type
.
to_s
end
end
end
end
app/graphql/types/ci/job_artifact_type.rb
0 → 100644
View file @
4ddf9636
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
JobArtifactType
<
BaseObject
graphql_name
'CiJobArtifact'
field
:download_path
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
"URL for downloading the artifact's file"
field
:file_type
,
::
Types
::
Ci
::
JobArtifactFileTypeEnum
,
null:
true
,
description:
'File type of the artifact'
def
download_path
::
Gitlab
::
Routing
.
url_helpers
.
download_project_job_artifacts_path
(
object
.
project
,
object
.
job
,
file_type:
object
.
file_type
)
end
end
end
end
app/graphql/types/ci/job_type.rb
View file @
4ddf9636
...
...
@@ -9,15 +9,28 @@ module Types
field
:pipeline
,
Types
::
Ci
::
PipelineType
,
null:
false
,
description:
'Pipeline the job belongs to'
,
resolve:
->
(
build
,
_
,
_
)
{
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
::
Ci
::
Pipeline
,
build
.
pipeline_id
).
find
}
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the job'
field
:needs
,
JobType
.
connection_type
,
null:
true
,
description:
'Builds that must complete before the jobs run'
field
:detailed_status
,
Types
::
Ci
::
DetailedStatusType
,
null:
true
,
description:
'Detailed status of the job'
,
resolve:
->
(
obj
,
_args
,
ctx
)
{
obj
.
detailed_status
(
ctx
[
:current_user
])
}
field
:scheduled_at
,
Types
::
TimeType
,
null:
true
,
description:
'Schedule for the build'
field
:artifacts
,
Types
::
Ci
::
JobArtifactType
.
connection_type
,
null:
true
,
description:
'Artifacts generated by the job'
def
artifacts
if
object
.
is_a?
(
::
Ci
::
Build
)
object
.
job_artifacts
end
end
end
end
end
changelogs/unreleased/251015-artifact-download.yml
0 → 100644
View file @
4ddf9636
---
title
:
Add artifacts field to JobType
merge_request
:
48207
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
4ddf9636
...
...
@@ -2315,6 +2315,31 @@ type CiGroupEdge {
}
type
CiJob
{
"""
Artifacts
generated
by
the
job
"""
artifacts
(
"""
Returns
the
elements
in
the
list
that
come
after
the
specified
cursor
.
"""
after
:
String
"""
Returns
the
elements
in
the
list
that
come
before
the
specified
cursor
.
"""
before
:
String
"""
Returns
the
first
_n_
elements
from
the
list
.
"""
first
:
Int
"""
Returns
the
last
_n_
elements
from
the
list
.
"""
last
:
Int
):
CiJobArtifactConnection
"""
Detailed
status
of
the
job
"""
...
...
@@ -2361,6 +2386,53 @@ type CiJob {
scheduledAt
:
Time
}
type
CiJobArtifact
{
"""
URL
for
downloading
the
artifact
'
s
file
"""
downloadPath
:
String
"""
File
type
of
the
artifact
"""
fileType
:
JobArtifactFileType
}
"""
The connection type for CiJobArtifact.
"""
type
CiJobArtifactConnection
{
"""
A
list
of
edges
.
"""
edges
:
[
CiJobArtifactEdge
]
"""
A
list
of
nodes
.
"""
nodes
:
[
CiJobArtifact
]
"""
Information
to
aid
in
pagination
.
"""
pageInfo
:
PageInfo
!
}
"""
An edge in a connection.
"""
type
CiJobArtifactEdge
{
"""
A
cursor
for
use
in
pagination
.
"""
cursor
:
String
!
"""
The
item
at
the
end
of
the
edge
.
"""
node
:
CiJobArtifact
}
"""
The connection type for CiJob.
"""
...
...
@@ -12038,6 +12110,36 @@ input JiraUsersMappingInputType {
jiraAccountId
:
String
!
}
enum
JobArtifactFileType
{
ACCESSIBILITY
API_FUZZING
ARCHIVE
BROWSER_PERFORMANCE
CLUSTER_APPLICATIONS
COBERTURA
CODEQUALITY
CONTAINER_SCANNING
COVERAGE_FUZZING
DAST
DEPENDENCY_SCANNING
DOTENV
JUNIT
LICENSE_MANAGEMENT
LICENSE_SCANNING
LOAD_PERFORMANCE
LSIF
METADATA
METRICS
METRICS_REFEREE
NETWORK_REFEREE
PERFORMANCE
REQUIREMENTS
SAST
SECRET_DETECTION
TERRAFORM
TRACE
}
type
Label
{
"""
Background
color
of
the
label
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
4ddf9636
This diff is collapsed.
Click to expand it.
doc/api/graphql/reference/index.md
View file @
4ddf9636
...
...
@@ -380,12 +380,20 @@ Represents the total number of issues and their weights for a particular day.
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`artifacts`
| CiJobArtifactConnection | Artifacts generated by the job |
|
`detailedStatus`
| DetailedStatus | Detailed status of the job |
|
`name`
| String | Name of the job |
|
`needs`
| CiJobConnection | Builds that must complete before the jobs run |
|
`pipeline`
| Pipeline! | Pipeline the job belongs to |
|
`scheduledAt`
| Time | Schedule for the build |
### CiJobArtifact
| Field | Type | Description |
| ----- | ---- | ----------- |
|
`downloadPath`
| String | URL for downloading the artifact's file |
|
`fileType`
| JobArtifactFileType | File type of the artifact |
### CiStage
| Field | Type | Description |
...
...
@@ -4145,6 +4153,38 @@ Iteration ID wildcard values.
|
`ANY`
| An iteration is assigned |
|
`NONE`
| No iteration is assigned |
### JobArtifactFileType
| Value | Description |
| ----- | ----------- |
|
`ACCESSIBILITY`
| |
|
`API_FUZZING`
| |
|
`ARCHIVE`
| |
|
`BROWSER_PERFORMANCE`
| |
|
`CLUSTER_APPLICATIONS`
| |
|
`COBERTURA`
| |
|
`CODEQUALITY`
| |
|
`CONTAINER_SCANNING`
| |
|
`COVERAGE_FUZZING`
| |
|
`DAST`
| |
|
`DEPENDENCY_SCANNING`
| |
|
`DOTENV`
| |
|
`JUNIT`
| |
|
`LICENSE_MANAGEMENT`
| |
|
`LICENSE_SCANNING`
| |
|
`LOAD_PERFORMANCE`
| |
|
`LSIF`
| |
|
`METADATA`
| |
|
`METRICS`
| |
|
`METRICS_REFEREE`
| |
|
`NETWORK_REFEREE`
| |
|
`PERFORMANCE`
| |
|
`REQUIREMENTS`
| |
|
`SAST`
| |
|
`SECRET_DETECTION`
| |
|
`TERRAFORM`
| |
|
`TRACE`
| |
### ListLimitMetric
List limit metric setting.
...
...
spec/graphql/types/ci/job_artifact_file_type_enum_spec.rb
0 → 100644
View file @
4ddf9636
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
GitlabSchema
.
types
[
'JobArtifactFileType'
]
do
it
'exposes all job artifact file types'
do
expect
(
described_class
.
values
.
keys
).
to
contain_exactly
(
*::
Ci
::
JobArtifact
::
TYPE_AND_FORMAT_PAIRS
.
keys
.
map
(
&
:to_s
).
map
(
&
:upcase
)
)
end
end
spec/graphql/types/ci/job_artifact_type_spec.rb
0 → 100644
View file @
4ddf9636
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
GitlabSchema
.
types
[
'CiJobArtifact'
]
do
it
'has the correct fields'
do
expected_fields
=
[
:download_path
,
:file_type
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/ci/job_type_spec.rb
View file @
4ddf9636
...
...
@@ -12,6 +12,7 @@ RSpec.describe Types::Ci::JobType do
needs
detailedStatus
scheduledAt
artifacts
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
...
...
spec/requests/api/graphql/ci/job_artifacts_spec.rb
0 → 100644
View file @
4ddf9636
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Query.project(fullPath).pipelines.jobs.artifacts'
do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines {
nodes {
jobs {
nodes {
artifacts {
nodes {
downloadPath
fileType
}
}
}
}
}
}
}
}
)
end
it
'returns the fields for the artifacts'
do
job
=
create
(
:ci_build
,
pipeline:
pipeline
)
create
(
:ci_job_artifact
,
:junit
,
job:
job
)
post_graphql
(
query
,
current_user:
user
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
pipelines_data
=
graphql_data
.
dig
(
'project'
,
'pipelines'
,
'nodes'
)
jobs_data
=
pipelines_data
.
first
.
dig
(
'jobs'
,
'nodes'
)
artifact_data
=
jobs_data
.
first
.
dig
(
'artifacts'
,
'nodes'
).
first
expect
(
artifact_data
[
'downloadPath'
]).
to
eq
(
"/
#{
project
.
full_path
}
/-/jobs/
#{
job
.
id
}
/artifacts/download?file_type=junit"
)
expect
(
artifact_data
[
'fileType'
]).
to
eq
(
'JUNIT'
)
end
end
spec/requests/api/graphql/ci/jobs_spec.rb
View file @
4ddf9636
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Query.project.pipeline
.stages.groups.jobs
'
do
RSpec
.
describe
'Query.project.pipeline'
do
include
GraphqlHelpers
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
stage
=
create
(
:ci_stage_entity
,
pipeline:
pipeline
,
name:
'first'
)
create
(
:commit_status
,
stage_id:
stage
.
id
,
pipeline:
pipeline
,
name:
'my test job'
)
pipeline
end
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
def
first
(
field
)
[
field
.
pluralize
,
'nodes'
,
0
]
end
let
(
:jobs_graphql_data
)
{
graphql_data
.
dig
(
*
%w[project pipeline]
,
*
first
(
'stage'
),
*
first
(
'group'
),
'jobs'
,
'nodes'
)
}
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
nodes {
name
groups {
nodes {
name
jobs {
nodes {
name
pipeline {
id
describe
'.stages.groups.jobs'
do
let
(
:pipeline
)
do
pipeline
=
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
stage
=
create
(
:ci_stage_entity
,
pipeline:
pipeline
,
name:
'first'
)
create
(
:commit_status
,
stage_id:
stage
.
id
,
pipeline:
pipeline
,
name:
'my test job'
)
pipeline
end
let
(
:jobs_graphql_data
)
{
graphql_data
.
dig
(
*
%w[project pipeline]
,
*
first
(
'stage'
),
*
first
(
'group'
),
'jobs'
,
'nodes'
)
}
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
nodes {
name
groups {
nodes {
name
jobs {
nodes {
name
pipeline {
id
}
}
}
}
...
...
@@ -45,17 +48,15 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
}
}
}
}
)
end
)
end
it
'returns the jobs of a pipeline stage'
do
post_graphql
(
query
,
current_user:
user
)
it
'returns the jobs of a pipeline stage'
do
post_graphql
(
query
,
current_user:
user
)
expect
(
jobs_graphql_data
).
to
contain_exactly
(
a_hash_including
(
'name'
=>
'my test job'
))
end
expect
(
jobs_graphql_data
).
to
contain_exactly
(
a_hash_including
(
'name'
=>
'my test job'
))
end
context
'when fetching jobs from the pipeline'
do
it
'avoids N+1 queries'
,
:aggregate_failures
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
post_graphql
(
query
,
current_user:
user
)
...
...
@@ -112,4 +113,50 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
])
end
end
describe
'.jobs.artifacts'
do
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
jobs {
nodes {
artifacts {
nodes {
downloadPath
}
}
}
}
}
}
}
)
end
context
'when the job is a build'
do
it
"returns the build's artifacts"
do
create
(
:ci_build
,
:artifacts
,
pipeline:
pipeline
)
post_graphql
(
query
,
current_user:
user
)
job_data
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'jobs'
,
'nodes'
).
first
expect
(
job_data
.
dig
(
'artifacts'
,
'nodes'
).
count
).
to
be
(
2
)
end
end
context
'when the job is not a build'
do
it
'returns nil'
do
create
(
:ci_bridge
,
pipeline:
pipeline
)
post_graphql
(
query
,
current_user:
user
)
job_data
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'jobs'
,
'nodes'
).
first
expect
(
job_data
[
'artifacts'
]).
to
be_nil
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