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 @@
module Mutations
module Ci
class PipelineCancel < BaseMutation
class PipelineCancel < Base
graphql_name 'PipelineCancel'
authorize :update_pipeline
def resolve
result = ::Ci::CancelUserPipelinesService.new.execute(current_user)
def resolve(id:)
pipeline = authorized_find!(id: id)
{
success: result.success?,
errors: [result&.message]
}
if pipeline.cancelable?
pipeline.cancel_running
{ success: true, errors: [] }
else
{ success: false, errors: ['Pipeline is not cancelable'] }
end
end
end
end
......
---
title: 'GraphQL: Updates PipelineCancel mutation'
merge_request: 40764
author:
type: changed
......@@ -10656,6 +10656,11 @@ input PipelineCancelInput {
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
The id of the pipeline to mutate
"""
id: CiPipelineID!
}
"""
......
......@@ -31967,6 +31967,20 @@
"description": "Autogenerated input type of PipelineCancel",
"fields": null,
"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",
"description": "A unique identifier for the client performing the mutation.",
......@@ -7,9 +7,14 @@ RSpec.describe 'PipelineCancel' do
let_it_be(:user) { create(:user) }
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) }
......@@ -17,24 +22,25 @@ RSpec.describe 'PipelineCancel' do
project.add_maintainer(user)
end
it 'reports the service-level error' do
service = double(execute: ServiceResponse.error(message: 'Error canceling pipeline'))
allow(::Ci::CancelUserPipelinesService).to receive(:new).and_return(service)
it 'does not cancel any pipelines not owned by the current user' do
build = create(:ci_build, :running, pipeline: pipeline)
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
it 'does not change any pipelines not owned by the current user' do
build = create(:ci_build, :running, pipeline: pipeline)
it 'returns a error if the pipline cannot be be canceled' do
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
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)
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