Commit 91c01cbf authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'lm-update-pipeline-mutation' into 'master'

GraphQL: Updates cancel pipeline mutation

See merge request gitlab-org/gitlab!40764
parents 9bbf16fe 50e1a148
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
module Mutations module Mutations
module Ci module Ci
class PipelineCancel < BaseMutation class PipelineCancel < Base
graphql_name 'PipelineCancel' graphql_name 'PipelineCancel'
authorize :update_pipeline authorize :update_pipeline
def resolve def resolve(id:)
result = ::Ci::CancelUserPipelinesService.new.execute(current_user) pipeline = authorized_find!(id: id)
{ if pipeline.cancelable?
success: result.success?, pipeline.cancel_running
errors: [result&.message] { success: true, errors: [] }
} else
{ success: false, errors: ['Pipeline is not cancelable'] }
end
end end
end end
end end
......
---
title: 'GraphQL: Updates PipelineCancel mutation'
merge_request: 40764
author:
type: changed
...@@ -10656,6 +10656,11 @@ input PipelineCancelInput { ...@@ -10656,6 +10656,11 @@ input PipelineCancelInput {
A unique identifier for the client performing the mutation. A unique identifier for the client performing the mutation.
""" """
clientMutationId: String clientMutationId: String
"""
The id of the pipeline to mutate
"""
id: CiPipelineID!
} }
""" """
......
...@@ -31967,6 +31967,20 @@ ...@@ -31967,6 +31967,20 @@
"description": "Autogenerated input type of PipelineCancel", "description": "Autogenerated input type of PipelineCancel",
"fields": null, "fields": null,
"inputFields": [ "inputFields": [
{
"name": "id",
"description": "The id of the pipeline to mutate",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "CiPipelineID",
"ofType": null
}
},
"defaultValue": null
},
{ {
"name": "clientMutationId", "name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.", "description": "A unique identifier for the client performing the mutation.",
...@@ -7,9 +7,14 @@ RSpec.describe 'PipelineCancel' do ...@@ -7,9 +7,14 @@ RSpec.describe 'PipelineCancel' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, :running, project: project, user: user) } let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:mutation) { graphql_mutation(:pipeline_cancel, {}, 'errors') } let(:mutation) do
variables = {
id: pipeline.to_global_id.to_s
}
graphql_mutation(:pipeline_cancel, variables, 'errors')
end
let(:mutation_response) { graphql_mutation_response(:pipeline_cancel) } let(:mutation_response) { graphql_mutation_response(:pipeline_cancel) }
...@@ -17,24 +22,25 @@ RSpec.describe 'PipelineCancel' do ...@@ -17,24 +22,25 @@ RSpec.describe 'PipelineCancel' do
project.add_maintainer(user) project.add_maintainer(user)
end end
it 'reports the service-level error' do it 'does not cancel any pipelines not owned by the current user' do
service = double(execute: ServiceResponse.error(message: 'Error canceling pipeline')) build = create(:ci_build, :running, pipeline: pipeline)
allow(::Ci::CancelUserPipelinesService).to receive(:new).and_return(service)
post_graphql_mutation(mutation, current_user: create(:user)) post_graphql_mutation(mutation, current_user: create(:user))
expect(mutation_response).to include('errors' => ['Error canceling pipeline']) expect(graphql_errors).not_to be_empty
expect(build).not_to be_canceled
end end
it 'does not change any pipelines not owned by the current user' do it 'returns a error if the pipline cannot be be canceled' do
build = create(:ci_build, :running, pipeline: pipeline) build = create(:ci_build, :success, pipeline: pipeline)
post_graphql_mutation(mutation, current_user: create(:user)) post_graphql_mutation(mutation, current_user: user)
expect(mutation_response).to include('errors' => include(eq 'Pipeline is not cancelable'))
expect(build).not_to be_canceled expect(build).not_to be_canceled
end end
it "cancels all of the current user's cancelable pipelines" do it "cancels all cancelable builds from a pipeline" do
build = create(:ci_build, :running, pipeline: pipeline) build = create(:ci_build, :running, pipeline: pipeline)
post_graphql_mutation(mutation, current_user: user) post_graphql_mutation(mutation, current_user: user)
......
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