diff options
Diffstat (limited to 'app/graphql/mutations/ci/pipeline_schedule')
3 files changed, 123 insertions, 0 deletions
diff --git a/app/graphql/mutations/ci/pipeline_schedule/create.rb b/app/graphql/mutations/ci/pipeline_schedule/create.rb new file mode 100644 index 00000000000..65b355cd80f --- /dev/null +++ b/app/graphql/mutations/ci/pipeline_schedule/create.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module PipelineSchedule + class Create < BaseMutation + graphql_name 'PipelineScheduleCreate' + + include FindsProject + + authorize :create_pipeline_schedule + + argument :project_path, GraphQL::Types::ID, + required: true, + description: 'Full path of the project the pipeline schedule is associated with.' + + argument :description, GraphQL::Types::String, + required: true, + description: 'Description of the pipeline schedule.' + + argument :cron, GraphQL::Types::String, + required: true, + description: 'Cron expression of the pipeline schedule.' + + argument :cron_timezone, GraphQL::Types::String, + required: false, + description: + <<-STR + Cron time zone supported by ActiveSupport::TimeZone. + For example: "Pacific Time (US & Canada)" (default: "UTC"). + STR + + argument :ref, GraphQL::Types::String, + required: true, + description: 'Ref of the pipeline schedule.' + + argument :active, GraphQL::Types::Boolean, + required: false, + description: 'Indicates if the pipeline schedule should be active or not.' + + argument :variables, [Mutations::Ci::PipelineSchedule::VariableInputType], + required: false, + description: 'Variables for the pipeline schedule.' + + field :pipeline_schedule, + Types::Ci::PipelineScheduleType, + description: 'Created pipeline schedule.' + + def resolve(project_path:, variables: [], **pipeline_schedule_attrs) + project = authorized_find!(project_path) + + params = pipeline_schedule_attrs.merge(variables_attributes: variables.map(&:to_h)) + + schedule = ::Ci::CreatePipelineScheduleService + .new(project, current_user, params) + .execute + + unless schedule.persisted? + return { + pipeline_schedule: nil, errors: schedule.errors.full_messages + } + end + + { + pipeline_schedule: schedule, + errors: [] + } + end + end + end + end +end diff --git a/app/graphql/mutations/ci/pipeline_schedule/play.rb b/app/graphql/mutations/ci/pipeline_schedule/play.rb new file mode 100644 index 00000000000..056890852c9 --- /dev/null +++ b/app/graphql/mutations/ci/pipeline_schedule/play.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module PipelineSchedule + class Play < Base + graphql_name 'PipelineSchedulePlay' + + authorize :play_pipeline_schedule + + field :pipeline_schedule, + Types::Ci::PipelineScheduleType, + null: true, + description: 'Pipeline schedule after mutation.' + + def resolve(id:) + schedule = authorized_find!(id: id) + + job_id = ::Ci::PipelineScheduleService + .new(schedule.project, current_user) + .execute(schedule) + + if job_id + { pipeline_schedule: schedule, errors: [] } + else + { pipeline_schedule: nil, errors: ['Unable to schedule a pipeline to run immediately.'] } + end + end + end + end + end +end diff --git a/app/graphql/mutations/ci/pipeline_schedule/variable_input_type.rb b/app/graphql/mutations/ci/pipeline_schedule/variable_input_type.rb new file mode 100644 index 00000000000..54a6ad92448 --- /dev/null +++ b/app/graphql/mutations/ci/pipeline_schedule/variable_input_type.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Mutations + module Ci + module PipelineSchedule + class VariableInputType < Types::BaseInputObject + graphql_name 'PipelineScheduleVariableInput' + + description 'Attributes for the pipeline schedule variable.' + + argument :key, GraphQL::Types::String, required: true, description: 'Name of the variable.' + + argument :value, GraphQL::Types::String, required: true, description: 'Value of the variable.' + + argument :variable_type, Types::Ci::VariableTypeEnum, required: true, description: 'Type of the variable.' + end + end + end +end |