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
67cc6cdd
Commit
67cc6cdd
authored
Mar 24, 2021
by
pburdette
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add jobs field
Add jobs field to the project type.
parent
97d7e378
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
100 additions
and
2 deletions
+100
-2
app/graphql/resolvers/project_jobs_resolver.rb
app/graphql/resolvers/project_jobs_resolver.rb
+38
-0
app/graphql/types/project_type.rb
app/graphql/types/project_type.rb
+8
-0
changelogs/unreleased/pb-add-jobs-field-to-project-type.yml
changelogs/unreleased/pb-add-jobs-field-to-project-type.yml
+5
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/resolvers/project_jobs_resolver_spec.rb
spec/graphql/resolvers/project_jobs_resolver_spec.rb
+39
-0
spec/graphql/types/project_type_spec.rb
spec/graphql/types/project_type_spec.rb
+7
-0
spec/requests/api/graphql/project/container_repositories_spec.rb
...quests/api/graphql/project/container_repositories_spec.rb
+1
-1
spec/requests/api/graphql/project/merge_request_spec.rb
spec/requests/api/graphql/project/merge_request_spec.rb
+1
-1
No files found.
app/graphql/resolvers/project_jobs_resolver.rb
0 → 100644
View file @
67cc6cdd
# frozen_string_literal: true
module
Resolvers
class
ProjectJobsResolver
<
BaseResolver
include
LooksAhead
type
::
Types
::
Ci
::
JobType
.
connection_type
,
null:
true
alias_method
:project
,
:object
argument
:statuses
,
[
::
Types
::
Ci
::
JobStatusEnum
],
required:
false
,
description:
'Filter jobs by status.'
def
ready?
(
**
args
)
context
[
self
.
class
]
||=
{
executions:
0
}
context
[
self
.
class
][
:executions
]
+=
1
raise
GraphQL
::
ExecutionError
,
"Jobs can only be requested for one project at a time"
if
context
[
self
.
class
][
:executions
]
>
1
super
end
def
resolve_with_lookahead
(
statuses:
nil
)
jobs
=
::
Ci
::
JobsFinder
.
new
(
current_user:
current_user
,
project:
project
,
params:
{
scope:
statuses
}).
execute
apply_lookahead
(
jobs
)
end
private
def
preloads
[
{
artifacts: :job_artifacts
},
{
pipeline: :user
}
]
end
end
end
app/graphql/types/project_type.rb
View file @
67cc6cdd
...
@@ -183,6 +183,14 @@ module Types
...
@@ -183,6 +183,14 @@ module Types
description:
'Packages of the project.'
,
description:
'Packages of the project.'
,
resolver:
Resolvers
::
ProjectPackagesResolver
resolver:
Resolvers
::
ProjectPackagesResolver
field
:jobs
,
Types
::
Ci
::
JobType
.
connection_type
,
null:
true
,
description:
'Jobs of a project, only jobs of a single project can be requested at a time.'
,
extras:
[
:lookahead
],
resolver:
Resolvers
::
ProjectJobsResolver
,
authorize: :read_build
field
:pipelines
,
field
:pipelines
,
null:
true
,
null:
true
,
description:
'Build pipelines of the project.'
,
description:
'Build pipelines of the project.'
,
...
...
changelogs/unreleased/pb-add-jobs-field-to-project-type.yml
0 → 100644
View file @
67cc6cdd
---
title
:
Add jobs field to the project type
merge_request
:
57376
author
:
type
:
added
doc/api/graphql/reference/index.md
View file @
67cc6cdd
...
@@ -4771,6 +4771,7 @@ An edge in a connection.
...
@@ -4771,6 +4771,7 @@ An edge in a connection.
|
`iterations`
|
[
`IterationConnection`
](
#iterationconnection
)
| Find iterations. |
|
`iterations`
|
[
`IterationConnection`
](
#iterationconnection
)
| Find iterations. |
|
`jiraImportStatus`
|
[
`String`
](
#string
)
| Status of Jira import background job of the project. |
|
`jiraImportStatus`
|
[
`String`
](
#string
)
| Status of Jira import background job of the project. |
|
`jiraImports`
|
[
`JiraImportConnection`
](
#jiraimportconnection
)
| Jira imports into the project. |
|
`jiraImports`
|
[
`JiraImportConnection`
](
#jiraimportconnection
)
| Jira imports into the project. |
|
`jobs`
|
[
`CiJobConnection`
](
#cijobconnection
)
| Jobs of a project, only jobs of a single project can be requested at a time. |
|
`jobsEnabled`
|
[
`Boolean`
](
#boolean
)
| Indicates if CI/CD pipeline jobs are enabled for the current user. |
|
`jobsEnabled`
|
[
`Boolean`
](
#boolean
)
| Indicates if CI/CD pipeline jobs are enabled for the current user. |
|
`label`
|
[
`Label`
](
#label
)
| A label available on this project. |
|
`label`
|
[
`Label`
](
#label
)
| A label available on this project. |
|
`labels`
|
[
`LabelConnection`
](
#labelconnection
)
| Labels available on this project. |
|
`labels`
|
[
`LabelConnection`
](
#labelconnection
)
| Labels available on this project. |
...
...
spec/graphql/resolvers/project_jobs_resolver_spec.rb
0 → 100644
View file @
67cc6cdd
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
ProjectJobsResolver
do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:irrelevant_project
)
{
create
(
:project
,
:repository
,
:public
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let_it_be
(
:irrelevant_pipeline
)
{
create
(
:ci_pipeline
,
project:
irrelevant_project
)
}
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:build_one
)
{
create
(
:ci_build
,
:success
,
name:
'Build One'
,
pipeline:
pipeline
)
}
let
(
:build_two
)
{
create
(
:ci_build
,
:success
,
name:
'Build Two'
,
pipeline:
pipeline
)
}
let
(
:build_three
)
{
create
(
:ci_build
,
:failed
,
name:
'Build Three'
,
pipeline:
pipeline
)
}
let
(
:irrelevant_build
)
{
create
(
:ci_build
,
name:
'Irrelevant Build'
,
pipeline:
irrelevant_pipeline
)}
let
(
:args
)
{
{}
}
subject
{
resolve_jobs
(
args
)
}
describe
'#resolve'
do
context
'with statuses argument'
do
let
(
:args
)
{
{
statuses:
[
Types
::
Ci
::
JobStatusEnum
.
values
[
'SUCCESS'
].
value
]
}
}
it
{
is_expected
.
to
contain_exactly
(
build_one
,
build_two
)
}
end
context
'without statuses argument'
do
it
{
is_expected
.
to
contain_exactly
(
build_one
,
build_two
,
build_three
)
}
end
end
private
def
resolve_jobs
(
args
=
{},
context
=
{
current_user:
current_user
})
resolve
(
described_class
,
obj:
project
,
args:
args
,
ctx:
context
)
end
end
spec/graphql/types/project_type_spec.rb
View file @
67cc6cdd
...
@@ -371,4 +371,11 @@ RSpec.describe GitlabSchema.types['Project'] do
...
@@ -371,4 +371,11 @@ RSpec.describe GitlabSchema.types['Project'] do
it
{
is_expected
.
to
have_graphql_type
(
Types
::
Ci
::
AnalyticsType
)
}
it
{
is_expected
.
to
have_graphql_type
(
Types
::
Ci
::
AnalyticsType
)
}
it
{
is_expected
.
to
have_graphql_resolver
(
Resolvers
::
ProjectPipelineStatisticsResolver
)
}
it
{
is_expected
.
to
have_graphql_resolver
(
Resolvers
::
ProjectPipelineStatisticsResolver
)
}
end
end
describe
'jobs field'
do
subject
{
described_class
.
fields
[
'jobs'
]
}
it
{
is_expected
.
to
have_graphql_type
(
Types
::
Ci
::
JobType
.
connection_type
)
}
it
{
is_expected
.
to
have_graphql_arguments
(
:statuses
)
}
end
end
end
spec/requests/api/graphql/project/container_repositories_spec.rb
View file @
67cc6cdd
...
@@ -16,7 +16,7 @@ RSpec.describe 'getting container repositories in a project' do
...
@@ -16,7 +16,7 @@ RSpec.describe 'getting container repositories in a project' do
<<~
GQL
<<~
GQL
edges {
edges {
node {
node {
#{
all_graphql_fields_for
(
'container_repositories'
.
classify
,
excluded:
[
'pipeline'
]
)
}
#{
all_graphql_fields_for
(
'container_repositories'
.
classify
,
excluded:
%w(pipeline jobs)
)
}
}
}
}
}
GQL
GQL
...
...
spec/requests/api/graphql/project/merge_request_spec.rb
View file @
67cc6cdd
...
@@ -9,7 +9,7 @@ RSpec.describe 'getting merge request information nested in a project' do
...
@@ -9,7 +9,7 @@ RSpec.describe 'getting merge request information nested in a project' do
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:merge_request_graphql_data
)
{
graphql_data
[
'project'
][
'mergeRequest'
]
}
let
(
:merge_request_graphql_data
)
{
graphql_data
[
'project'
][
'mergeRequest'
]
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let!
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:mr_fields
)
{
all_graphql_fields_for
(
'MergeRequest'
,
excluded:
[
'pipeline'
]
)
}
let
(
:mr_fields
)
{
all_graphql_fields_for
(
'MergeRequest'
,
excluded:
%w(pipeline jobs)
)
}
let
(
:query
)
do
let
(
:query
)
do
graphql_query_for
(
graphql_query_for
(
...
...
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