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

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

module Mutations
  module JiraImport
    class Start < BaseMutation
      include Mutations::ResolvesProject

      graphql_name 'JiraImportStart'

      field :jira_import,
            Types::JiraImportType,
            null: true,
            description: 'The Jira import data after mutation'

      argument :project_path, GraphQL::ID_TYPE,
               required: true,
               description: 'The project to import the Jira project into'
      argument :jira_project_key, GraphQL::STRING_TYPE,
               required: true,
               description: 'Project key of the importer Jira project'
      argument :jira_project_name, GraphQL::STRING_TYPE,
               required: false,
               description: 'Project name of the importer Jira project'

      def resolve(project_path:, jira_project_key:)
        project = find_project!(project_path: project_path)

        raise_resource_not_available_error! unless project

        service_response = ::JiraImport::StartImportService
                             .new(context[:current_user], project, jira_project_key)
                             .execute
        jira_import = service_response.success? ? service_response.payload[:import_data] : nil
        errors = service_response.error? ? [service_response.message] : []
        {
          jira_import: jira_import,
          errors: errors
        }
      end

      private

      def find_project!(project_path:)
        return unless project_path.present?

        authorized_find!(full_path: project_path)
      end

      def find_object(full_path:)
        resolve_project(full_path: full_path)
      end

      def authorized_resource?(project)
        Ability.allowed?(context[:current_user], :admin_project, project)
      end
    end
  end
end