Commit 7423a9dd authored by lauraMon's avatar lauraMon

Makes pipeline be searchable by sha or iid

* Updates project_pipeline resolver
parent 898748a3
......@@ -7,14 +7,34 @@ module Resolvers
alias_method :project, :object
argument :iid, GraphQL::ID_TYPE,
required: true,
required: false,
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
......
......@@ -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
......
---
title: Updates ProjectPipelineResolver to use sha or iid
merge_request: 54471
author:
type: changed
......@@ -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. |
......
......@@ -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
......
......@@ -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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment