diff options
Diffstat (limited to 'app/graphql/mutations/ci/pipeline')
-rw-r--r-- | app/graphql/mutations/ci/pipeline/base.rb | 24 | ||||
-rw-r--r-- | app/graphql/mutations/ci/pipeline/cancel.rb | 24 | ||||
-rw-r--r-- | app/graphql/mutations/ci/pipeline/destroy.rb | 24 | ||||
-rw-r--r-- | app/graphql/mutations/ci/pipeline/retry.rb | 29 |
4 files changed, 101 insertions, 0 deletions
diff --git a/app/graphql/mutations/ci/pipeline/base.rb b/app/graphql/mutations/ci/pipeline/base.rb new file mode 100644 index 00000000000..ebfab56e743 --- /dev/null +++ b/app/graphql/mutations/ci/pipeline/base.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Pipeline + class Base < BaseMutation + PipelineID = ::Types::GlobalIDType[::Ci::Pipeline] + + argument :id, PipelineID, + required: true, + description: 'The ID of the pipeline to mutate.' + + private + + def find_object(id:) + # TODO: remove this line when the compatibility layer is removed + # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 + id = PipelineID.coerce_isolated_input(id) + GlobalID::Locator.locate(id) + end + end + end + end +end diff --git a/app/graphql/mutations/ci/pipeline/cancel.rb b/app/graphql/mutations/ci/pipeline/cancel.rb new file mode 100644 index 00000000000..3fb34a37cfc --- /dev/null +++ b/app/graphql/mutations/ci/pipeline/cancel.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Pipeline + class Cancel < Base + graphql_name 'PipelineCancel' + + authorize :update_pipeline + + def resolve(id:) + pipeline = authorized_find!(id: id) + + if pipeline.cancelable? + pipeline.cancel_running + { success: true, errors: [] } + else + { success: false, errors: ['Pipeline is not cancelable'] } + end + end + end + end + end +end diff --git a/app/graphql/mutations/ci/pipeline/destroy.rb b/app/graphql/mutations/ci/pipeline/destroy.rb new file mode 100644 index 00000000000..3f933818ce1 --- /dev/null +++ b/app/graphql/mutations/ci/pipeline/destroy.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Pipeline + class Destroy < Base + graphql_name 'PipelineDestroy' + + authorize :destroy_pipeline + + def resolve(id:) + pipeline = authorized_find!(id: id) + project = pipeline.project + + result = ::Ci::DestroyPipelineService.new(project, current_user).execute(pipeline) + { + success: result.success?, + errors: result.errors + } + end + end + end + end +end diff --git a/app/graphql/mutations/ci/pipeline/retry.rb b/app/graphql/mutations/ci/pipeline/retry.rb new file mode 100644 index 00000000000..a12330470f0 --- /dev/null +++ b/app/graphql/mutations/ci/pipeline/retry.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module Pipeline + class Retry < Base + graphql_name 'PipelineRetry' + + field :pipeline, + Types::Ci::PipelineType, + null: true, + description: 'The pipeline after mutation.' + + authorize :update_pipeline + + def resolve(id:) + pipeline = authorized_find!(id: id) + project = pipeline.project + + ::Ci::RetryPipelineService.new(project, current_user).execute(pipeline) + { + pipeline: pipeline, + errors: errors_on_object(pipeline) + } + end + end + end + end +end |