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
961b0b52
Commit
961b0b52
authored
Apr 26, 2021
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CI template field to project GraphQL type
Changelog: added
parent
c45b9155
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
0 deletions
+142
-0
app/graphql/resolvers/ci/template_resolver.rb
app/graphql/resolvers/ci/template_resolver.rb
+18
-0
app/graphql/types/ci/template_type.rb
app/graphql/types/ci/template_type.rb
+15
-0
app/graphql/types/project_type.rb
app/graphql/types/project_type.rb
+4
-0
spec/graphql/resolvers/ci/template_resolver_spec.rb
spec/graphql/resolvers/ci/template_resolver_spec.rb
+33
-0
spec/graphql/types/ci/template_type_spec.rb
spec/graphql/types/ci/template_type_spec.rb
+16
-0
spec/graphql/types/project_type_spec.rb
spec/graphql/types/project_type_spec.rb
+8
-0
spec/requests/api/graphql/ci/template_spec.rb
spec/requests/api/graphql/ci/template_spec.rb
+48
-0
No files found.
app/graphql/resolvers/ci/template_resolver.rb
0 → 100644
View file @
961b0b52
# frozen_string_literal: true
module
Resolvers
module
Ci
class
TemplateResolver
<
BaseResolver
type
Types
::
Ci
::
TemplateType
,
null:
true
argument
:name
,
GraphQL
::
STRING_TYPE
,
required:
true
,
description:
'Name of the template to search for.'
alias_method
:project
,
:object
def
resolve
(
name:
nil
)
::
TemplateFinder
.
new
(
:gitlab_ci_ymls
,
project
,
name:
name
).
execute
end
end
end
end
app/graphql/types/ci/template_type.rb
0 → 100644
View file @
961b0b52
# frozen_string_literal: true
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
TemplateType
<
BaseObject
graphql_name
'CiTemplate'
field
:name
,
GraphQL
::
STRING_TYPE
,
null:
false
,
description:
'Name of the CI template.'
field
:content
,
GraphQL
::
STRING_TYPE
,
null:
false
,
description:
'Contents of the CI template.'
end
end
end
app/graphql/types/project_type.rb
View file @
961b0b52
...
...
@@ -337,6 +337,10 @@ module Types
description:
'Pipeline analytics.'
,
resolver:
Resolvers
::
ProjectPipelineStatisticsResolver
field
:ci_template
,
Types
::
Ci
::
TemplateType
,
null:
true
,
description:
'Find a single CI template by name.'
,
resolver:
Resolvers
::
Ci
::
TemplateResolver
def
label
(
title
:)
BatchLoader
::
GraphQL
.
for
(
title
).
batch
(
key:
project
)
do
|
titles
,
loader
,
args
|
LabelsFinder
...
...
spec/graphql/resolvers/ci/template_resolver_spec.rb
0 → 100644
View file @
961b0b52
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
Ci
::
TemplateResolver
do
include
GraphqlHelpers
describe
'#resolve'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
(
:resolve_subject
)
{
resolve
(
described_class
,
obj:
project
,
ctx:
{
current_user:
user
},
args:
{
name:
template_name
})
}
context
'when template exists'
do
let
(
:template_name
)
{
'Android'
}
it
'returns the found template'
do
found_template
=
resolve_subject
expect
(
found_template
).
to
be_an_instance_of
(
Gitlab
::
Template
::
GitlabCiYmlTemplate
)
expect
(
found_template
.
name
).
to
eq
(
'Android'
)
end
end
context
'when template does not exist'
do
let
(
:template_name
)
{
'invalidname'
}
it
'returns nil'
do
expect
(
resolve_subject
).
to
eq
(
nil
)
end
end
end
end
spec/graphql/types/ci/template_type_spec.rb
0 → 100644
View file @
961b0b52
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
Ci
::
TemplateType
do
specify
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'CiTemplate'
)
}
it
'exposes the expected fields'
do
expected_fields
=
%i[
name
content
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
spec/graphql/types/project_type_spec.rb
View file @
961b0b52
...
...
@@ -32,6 +32,7 @@ RSpec.describe GitlabSchema.types['Project'] do
issue_status_counts terraform_states alert_management_integrations
container_repositories container_repositories_count
pipeline_analytics squash_read_only sast_ci_configuration
ci_template
]
expect
(
described_class
).
to
include_graphql_fields
(
*
expected_fields
)
...
...
@@ -379,4 +380,11 @@ RSpec.describe GitlabSchema.types['Project'] do
it
{
is_expected
.
to
have_graphql_type
(
Types
::
Ci
::
JobType
.
connection_type
)
}
it
{
is_expected
.
to
have_graphql_arguments
(
:statuses
)
}
end
describe
'ci_template field'
do
subject
{
described_class
.
fields
[
'ciTemplate'
]
}
it
{
is_expected
.
to
have_graphql_type
(
Types
::
Ci
::
TemplateType
)
}
it
{
is_expected
.
to
have_graphql_arguments
(
:name
)
}
end
end
spec/requests/api/graphql/ci/template_spec.rb
0 → 100644
View file @
961b0b52
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Querying CI template'
do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:query
)
do
<<~
QUERY
{
project(fullPath: "
#{
project
.
full_path
}
") {
name
ciTemplate(name: "
#{
template_name
}
") {
name
content
}
}
}
QUERY
end
before
do
post_graphql
(
query
,
current_user:
user
)
end
context
'when the template exists'
do
let
(
:template_name
)
{
'Android'
}
it_behaves_like
'a working graphql query'
it
'returns correct data'
do
expect
(
graphql_data
.
dig
(
'project'
,
'ciTemplate'
,
'name'
)).
to
eq
(
template_name
)
expect
(
graphql_data
.
dig
(
'project'
,
'ciTemplate'
,
'content'
)).
not_to
be_blank
end
end
context
'when the template does not exist'
do
let
(
:template_name
)
{
'doesnotexist'
}
it_behaves_like
'a working graphql query'
it
'returns correct data'
do
expect
(
graphql_data
.
dig
(
'project'
,
'ciTemplate'
)).
to
eq
(
nil
)
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