2020-05-22 08:08:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
module Projects
|
|
|
|
class JiraProjectsResolver < BaseResolver
|
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
2020-11-09 19:08:52 -05:00
|
|
|
type Types::Projects::Services::JiraProjectType.connection_type, null: true
|
2020-12-23 13:10:19 -05:00
|
|
|
authorize :admin_project
|
2020-11-09 19:08:52 -05:00
|
|
|
|
2020-05-22 08:08:15 -04:00
|
|
|
argument :name,
|
2021-07-22 08:10:04 -04:00
|
|
|
GraphQL::Types::String,
|
2020-05-22 08:08:15 -04:00
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Project name or key.'
|
2020-05-22 08:08:15 -04:00
|
|
|
|
|
|
|
def resolve(name: nil, **args)
|
|
|
|
authorize!(project)
|
|
|
|
|
2020-06-22 08:08:47 -04:00
|
|
|
response = jira_projects(name: name)
|
2020-05-22 08:08:15 -04:00
|
|
|
|
2020-06-08 20:08:47 -04:00
|
|
|
if response.success?
|
2020-07-29 08:09:45 -04:00
|
|
|
projects_array = response.payload[:projects]
|
|
|
|
|
|
|
|
GraphQL::Pagination::ArrayConnection.new(
|
|
|
|
projects_array,
|
|
|
|
# override default max_page_size to whatever the size of the response is,
|
|
|
|
# see https://gitlab.com/gitlab-org/gitlab/-/issues/231394
|
2020-10-06 11:08:33 -04:00
|
|
|
**args.merge({ max_page_size: projects_array.size })
|
2020-07-29 08:09:45 -04:00
|
|
|
)
|
2020-06-08 20:08:47 -04:00
|
|
|
else
|
|
|
|
raise Gitlab::Graphql::Errors::BaseError, response.message
|
|
|
|
end
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
alias_method :jira_integration, :object
|
2020-05-22 08:08:15 -04:00
|
|
|
|
|
|
|
def project
|
2021-06-18 11:10:16 -04:00
|
|
|
jira_integration&.project
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
|
2020-06-22 08:08:47 -04:00
|
|
|
def jira_projects(name:)
|
|
|
|
args = { query: name }.compact
|
2020-05-22 08:08:15 -04:00
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
Jira::Requests::Projects::ListService.new(project.jira_integration, args).execute
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|