Class: Fastlane::Helper::CerberusHelper::JiraHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/cerberus/helper/cerberus_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, username:, password:, context_path:, disable_ssl_verification:, jira_client_helper: nil) ⇒ JiraHelper

Returns a new instance of JiraHelper.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/cerberus/helper/cerberus_helper.rb', line 25

def initialize(host:, username:, password:, context_path:, disable_ssl_verification:, jira_client_helper: nil)
  @host = host
  @context_path = context_path

  jira_client_helper ||= JiraClientHelper.client(
    host: host,
    username: username,
    password: password,
    context_path: context_path,
    disable_ssl_verification: disable_ssl_verification
  )
  @client = jira_client_helper
end

Instance Method Details

#add_comment(comment:, issues:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/cerberus/helper/cerberus_helper.rb', line 51

def add_comment(comment:, issues:)
  return if issues.to_a.empty?

  issues.each do |issue|
    begin
      issue.comments.build.save({ 'body' => comment })
    rescue => e
      UI.important("Jira Client: Failed to comment on issues - #{issue.key}")
      UI.important("Jira Client: Reason - #{e.message}")
    end
  end
end

#get(issues:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/cerberus/helper/cerberus_helper.rb', line 39

def get(issues:)
  return [] if issues.to_a.empty?

  begin
    @client.Issue.jql("KEY IN (#{issues.join(',')})", fields: [:key, :summary], validate_query: false)
  rescue => e
    UI.important('Jira Client: Failed to get issue.')
    UI.important("Jira Client: Reason - #{e.message}")
    []
  end
end

#url(issue:) ⇒ Object



64
65
66
# File 'lib/fastlane/plugin/cerberus/helper/cerberus_helper.rb', line 64

def url(issue:)
  [@host, @context_path, 'browse', issue.key].reject(&:empty?).join('/')
end