debian-mirror-gitlab/app/graphql/resolvers/projects/jira_projects_resolver.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Resolvers
module Projects
class JiraProjectsResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
2021-01-29 00:20:46 +05:30
type Types::Projects::Services::JiraProjectType.connection_type, null: true
2021-03-08 18:12:59 +05:30
authorize :admin_project
2021-01-29 00:20:46 +05:30
2020-06-23 00:09:42 +05:30
argument :name,
GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Project name or key.'
2020-06-23 00:09:42 +05:30
def resolve(name: nil, **args)
authorize!(project)
2020-07-28 23:09:34 +05:30
response = jira_projects(name: name)
2020-06-23 00:09:42 +05:30
if response.success?
2020-10-24 23:57:45 +05:30
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
2021-01-03 14:25:43 +05:30
**args.merge({ max_page_size: projects_array.size })
2020-10-24 23:57:45 +05:30
)
2020-06-23 00:09:42 +05:30
else
raise Gitlab::Graphql::Errors::BaseError, response.message
end
end
private
alias_method :jira_service, :object
def project
jira_service&.project
end
2020-07-28 23:09:34 +05:30
def jira_projects(name:)
args = { query: name }.compact
2020-06-23 00:09:42 +05:30
2020-07-28 23:09:34 +05:30
Jira::Requests::Projects::ListService.new(project.jira_service, args).execute
2020-06-23 00:09:42 +05:30
end
end
end
end