Commit f1cb789d authored by Cong Chen's avatar Cong Chen Committed by Alex Kalderimis

Add `ref_path` to PipelineType

Changelog: added
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72591
parent ef987699
......@@ -18,8 +18,14 @@ module Types
field :iid, GraphQL::Types::String, null: false,
description: 'Internal ID of the pipeline.'
field :sha, GraphQL::Types::String, null: false,
description: "SHA of the pipeline's commit."
field :sha, GraphQL::Types::String, null: true,
method: :sha,
description: "SHA of the pipeline's commit." do
argument :format,
type: Types::ShaFormatEnum,
required: false,
description: 'Format of the SHA.'
end
field :before_sha, GraphQL::Types::String, null: true,
description: 'Base SHA of the source branch.'
......@@ -162,6 +168,10 @@ module Types
field :ref, GraphQL::Types::String, null: true,
description: 'Reference to the branch from which the pipeline was triggered.'
field :ref_path, GraphQL::Types::String, null: true,
description: 'Reference path to the branch from which the pipeline was triggered.',
method: :source_ref_path
def detailed_status
object.detailed_status(current_user)
end
......@@ -189,6 +199,12 @@ module Types
end.take # rubocop: disable CodeReuse/ActiveRecord
end
def sha(format: Types::ShaFormatEnum.enum[:long])
return pipeline.short_sha if format == Types::ShaFormatEnum.enum[:short]
pipeline.sha
end
alias_method :pipeline, :object
end
end
......
# frozen_string_literal: true
module Types
class ShaFormatEnum < BaseEnum
graphql_name 'ShaFormat'
description 'How to format SHA strings.'
FORMATS_DESCRIPTION = {
short: 'Abbreviated format. Short SHAs are typically eight characters long.',
long: 'Unabbreviated format.'
}.freeze
FORMATS_DESCRIPTION.each do |format, description|
value format.to_s.upcase,
description: description,
value: format.to_s
end
end
end
......@@ -12833,9 +12833,9 @@ Represents a file or directory in the project repository that has been locked.
| <a id="pipelineproject"></a>`project` | [`Project`](#project) | Project the pipeline belongs to. |
| <a id="pipelinequeuedduration"></a>`queuedDuration` | [`Duration`](#duration) | How long the pipeline was queued before starting. |
| <a id="pipelineref"></a>`ref` | [`String`](#string) | Reference to the branch from which the pipeline was triggered. |
| <a id="pipelinerefpath"></a>`refPath` | [`String`](#string) | Reference path to the branch from which the pipeline was triggered. |
| <a id="pipelineretryable"></a>`retryable` | [`Boolean!`](#boolean) | Specifies if a pipeline can be retried. |
| <a id="pipelinesecurityreportsummary"></a>`securityReportSummary` | [`SecurityReportSummary`](#securityreportsummary) | Vulnerability and scanned resource counts for each security scanner of the pipeline. |
| <a id="pipelinesha"></a>`sha` | [`String!`](#string) | SHA of the pipeline's commit. |
| <a id="pipelinesourcejob"></a>`sourceJob` | [`CiJob`](#cijob) | Job where pipeline was triggered from. |
| <a id="pipelinestages"></a>`stages` | [`CiStageConnection`](#cistageconnection) | Stages of the pipeline. (see [Connections](#connections)) |
| <a id="pipelinestartedat"></a>`startedAt` | [`Time`](#time) | Timestamp when the pipeline was started. |
......@@ -12899,6 +12899,18 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="pipelinesecurityreportfindingsseverity"></a>`severity` | [`[String!]`](#string) | Filter vulnerability findings by severity. |
| <a id="pipelinesecurityreportfindingsstate"></a>`state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerability findings by state. |
##### `Pipeline.sha`
SHA of the pipeline's commit.
Returns [`String`](#string).
###### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="pipelineshaformat"></a>`format` | [`ShaFormat`](#shaformat) | Format of the SHA. |
##### `Pipeline.testSuite`
A specific test suite in a pipeline test report.
......@@ -17233,6 +17245,15 @@ State of a Sentry error.
| <a id="servicetypeyoutrack_service"></a>`YOUTRACK_SERVICE` | YoutrackService type. |
| <a id="servicetypezentao_service"></a>`ZENTAO_SERVICE` | ZentaoService type. |
### `ShaFormat`
How to format SHA strings.
| Value | Description |
| ----- | ----------- |
| <a id="shaformatlong"></a>`LONG` | Unabbreviated format. |
| <a id="shaformatshort"></a>`SHORT` | Abbreviated format. Short SHAs are typically eight characters long. |
### `SharedRunnersSetting`
| Value | Description |
......@@ -14,7 +14,7 @@ RSpec.describe Types::Ci::PipelineType do
coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job job job_artifacts downstream
upstream path project active user_permissions warnings commit commit_path uses_needs
test_report_summary test_suite ref
test_report_summary test_suite ref ref_path
]
if Gitlab.ee?
......
......@@ -12,6 +12,38 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
travel_to(Time.current) { example.run }
end
describe 'sha' do
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let(:pipelines_graphql_data) { graphql_data.dig(*%w[project pipelines nodes]).first }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines {
nodes {
fullSha: sha
shortSha: sha(format: SHORT)
alsoFull: sha(format: LONG)
}
}
}
}
)
end
it 'returns all formats of the SHA' do
post_graphql(query, current_user: user)
expect(pipelines_graphql_data).to include(
'fullSha' => eq(pipeline.sha),
'alsoFull' => eq(pipeline.sha),
'shortSha' => eq(pipeline.short_sha)
)
end
end
describe 'duration fields' do
let_it_be(:pipeline) do
create(:ci_pipeline, project: project)
......@@ -420,4 +452,36 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end
end
end
describe 'ref_path' do
let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let_it_be(:pipeline_1) { create(:ci_pipeline, project: project, user: user, merge_request: merge_request) }
let_it_be(:pipeline_2) { create(:ci_pipeline, project: project, user: user, merge_request: merge_request) }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines {
nodes {
refPath
}
}
}
}
)
end
it 'avoids N+1 queries' do
control_count = ActiveRecord::QueryRecorder.new do
post_graphql(query, current_user: user)
end
create(:ci_pipeline, project: project, user: user, merge_request: merge_request)
expect do
post_graphql(query, current_user: user)
end.not_to exceed_query_limit(control_count)
end
end
end
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