Commit 1dae49eb authored by Michael Kozono's avatar Michael Kozono

Merge branch 'jivanvl-add-ci-mutations-cancel-unschedule' into 'master'

Add missing Ci::Build graphql mutations

See merge request gitlab-org/gitlab!68399
parents 0cdbca1d b0389d7d
# frozen_string_literal: true
module Mutations
module Ci
module Job
class Cancel < Base
graphql_name 'JobCancel'
field :job,
Types::Ci::JobType,
null: true,
description: 'Job after the mutation.'
authorize :update_build
def resolve(id:)
job = authorized_find!(id: id)
::Ci::BuildCancelService.new(job, current_user).execute
{
job: job,
errors: errors_on_object(job)
}
end
end
end
end
end
# frozen_string_literal: true
module Mutations
module Ci
module Job
class Unschedule < Base
graphql_name 'JobUnschedule'
field :job,
Types::Ci::JobType,
null: true,
description: 'Job after the mutation.'
authorize :update_build
def resolve(id:)
job = authorized_find!(id: id)
::Ci::BuildUnscheduleService.new(job, current_user).execute
{
job: job,
errors: errors_on_object(job)
}
end
end
end
end
end
......@@ -99,6 +99,8 @@ module Types
mount_mutation Mutations::Ci::CiCdSettingsUpdate
mount_mutation Mutations::Ci::Job::Play
mount_mutation Mutations::Ci::Job::Retry
mount_mutation Mutations::Ci::Job::Cancel
mount_mutation Mutations::Ci::Job::Unschedule
mount_mutation Mutations::Ci::JobTokenScope::AddProject
mount_mutation Mutations::Ci::JobTokenScope::RemoveProject
mount_mutation Mutations::Ci::Runner::Update, feature_flag: :runner_graphql_query
......
......@@ -2882,6 +2882,25 @@ Input type: `JiraImportUsersInput`
| <a id="mutationjiraimportuserserrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationjiraimportusersjirausers"></a>`jiraUsers` | [`[JiraUser!]`](#jirauser) | Users returned from Jira, matched by email and name if possible. |
### `Mutation.jobCancel`
Input type: `JobCancelInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationjobcancelclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationjobcancelid"></a>`id` | [`CiBuildID!`](#cibuildid) | ID of the job to mutate. |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationjobcancelclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationjobcancelerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationjobcanceljob"></a>`job` | [`CiJob`](#cijob) | Job after the mutation. |
### `Mutation.jobPlay`
Input type: `JobPlayInput`
......@@ -2920,6 +2939,25 @@ Input type: `JobRetryInput`
| <a id="mutationjobretryerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationjobretryjob"></a>`job` | [`CiJob`](#cijob) | Job after the mutation. |
### `Mutation.jobUnschedule`
Input type: `JobUnscheduleInput`
#### Arguments
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationjobunscheduleclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationjobunscheduleid"></a>`id` | [`CiBuildID!`](#cibuildid) | ID of the job to mutate. |
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="mutationjobunscheduleclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationjobunscheduleerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
| <a id="mutationjobunschedulejob"></a>`job` | [`CiJob`](#cijob) | Job after the mutation. |
### `Mutation.labelCreate`
Input type: `LabelCreateInput`
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe "JobCancel" do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let_it_be(:job) { create(:ci_build, pipeline: pipeline, name: 'build') }
let(:mutation) do
variables = {
id: job.to_global_id.to_s
}
graphql_mutation(:job_cancel, variables,
<<-QL
errors
job {
id
}
QL
)
end
let(:mutation_response) { graphql_mutation_response(:job_cancel) }
it 'returns an error if the user is not allowed to cancel the job' do
project.add_developer(user)
post_graphql_mutation(mutation, current_user: user)
expect(graphql_errors).not_to be_empty
end
it 'cancels a job' do
job_id = ::Gitlab::GlobalId.build(job, id: job.id).to_s
project.add_maintainer(user)
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['job']['id']).to eq(job_id)
expect(job.reload.status).to eq('canceled')
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'JobUnschedule' do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let_it_be(:job) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'build') }
let(:mutation) do
variables = {
id: job.to_global_id.to_s
}
graphql_mutation(:job_unschedule, variables,
<<-QL
errors
job {
id
}
QL
)
end
let(:mutation_response) { graphql_mutation_response(:job_unschedule) }
it 'returns an error if the user is not allowed to unschedule the job' do
project.add_developer(user)
post_graphql_mutation(mutation, current_user: user)
expect(graphql_errors).not_to be_empty
expect(job.reload.status).to eq('scheduled')
end
it 'unschedules a job' do
project.add_maintainer(user)
job_id = ::Gitlab::GlobalId.build(job, id: job.id).to_s
post_graphql_mutation(mutation, current_user: user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['job']['id']).to eq(job_id)
expect(job.reload.status).to eq('manual')
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