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
7423a9dd
Commit
7423a9dd
authored
Feb 17, 2021
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes pipeline be searchable by sha or iid
* Updates project_pipeline resolver
parent
898748a3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
10 deletions
+67
-10
app/graphql/resolvers/project_pipeline_resolver.rb
app/graphql/resolvers/project_pipeline_resolver.rb
+25
-5
app/graphql/types/ci/pipeline_type.rb
app/graphql/types/ci/pipeline_type.rb
+7
-0
changelogs/unreleased/lm-add-short-sha-and-path-to-pipeline.yml
...logs/unreleased/lm-add-short-sha-and-path-to-pipeline.yml
+5
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
+28
-4
spec/graphql/types/ci/pipeline_type_spec.rb
spec/graphql/types/ci/pipeline_type_spec.rb
+1
-1
No files found.
app/graphql/resolvers/project_pipeline_resolver.rb
View file @
7423a9dd
...
...
@@ -7,14 +7,34 @@ module Resolvers
alias_method
:project
,
:object
argument
:iid
,
GraphQL
::
ID_TYPE
,
required:
tru
e
,
required:
fals
e
,
description:
'IID of the Pipeline, e.g., "1".'
def
resolve
(
iid
:)
BatchLoader
::
GraphQL
.
for
(
iid
).
batch
(
key:
project
)
do
|
iids
,
loader
,
args
|
finder
=
::
Ci
::
PipelinesFinder
.
new
(
project
,
context
[
:current_user
],
iids:
iids
)
argument
:sha
,
GraphQL
::
STRING_TYPE
,
required:
false
,
description:
'Sha of the Pipeline, e.g., ""dyd0f15ay83993f5ab66k927w28673882x99100b".'
finder
.
execute
.
each
{
|
pipeline
|
loader
.
call
(
pipeline
.
iid
.
to_s
,
pipeline
)
}
def
ready?
(
iid:
nil
,
sha:
nil
)
unless
iid
.
present?
^
sha
.
present?
raise
Gitlab
::
Graphql
::
Errors
::
ArgumentError
,
'Provide either an iid or sha'
end
super
end
def
resolve
(
iid:
nil
,
sha:
nil
)
if
iid
BatchLoader
::
GraphQL
.
for
(
iid
).
batch
(
key:
project
)
do
|
iids
,
loader
,
args
|
finder
=
::
Ci
::
PipelinesFinder
.
new
(
project
,
context
[
:current_user
],
iids:
iids
)
finder
.
execute
.
each
{
|
pipeline
|
loader
.
call
(
pipeline
.
iid
.
to_s
,
pipeline
)
}
end
else
BatchLoader
::
GraphQL
.
for
(
sha
).
batch
(
key:
project
)
do
|
shas
,
loader
,
args
|
finder
=
::
Ci
::
PipelinesFinder
.
new
(
project
,
context
[
:current_user
],
shas:
sha
)
finder
.
execute
.
each
{
|
pipeline
|
loader
.
call
(
pipeline
.
sha
.
to_s
,
pipeline
)
}
end
end
end
end
...
...
app/graphql/types/ci/pipeline_type.rb
View file @
7423a9dd
...
...
@@ -95,6 +95,9 @@ module Types
field
:path
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
"Relative path to the pipeline's page."
field
:commit_path
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Relative path to the'
field
:project
,
Types
::
ProjectType
,
null:
true
,
description:
'Project the pipeline belongs to.'
...
...
@@ -109,6 +112,10 @@ module Types
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
User
,
object
.
user_id
).
find
end
def
commit_path
::
Gitlab
::
Routing
.
url_helpers
.
project_commit_path
(
object
.
project
,
object
.
sha
)
end
def
path
::
Gitlab
::
Routing
.
url_helpers
.
project_pipeline_path
(
object
.
project
,
object
)
end
...
...
changelogs/unreleased/lm-add-short-sha-and-path-to-pipeline.yml
0 → 100644
View file @
7423a9dd
---
title
:
Updates ProjectPipelineResolver to use sha or iid
merge_request
:
54471
author
:
type
:
changed
doc/api/graphql/reference/index.md
View file @
7423a9dd
...
...
@@ -3172,6 +3172,7 @@ Information about pagination in a connection.
|
`active`
| Boolean! | Indicates if the pipeline is active. |
|
`beforeSha`
| String | Base SHA of the source branch. |
|
`cancelable`
| Boolean! | Specifies if a pipeline can be canceled. |
|
`commitPath`
| String | Relative path to the |
|
`committedAt`
| Time | Timestamp of the pipeline's commit. |
|
`configSource`
| PipelineConfigSourceEnum | Configuration source of the pipeline (UNKNOWN_SOURCE, REPOSITORY_SOURCE, AUTO_DEVOPS_SOURCE, WEBIDE_SOURCE, REMOTE_SOURCE, EXTERNAL_PROJECT_SOURCE, BRIDGE_SOURCE, PARAMETER_SOURCE, COMPLIANCE_SOURCE) |
|
`coverage`
| Float | Coverage percentage. |
...
...
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
View file @
7423a9dd
...
...
@@ -6,7 +6,7 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
iid:
'1234'
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
iid:
'1234'
,
sha:
'sha'
)
}
let_it_be
(
:other_pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:current_user
)
{
create
(
:user
)
}
...
...
@@ -30,7 +30,15 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
expect
(
result
).
to
eq
(
pipeline
)
end
it
'keeps the queries under the threshold'
do
it
'resolves pipeline for the passed sha'
do
result
=
batch_sync
do
resolve_pipeline
(
project
,
{
sha:
'sha'
})
end
expect
(
result
).
to
eq
(
pipeline
)
end
it
'keeps the queries under the threshold for iid'
do
create
(
:ci_pipeline
,
project:
project
,
iid:
'1235'
)
control
=
ActiveRecord
::
QueryRecorder
.
new
do
...
...
@@ -45,6 +53,21 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
end
.
not_to
exceed_query_limit
(
control
)
end
it
'keeps the queries under the threshold for sha'
do
create
(
:ci_pipeline
,
project:
project
,
sha:
'sha'
)
control
=
ActiveRecord
::
QueryRecorder
.
new
do
batch_sync
{
resolve_pipeline
(
project
,
{
sha:
'sha'
})
}
end
expect
do
batch_sync
do
resolve_pipeline
(
project
,
{
sha:
'sha'
})
resolve_pipeline
(
project
,
{
sha:
'sha2'
})
end
end
.
not_to
exceed_query_limit
(
control
)
end
it
'does not resolve a pipeline outside the project'
do
result
=
batch_sync
do
resolve_pipeline
(
other_pipeline
.
project
,
{
iid:
'1234'
})
...
...
@@ -53,8 +76,9 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
expect
(
result
).
to
be_nil
end
it
'errors when no iid is passed'
do
expect
{
resolve_pipeline
(
project
,
{})
}.
to
raise_error
(
ArgumentError
)
it
'errors when no iid or sha is passed'
do
expect
{
resolve_pipeline
(
project
,
{})
}
.
to
raise_error
(
Gitlab
::
Graphql
::
Errors
::
ArgumentError
)
end
context
'when the pipeline is a dangling pipeline'
do
...
...
spec/graphql/types/ci/pipeline_type_spec.rb
View file @
7423a9dd
...
...
@@ -12,7 +12,7 @@ RSpec.describe Types::Ci::PipelineType do
id iid sha before_sha status detailed_status config_source duration
coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job downstream
upstream path project active user_permissions warnings
upstream path project active user_permissions warnings
commit_path
]
if
Gitlab
.
ee?
...
...
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