2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module JiraImport
|
|
|
|
class Start < BaseMutation
|
2020-06-23 00:09:42 +05:30
|
|
|
include ResolvesProject
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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'
|
2020-07-28 23:09:34 +05:30
|
|
|
argument :users_mapping,
|
|
|
|
[Types::JiraUsersMappingInputType],
|
|
|
|
required: false,
|
|
|
|
description: 'The mapping of Jira to GitLab users'
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def resolve(project_path:, jira_project_key:, users_mapping:)
|
2020-06-23 00:09:42 +05:30
|
|
|
project = authorized_find!(full_path: project_path)
|
2020-07-28 23:09:34 +05:30
|
|
|
mapping = users_mapping.to_ary.map { |map| map.to_hash }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
service_response = ::JiraImport::StartImportService
|
2020-07-28 23:09:34 +05:30
|
|
|
.new(context[:current_user], project, jira_project_key, mapping)
|
2020-04-22 19:07:51 +05:30
|
|
|
.execute
|
|
|
|
jira_import = service_response.success? ? service_response.payload[:import_data] : nil
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
{
|
|
|
|
jira_import: jira_import,
|
2020-06-23 00:09:42 +05:30
|
|
|
errors: service_response.errors
|
2020-04-22 19:07:51 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|