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

update.rb « merge_requests « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: da4db7342a39171f8b949302ce3deec054c485e2 (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
# frozen_string_literal: true

module Mutations
  module MergeRequests
    class Update < Base
      graphql_name 'MergeRequestUpdate'

      description 'Update attributes of a merge request'

      argument :title, GraphQL::Types::String,
               required: false,
               description: copy_field_description(Types::MergeRequestType, :title)

      argument :target_branch, GraphQL::Types::String,
               required: false,
               description: copy_field_description(Types::MergeRequestType, :target_branch)

      argument :description, GraphQL::Types::String,
               required: false,
               description: copy_field_description(Types::MergeRequestType, :description)

      argument :state, ::Types::MergeRequestStateEventEnum,
               required: false,
               as: :state_event,
               description: 'Action to perform to change the state.'

      argument :time_estimate, GraphQL::Types::String,
               required: false,
               description: 'Estimated time to complete the merge request, or `0` to remove the current estimate.'

      def resolve(project_path:, iid:, **args)
        merge_request = authorized_find!(project_path: project_path, iid: iid)
        args = parse_arguments(args)

        ::MergeRequests::UpdateService
          .new(project: merge_request.project, current_user: current_user, params: args)
          .execute(merge_request)

        errors = errors_on_object(merge_request)

        {
          merge_request: merge_request.reset,
          errors: errors
        }
      end

      def ready?(time_estimate: nil, **args)
        if !time_estimate.nil? && Gitlab::TimeTrackingFormatter.parse(time_estimate, keep_zero: true).nil?
          raise Gitlab::Graphql::Errors::ArgumentError,
                'timeEstimate must be formatted correctly, for example `1h 30m`'
        end

        super
      end

      private

      def parse_arguments(args)
        unless args[:time_estimate].nil?
          args[:time_estimate] = Gitlab::TimeTrackingFormatter.parse(args[:time_estimate], keep_zero: true)
        end

        args.compact
      end
    end
  end
end