Commit 8514a0e3 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'add-short_sha-to-pipeline-type' into 'master'

Add `short_sha` and `ref_path` to `PipelineType` (GraphQL)

See merge request gitlab-org/gitlab!72591
parents 23b81f0a f1cb789d
...@@ -18,8 +18,14 @@ module Types ...@@ -18,8 +18,14 @@ module Types
field :iid, GraphQL::Types::String, null: false, field :iid, GraphQL::Types::String, null: false,
description: 'Internal ID of the pipeline.' description: 'Internal ID of the pipeline.'
field :sha, GraphQL::Types::String, null: false, field :sha, GraphQL::Types::String, null: true,
description: "SHA of the pipeline's commit." 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, field :before_sha, GraphQL::Types::String, null: true,
description: 'Base SHA of the source branch.' description: 'Base SHA of the source branch.'
...@@ -162,6 +168,10 @@ module Types ...@@ -162,6 +168,10 @@ module Types
field :ref, GraphQL::Types::String, null: true, field :ref, GraphQL::Types::String, null: true,
description: 'Reference to the branch from which the pipeline was triggered.' 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 def detailed_status
object.detailed_status(current_user) object.detailed_status(current_user)
end end
...@@ -189,6 +199,12 @@ module Types ...@@ -189,6 +199,12 @@ module Types
end.take # rubocop: disable CodeReuse/ActiveRecord end.take # rubocop: disable CodeReuse/ActiveRecord
end 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 alias_method :pipeline, :object
end end
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
...@@ -12857,9 +12857,9 @@ Represents a file or directory in the project repository that has been locked. ...@@ -12857,9 +12857,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="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="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="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="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="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="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="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. | | <a id="pipelinestartedat"></a>`startedAt` | [`Time`](#time) | Timestamp when the pipeline was started. |
...@@ -12923,6 +12923,18 @@ four standard [pagination arguments](#connection-pagination-arguments): ...@@ -12923,6 +12923,18 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="pipelinesecurityreportfindingsseverity"></a>`severity` | [`[String!]`](#string) | Filter vulnerability findings by severity. | | <a id="pipelinesecurityreportfindingsseverity"></a>`severity` | [`[String!]`](#string) | Filter vulnerability findings by severity. |
| <a id="pipelinesecurityreportfindingsstate"></a>`state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerability findings by state. | | <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` ##### `Pipeline.testSuite`
A specific test suite in a pipeline test report. A specific test suite in a pipeline test report.
...@@ -17267,6 +17279,15 @@ State of a Sentry error. ...@@ -17267,6 +17279,15 @@ State of a Sentry error.
| <a id="servicetypeyoutrack_service"></a>`YOUTRACK_SERVICE` | YoutrackService type. | | <a id="servicetypeyoutrack_service"></a>`YOUTRACK_SERVICE` | YoutrackService type. |
| <a id="servicetypezentao_service"></a>`ZENTAO_SERVICE` | ZentaoService 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` ### `SharedRunnersSetting`
| Value | Description | | Value | Description |
...@@ -14,7 +14,7 @@ RSpec.describe Types::Ci::PipelineType do ...@@ -14,7 +14,7 @@ RSpec.describe Types::Ci::PipelineType do
coverage created_at updated_at started_at finished_at committed_at coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job job job_artifacts downstream stages user retryable cancelable jobs source_job job job_artifacts downstream
upstream path project active user_permissions warnings commit commit_path uses_needs 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? if Gitlab.ee?
......
...@@ -12,6 +12,38 @@ RSpec.describe 'Query.project(fullPath).pipelines' do ...@@ -12,6 +12,38 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
travel_to(Time.current) { example.run } travel_to(Time.current) { example.run }
end 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 describe 'duration fields' do
let_it_be(:pipeline) do let_it_be(:pipeline) do
create(:ci_pipeline, project: project) create(:ci_pipeline, project: project)
...@@ -420,4 +452,36 @@ RSpec.describe 'Query.project(fullPath).pipelines' do ...@@ -420,4 +452,36 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end end
end 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 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