Commit fc73d77c authored by lauraMon's avatar lauraMon

Adds retryPipeline mutation

* First unrefactored spec
parent a0efb830
# frozen_string_literal: true
module Mutations
module Ci
class Base < BaseMutation
argument :id, GraphQL::ID_TYPE,
required: true,
description: 'The id of the pipeline to mutate'
field :pipeline,
Types::Ci::PipelineType,
null: true,
description: 'The pipeline after mutation'
authorize :update_pipeline
private
def find_object(id:)
::Ci::Pipeline.find(id)
end
end
end
end
# frozen_string_literal: true
module Mutations
module Ci
class PipelineRetry < Base
graphql_name 'PipelineRetry'
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
......@@ -62,6 +62,7 @@ module Types
mount_mutation Mutations::DesignManagement::Delete, calls_gitaly: true
mount_mutation Mutations::DesignManagement::Move
mount_mutation Mutations::ContainerExpirationPolicies::Update
mount_mutation Mutations::Ci::PipelineRetry
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineCancel' do
include GraphqlHelpers
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:mutation) do
variables = {
id: pipeline.id
}
graphql_mutation(:pipeline_retry, variables,
<<-QL
errors
pipeline {
id
}
QL
)
end
let(:mutation_response) { graphql_mutation_response(:pipeline_cancel) }
before do
project.add_maintainer(user)
end
it 'returns an error if the user is not allowed to retry the pipeline' do
post_graphql_mutation(mutation, current_user: create(:user))
expect(graphql_errors).not_to be_empty
end
it 'retries a pipeline' do
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['pipeline']['id']).to include(pipeline.id.to_s)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'PipelineRetry' do
include GraphqlHelpers
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:mutation) do
variables = {
id: pipeline.id
}
graphql_mutation(:pipeline_retry, variables,
<<-QL
errors
pipeline {
id
}
QL
)
end
let(:mutation_response) { graphql_mutation_response(:pipeline_retry) }
before do
project.add_maintainer(user)
end
it 'returns an error if the user is not allowed to retry the pipeline' do
post_graphql_mutation(mutation, current_user: create(:user))
expect(graphql_errors).not_to be_empty
end
it 'retries a pipeline' do
pipeline_id = ::Gitlab::GlobalId.build(pipeline, id: pipeline.id).to_s
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['pipeline']['id']).to eq(pipeline_id)
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