Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create.rb « pipeline_schedule « ci « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d21ac6fd7279b9b3cec9d14b77abdc1a9803a3e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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))

          response = ::Ci::PipelineSchedules::CreateService
                        .new(project, current_user, params)
                        .execute

          schedule = response.payload

          unless response.success?
            return {
              pipeline_schedule: nil, errors: response.errors
            }
          end

          {
            pipeline_schedule: schedule,
            errors: []
          }
        end
      end
    end
  end
end