Commit 69da6c27 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'lm-add-pipeline-messages-gql' into 'master'

Add PipelineMessageType to GraphQL

See merge request gitlab-org/gitlab!78118
parents f1083234 c271c808
# frozen_string_literal: true
module Types
module Ci
# rubocop: disable Graphql/AuthorizeTypes
class PipelineMessageType < BaseObject
graphql_name 'PipelineMessage'
field :id, GraphQL::Types::ID, null: false,
description: 'ID of the pipeline message.'
field :content, GraphQL::Types::String, null: false,
description: 'Content of the pipeline message.'
end
end
end
......@@ -172,6 +172,9 @@ module Types
description: 'Reference path to the branch from which the pipeline was triggered.',
method: :source_ref_path
field :warning_messages, [Types::Ci::PipelineMessageType], null: true,
description: 'Pipeline warning messages.'
def detailed_status
object.detailed_status(current_user)
end
......
......@@ -13024,6 +13024,7 @@ Represents a file or directory in the project repository that has been locked.
| <a id="pipelineuser"></a>`user` | [`UserCore`](#usercore) | Pipeline user. |
| <a id="pipelineuserpermissions"></a>`userPermissions` | [`PipelinePermissions!`](#pipelinepermissions) | Permissions for the current user on the resource. |
| <a id="pipelineusesneeds"></a>`usesNeeds` | [`Boolean`](#boolean) | Indicates if the pipeline has jobs with `needs` dependencies. |
| <a id="pipelinewarningmessages"></a>`warningMessages` | [`[PipelineMessage!]`](#pipelinemessage) | Pipeline warning messages. |
| <a id="pipelinewarnings"></a>`warnings` | [`Boolean!`](#boolean) | Indicates if a pipeline has warnings. |
#### Fields with arguments
......@@ -13136,6 +13137,15 @@ Represents the Geo sync and verification state of a pipeline artifact.
| <a id="pipelineartifactregistryretrycount"></a>`retryCount` | [`Int`](#int) | Number of consecutive failed sync attempts of the PipelineArtifactRegistry. |
| <a id="pipelineartifactregistrystate"></a>`state` | [`RegistryState`](#registrystate) | Sync state of the PipelineArtifactRegistry. |
### `PipelineMessage`
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="pipelinemessagecontent"></a>`content` | [`String!`](#string) | Content of the pipeline message. |
| <a id="pipelinemessageid"></a>`id` | [`ID!`](#id) | ID of the pipeline message. |
### `PipelinePermissions`
#### Fields
......@@ -143,8 +143,7 @@ module Gitlab
deprecation = entry.deprecation
add_warning(
"`#{entry.key}` is deprecated in " \
"#{deprecation[:deprecated]} and will be removed in #{deprecation[:removed]} " \
"- read more: #{deprecation[:documentation]}"
"#{deprecation[:deprecated]} and will be removed in #{deprecation[:removed]}."
)
end
end
......
# frozen_string_literal: true
FactoryBot.define do
factory :ci_pipeline_message, class: 'Ci::PipelineMessage' do
pipeline factory: :ci_pipeline
content { 'warning' }
severity { 1 }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Ci::PipelineMessageType do
specify { expect(described_class.graphql_name).to eq('PipelineMessage') }
it 'contains attributes related to a pipeline message' do
expected_fields = %w[
id content
]
expect(described_class).to have_graphql_fields(*expected_fields)
end
end
......@@ -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 ref_path
test_report_summary test_suite ref ref_path warning_messages
]
if Gitlab.ee?
......
......@@ -70,7 +70,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do
it 'returns array of types as stages with a warning' do
expect(root.stages_value).to eq %w[test deploy]
expect(root.warnings).to eq(["root `types` is deprecated in 9.0 and will be removed in 15.0 - read more: https://docs.gitlab.com/ee/ci/yaml/#deprecated-keywords"])
expect(root.warnings).to match_array(["root `types` is deprecated in 9.0 and will be removed in 15.0."])
end
it 'logs usage of types keyword' do
......
......@@ -233,7 +233,7 @@ RSpec.describe 'Query.ciConfig' do
it 'returns a warning' do
post_graphql_query
expect(graphql_data['ciConfig']['warnings']).to include('root `types` is deprecated in 9.0 and will be removed in 15.0 - read more: https://docs.gitlab.com/ee/ci/yaml/#deprecated-keywords')
expect(graphql_data['ciConfig']['warnings']).to include('root `types` is deprecated in 9.0 and will be removed in 15.0.')
end
end
......
......@@ -283,6 +283,50 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
end
end
describe 'warningMessages' do
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:warning_message) { create(:ci_pipeline_message, pipeline: pipeline, content: 'warning') }
let(:pipelines_graphql_data) { graphql_data.dig(*%w[project pipelines nodes]).first }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
pipelines {
nodes {
warningMessages {
content
}
}
}
}
}
)
end
it 'returns pipeline warnings' do
post_graphql(query, current_user: user)
expect(pipelines_graphql_data['warningMessages']).to contain_exactly(
a_hash_including('content' => 'warning')
)
end
it 'avoids N+1 queries' do
control_count = ActiveRecord::QueryRecorder.new do
post_graphql(query, current_user: user)
end
pipeline_2 = create(:ci_pipeline, project: project)
create(:ci_pipeline_message, pipeline: pipeline_2, content: 'warning')
expect do
post_graphql(query, current_user: user)
end.not_to exceed_query_limit(control_count)
end
end
describe '.jobs(securityReportTypes)' do
let_it_be(:query) do
%(
......
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