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

52 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
argument :name,
GraphQL::STRING_TYPE,
required: false,
description: 'Project name or key'
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
def authorized_resource?(project)
Ability.allowed?(context[:current_user], :admin_project, project)
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