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
4451c5a0
Commit
4451c5a0
authored
Aug 11, 2020
by
Laura Montemayor
Committed by
Vitali Tatarintev
Aug 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds graphql types
* Stages, jobs, and groups
parent
f6e53638
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
1208 additions
and
0 deletions
+1208
-0
app/graphql/resolvers/ci/pipeline_stages_resolver.rb
app/graphql/resolvers/ci/pipeline_stages_resolver.rb
+21
-0
app/graphql/types/ci/group_type.rb
app/graphql/types/ci/group_type.rb
+17
-0
app/graphql/types/ci/job_type.rb
app/graphql/types/ci/job_type.rb
+15
-0
app/graphql/types/ci/pipeline_type.rb
app/graphql/types/ci/pipeline_type.rb
+4
-0
app/graphql/types/ci/stage_type.rb
app/graphql/types/ci/stage_type.rb
+15
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+231
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+643
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+19
-0
spec/graphql/types/ci/group_type_spec.rb
spec/graphql/types/ci/group_type_spec.rb
+17
-0
spec/graphql/types/ci/job_type_spec.rb
spec/graphql/types/ci/job_type_spec.rb
+16
-0
spec/graphql/types/ci/stage_type_spec.rb
spec/graphql/types/ci/stage_type_spec.rb
+16
-0
spec/requests/api/graphql/ci/groups_spec.rb
spec/requests/api/graphql/ci/groups_spec.rb
+55
-0
spec/requests/api/graphql/ci/jobs_spec.rb
spec/requests/api/graphql/ci/jobs_spec.rb
+93
-0
spec/requests/api/graphql/ci/stages_spec.rb
spec/requests/api/graphql/ci/stages_spec.rb
+46
-0
No files found.
app/graphql/resolvers/ci/pipeline_stages_resolver.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
module
Resolvers
module
Ci
class
PipelineStagesResolver
<
BaseResolver
include
LooksAhead
alias_method
:pipeline
,
:object
def
resolve_with_lookahead
apply_lookahead
(
pipeline
.
stages
)
end
def
preloads
{
statuses:
[
:needs
]
}
end
end
end
end
app/graphql/types/ci/group_type.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
GroupType
<
BaseObject
graphql_name
'CiGroup'
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the job group'
field
:size
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Size of the group'
field
:jobs
,
Ci
::
JobType
.
connection_type
,
null:
true
,
description:
'Jobs in group'
end
end
end
app/graphql/types/ci/job_type.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
JobType
<
BaseObject
graphql_name
'CiJob'
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'
end
end
end
app/graphql/types/ci/pipeline_type.rb
View file @
4451c5a0
...
...
@@ -37,6 +37,10 @@ module Types
description:
"Timestamp of the pipeline's completion"
field
:committed_at
,
Types
::
TimeType
,
null:
true
,
description:
"Timestamp of the pipeline's commit"
field
:stages
,
Types
::
Ci
::
StageType
.
connection_type
,
null:
true
,
description:
'Stages of the pipeline'
,
extras:
[
:lookahead
],
resolver:
Resolvers
::
Ci
::
PipelineStagesResolver
# TODO: Add triggering user as a type
end
...
...
app/graphql/types/ci/stage_type.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
StageType
<
BaseObject
graphql_name
'CiStage'
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Name of the stage'
field
:groups
,
Ci
::
GroupType
.
connection_type
,
null:
true
,
description:
'Group of jobs for the stage'
end
end
end
doc/api/graphql/reference/gitlab_schema.graphql
View file @
4451c5a0
...
...
@@ -1347,6 +1347,212 @@ type Branch {
name
:
String
!
}
type
CiGroup
{
"""
Jobs
in
group
"""
jobs
(
"""
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
):
CiJobConnection
"""
Name
of
the
job
group
"""
name
:
String
"""
Size
of
the
group
"""
size
:
Int
}
"""
The connection type for CiGroup.
"""
type
CiGroupConnection
{
"""
A
list
of
edges
.
"""
edges
:
[
CiGroupEdge
]
"""
A
list
of
nodes
.
"""
nodes
:
[
CiGroup
]
"""
Information
to
aid
in
pagination
.
"""
pageInfo
:
PageInfo
!
}
"""
An edge in a connection.
"""
type
CiGroupEdge
{
"""
A
cursor
for
use
in
pagination
.
"""
cursor
:
String
!
"""
The
item
at
the
end
of
the
edge
.
"""
node
:
CiGroup
}
type
CiJob
{
"""
Name
of
the
job
"""
name
:
String
"""
Builds
that
must
complete
before
the
jobs
run
"""
needs
(
"""
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
):
CiJobConnection
}
"""
The connection type for CiJob.
"""
type
CiJobConnection
{
"""
A
list
of
edges
.
"""
edges
:
[
CiJobEdge
]
"""
A
list
of
nodes
.
"""
nodes
:
[
CiJob
]
"""
Information
to
aid
in
pagination
.
"""
pageInfo
:
PageInfo
!
}
"""
An edge in a connection.
"""
type
CiJobEdge
{
"""
A
cursor
for
use
in
pagination
.
"""
cursor
:
String
!
"""
The
item
at
the
end
of
the
edge
.
"""
node
:
CiJob
}
type
CiStage
{
"""
Group
of
jobs
for
the
stage
"""
groups
(
"""
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
):
CiGroupConnection
"""
Name
of
the
stage
"""
name
:
String
}
"""
The connection type for CiStage.
"""
type
CiStageConnection
{
"""
A
list
of
edges
.
"""
edges
:
[
CiStageEdge
]
"""
A
list
of
nodes
.
"""
nodes
:
[
CiStage
]
"""
Information
to
aid
in
pagination
.
"""
pageInfo
:
PageInfo
!
}
"""
An edge in a connection.
"""
type
CiStageEdge
{
"""
A
cursor
for
use
in
pagination
.
"""
cursor
:
String
!
"""
The
item
at
the
end
of
the
edge
.
"""
node
:
CiStage
}
type
Commit
{
"""
Author
of
the
commit
...
...
@@ -9850,6 +10056,31 @@ type Pipeline {
"""
sha
:
String
!
"""
Stages
of
the
pipeline
"""
stages
(
"""
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
):
CiStageConnection
"""
Timestamp
when
the
pipeline
was
started
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
4451c5a0
This diff is collapsed.
Click to expand it.
doc/api/graphql/reference/index.md
View file @
4451c5a0
...
...
@@ -231,6 +231,25 @@ Autogenerated return type of BoardListUpdateLimitMetrics
|
`commit`
| Commit | Commit for the branch |
|
`name`
| String! | Name of the branch |
## CiGroup
| Name | Type | Description |
| --- | ---- | ---------- |
|
`name`
| String | Name of the job group |
|
`size`
| Int | Size of the group |
## CiJob
| Name | Type | Description |
| --- | ---- | ---------- |
|
`name`
| String | Name of the job |
## CiStage
| Name | Type | Description |
| --- | ---- | ---------- |
|
`name`
| String | Name of the stage |
## Commit
| Name | Type | Description |
...
...
spec/graphql/types/ci/group_type_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
GroupType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'CiGroup'
)
}
it
'exposes the expected fields'
do
expected_fields
=
%i[
name
size
jobs
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/ci/job_type_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
JobType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'CiJob'
)
}
it
'exposes the expected fields'
do
expected_fields
=
%i[
name
needs
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/ci/stage_type_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
StageType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'CiStage'
)
}
it
'exposes the expected fields'
do
expected_fields
=
%i[
name
groups
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/requests/api/graphql/ci/groups_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Query.project.pipeline.stages.groups'
do
include
GraphqlHelpers
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
}
let
(
:group_graphql_data
)
{
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'stages'
,
'nodes'
,
0
,
'groups'
,
'nodes'
)
}
let
(
:params
)
{
{}
}
let
(
:fields
)
do
<<~
QUERY
nodes {
#{
all_graphql_fields_for
(
'CiGroup'
)
}
}
QUERY
end
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
nodes {
groups {
#{fields}
}
}
}
}
}
}
)
end
before
do
create
(
:commit_status
,
pipeline:
pipeline
,
name:
'rspec 0 2'
)
create
(
:commit_status
,
pipeline:
pipeline
,
name:
'rspec 0 1'
)
create
(
:commit_status
,
pipeline:
pipeline
,
name:
'spinach 0 1'
)
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
it
'returns a array of jobs belonging to a pipeline'
do
expect
(
group_graphql_data
.
map
{
|
g
|
g
.
slice
(
'name'
,
'size'
)
}).
to
eq
([
{
'name'
=>
'rspec'
,
'size'
=>
2
},
{
'name'
=>
'spinach'
,
'size'
=>
1
}
])
end
end
spec/requests/api/graphql/ci/jobs_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Query.project.pipeline.stages.groups.jobs'
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
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
}
}
}
}
}
}
}
}
}
)
end
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
context
'when fetching jobs from the pipeline'
do
it
'avoids N+1 queries'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
post_graphql
(
query
,
current_user:
user
)
end
build_stage
=
create
(
:ci_stage_entity
,
name:
'build'
,
pipeline:
pipeline
)
test_stage
=
create
(
:ci_stage_entity
,
name:
'test'
,
pipeline:
pipeline
)
create
(
:commit_status
,
pipeline:
pipeline
,
stage_id:
build_stage
.
id
,
name:
'docker 1 2'
)
create
(
:commit_status
,
pipeline:
pipeline
,
stage_id:
build_stage
.
id
,
name:
'docker 2 2'
)
create
(
:commit_status
,
pipeline:
pipeline
,
stage_id:
test_stage
.
id
,
name:
'rspec 1 2'
)
create
(
:commit_status
,
pipeline:
pipeline
,
stage_id:
test_stage
.
id
,
name:
'rspec 2 2'
)
expect
do
post_graphql
(
query
,
current_user:
user
)
end
.
not_to
exceed_query_limit
(
control_count
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
build_stage
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'stages'
,
'nodes'
).
find
do
|
stage
|
stage
[
'name'
]
==
'build'
end
test_stage
=
graphql_data
.
dig
(
'project'
,
'pipeline'
,
'stages'
,
'nodes'
).
find
do
|
stage
|
stage
[
'name'
]
==
'test'
end
docker_group
=
build_stage
.
dig
(
'groups'
,
'nodes'
).
first
rspec_group
=
test_stage
.
dig
(
'groups'
,
'nodes'
).
first
expect
(
docker_group
[
'name'
]).
to
eq
(
'docker'
)
expect
(
rspec_group
[
'name'
]).
to
eq
(
'rspec'
)
docker_jobs
=
docker_group
.
dig
(
'jobs'
,
'nodes'
)
rspec_jobs
=
rspec_group
.
dig
(
'jobs'
,
'nodes'
)
expect
(
docker_jobs
).
to
eq
([{
'name'
=>
'docker 1 2'
},
{
'name'
=>
'docker 2 2'
}])
expect
(
rspec_jobs
).
to
eq
([{
'name'
=>
'rspec 1 2'
},
{
'name'
=>
'rspec 2 2'
}])
end
end
end
spec/requests/api/graphql/ci/stages_spec.rb
0 → 100644
View file @
4451c5a0
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Query.project.pipeline.stages'
do
include
GraphqlHelpers
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
}
let
(
:stage_graphql_data
)
{
graphql_data
[
'project'
][
'pipeline'
][
'stages'
]
}
let
(
:params
)
{
{}
}
let
(
:fields
)
do
<<~
QUERY
nodes {
#{
all_graphql_fields_for
(
'CiStage'
)
}
}
QUERY
end
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
#{fields}
}
}
}
}
)
end
before
do
create
(
:ci_stage_entity
,
pipeline:
pipeline
,
name:
'deploy'
)
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
it
'returns the stage of a pipeline'
do
expect
(
stage_graphql_data
[
'nodes'
].
first
[
'name'
]).
to
eq
(
'deploy'
)
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