Class: Fastlane::Actions::JiraGetTicketAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



95
96
97
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 95

def self.authors
  ["Flop Butylkin"]
end

.available_optionsObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 65

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :url,
                                 env_name: "FL_JIRA_SITE",
                                 description: "URL for Jira instance",
                                 verify_block: proc do |value|
                                   UI.user_error!("No url for Jira given") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_JIRA_USERNAME",
                                 description: "Username for Jira instance",
                                 verify_block: proc do |value|
                                   UI.user_error!("No username") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "FL_JIRA_PASSWORD",
                                 description: "Password or api token for Jira",
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No password") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :ticket,
                                 env_name: "FL_JIRA_TICKET",
                                 description: "Jira ticket id",
                                 type: String,
                                 optional: true,
                                 default_value: nil)
  ]
end

.categoryObject



113
114
115
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 113

def self.category
  :misc
end

.descriptionObject



49
50
51
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 49

def self.description
  "Jira ticket comment replace action"
end

.detailsObject



53
54
55
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 53

def self.details
  "Replace Jira ticket comment"
end

.example_codeObject



103
104
105
106
107
108
109
110
111
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 103

def self.example_code
  [
    '
    jira_get_ticket(
      ticket: "APP-132",
    )
    '
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 99

def self.is_supported?(platform)
  true
end

.return_typeObject



61
62
63
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 61

def self.return_type
  :hash
end

.return_valueObject



57
58
59
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 57

def self.return_value
  "Hash where keys are Jira ticket IDs and values results of the action"
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/jira_update/actions/jira_get_ticket.rb', line 4

def self.run(params)
  Actions.verify_gem!('jira-ruby')
  require 'jira-ruby'

  client = JIRA::Client.new(
    username:     params[:username],
    password:     params[:password],
    site:         params[:url],
    context_path: '',
    auth_type:    :basic
  )

  ticket = params[:ticket]
  UI.message("JIRA ticket id: '#{ticket}'")

  begin
    issue = client.Issue.find(ticket)
    
  rescue StandardError => e
    UI.important("Failed to fetch issue #{ticket}: #{e.message}")
    UI.error!("Failed to fetch issue #{ticket}: #{e.message}") if fail_if_not_found
    result = "Ticket not found"
  end

  # Convert the issue to a hash only with the fields we need
  issue_hash = {
    id: issue.id,
    key: issue.key,
    summary: issue.summary,
    description: issue.description,
    status: issue.status.name,
    assignee: issue.assignee.displayName,
    reporter: issue.reporter.displayName,
    created: issue.created,
    updated: issue.updated
  }

  UI.message("JIRA ticket found: '#{issue_hash[:key]}'")
  return issue_hash
end