blob: ac9e9bf0be9f25e89d3139b89b931972dd184dd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# frozen_string_literal: true
module Jira
module Requests
module Projects
class ListService < Base
extend ::Gitlab::Utils::Override
def initialize(jira_integration, params = {})
super(jira_integration, params)
@query = params[:query]
end
private
attr_reader :query
override :url
def url
"#{base_api_url}/project"
end
override :build_service_response
def build_service_response(response)
return ServiceResponse.success(payload: empty_payload) unless response.present?
ServiceResponse.success(payload: { projects: map_projects(response), is_last: true })
end
def map_projects(response)
response.map { |v| JIRA::Resource::Project.build(client, v) }.select(&method(:match_query?))
end
def match_query?(jira_project)
downcase_query = query.to_s.downcase
jira_project&.key&.downcase&.include?(downcase_query) || jira_project&.name&.downcase&.include?(downcase_query)
end
def empty_payload
{ projects: [], is_last: true }
end
end
end
end
end
|