File: createmeta.rb

package info (click to toggle)
ruby-jira 2.1.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 968 kB
  • sloc: ruby: 5,125; makefile: 12
file content (44 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (2)
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
module JIRA
  module Resource
    class CreatemetaFactory < JIRA::BaseFactory # :nodoc:
    end

    class Createmeta < JIRA::Base
      def self.endpoint_name
        '/issue/createmeta'
      end

      def self.all(client, params = {})
        if params.key?(:projectKeys)
          values = Array(params[:projectKeys]).map { |i| (i.is_a?(JIRA::Resource::Project) ? i.key : i) }
          params[:projectKeys] = values.join(',')
        end

        if params.key?(:projectIds)
          values = Array(params[:projectIds]).map { |i| (i.is_a?(JIRA::Resource::Project) ? i.id : i) }
          params[:projectIds] = values.join(',')
        end

        if params.key?(:issuetypeNames)
          values = Array(params[:issuetypeNames]).map { |i| (i.is_a?(JIRA::Resource::Issuetype) ? i.name : i) }
          params[:issuetypeNames] = values.join(',')
        end

        if params.key?(:issuetypeIds)
          values = Array(params[:issuetypeIds]).map { |i| (i.is_a?(JIRA::Resource::Issuetype) ? i.id : i) }
          params[:issuetypeIds] = values.join(',')
        end

        create_meta_url = client.options[:rest_base_path] + endpoint_name
        params = hash_to_query_string(params)

        response = params.empty? ? client.get(create_meta_url.to_s) : client.get("#{create_meta_url}?#{params}")

        json = parse_json(response.body)
        json['projects'].map do |attrs|
          new(client, attrs: attrs)
        end
      end
    end
  end
end