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-05-22 08:08:15 -04:00
|
|
|
argument :name,
|
|
|
|
GraphQL::STRING_TYPE,
|
|
|
|
required: false,
|
|
|
|
description: 'Project name or key'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def authorized_resource?(project)
|
2020-05-26 08:08:22 -04:00
|
|
|
Ability.allowed?(context[:current_user], :admin_project, project)
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :jira_service, :object
|
|
|
|
|
|
|
|
def project
|
|
|
|
jira_service&.project
|
|
|
|
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
|
|
|
|
2020-07-10 20:09:17 -04:00
|
|
|
Jira::Requests::Projects::ListService.new(project.jira_service, args).execute
|
2020-05-22 08:08:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|