summaryrefslogtreecommitdiff
path: root/qa/qa/vendor/jira/jira_api.rb
blob: 64af824418df1e3c4f7d88b12ba8916a1718fc78 (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
48
49
50
51
52
53
54
# frozen_string_literal: true

module QA
  module Vendor
    module Jira
      class JiraAPI
        include Scenario::Actable
        include Support::API

        def base_url
          host = QA::Runtime::Env.jira_hostname || 'localhost'

          "http://#{host}:8080"
        end

        def api_url
          "#{base_url}/rest/api/2"
        end

        def fetch_issue(issue_key)
          response = get("#{api_url}/issue/#{issue_key}", user: Runtime::Env.jira_admin_username, password: Runtime::Env.jira_admin_password)

          parse_body(response)
        end

        def create_issue(jira_project_key)
          payload = {
            fields: {
              project: {
                key: jira_project_key
              },
              summary: 'REST ye merry gentlemen.',
              description: 'Creating of an issue using project keys and issue type names using the REST API',
              issuetype: {
                name: 'Bug'
              }
            }
          }

          response = post("#{api_url}/issue",
            payload.to_json, headers: { 'Content-Type': 'application/json' },
            user: Runtime::Env.jira_admin_username,
            password: Runtime::Env.jira_admin_password)

          issue_key = parse_body(response)[:key]

          QA::Runtime::Logger.debug("Created JIRA issue with key: '#{issue_key}'")

          issue_key
        end
      end
    end
  end
end