Class: Fastlane::Actions::JiraReleaseNotesAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



117
118
119
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 117

def self.authors
  ["Alexander Ignition"]
end

.available_optionsObject



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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 68

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: :project,
                                 env_name: "FL_JIRA_PROJECT",
                                 description: "Jira project name",
                                 sensitive: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No Jira project name") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :version,
                                 env_name: "FL_JIRA_PROJECT_VERSION",
                                 description: "Jira project version",
                                 sensitive: true,
                                 is_string: false,
                                 verify_block: proc do |value|
                                   UI.user_error!("'version' value must be a String or Regexp! Found #{value.class} instead.") unless value.kind_of?(String) || value.kind_of?(Regexp)
                                   UI.user_error!("No Jira project version") if value.to_s.length == 0
                                 end),
    FastlaneCore::ConfigItem.new(key: :format,
                                 env_name: "FL_JIRA_RELEASE_NOTES_FORMAT",
                                 description: "Format text. Plain, html or none",
                                 sensitive: true,
                                 default_value: "plain"),
    FastlaneCore::ConfigItem.new(key: :max_results,
                                 env_name: "FL_JIRA_RELEASE_NOTES_MAX_RESULTS",
                                 description: "Maximum number of issues",
                                 default_value: "50")
  ]
end

.categoryObject



146
147
148
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 146

def self.category
  :misc
end

.descriptionObject



56
57
58
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 56

def self.description
  "Jira release notes"
end

.detailsObject



60
61
62
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 60

def self.details
  "Fetch release notes for Jira project for version"
end

.example_codeObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 125

def self.example_code
  [
    'notes = jira_release_notes(
      url: "https://bugs.yourdomain.com",
      username: "Your username",
      password: "Your password",
      project: "ABC",
      version: "1.0"
    )
    gym
    crashlytics(notes: notes)',
    'notes = jira_release_notes(
      project: "ABC",
      version: "1.0",
      format: "html"
    )
    gym
    slack(message: notes)'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 121

def self.is_supported?(platform)
  true
end

.return_valueObject



64
65
66
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.rb', line 64

def self.return_value
  "List of issues from jira. Formatted string or class"
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
44
45
46
47
48
49
50
# File 'lib/fastlane/plugin/jira_release_notes/actions/jira_release_notes_action.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
  )

  version = params[:version]
  project = params[:project]
  max_results = params[:max_results].to_i
  issues = []

  UI.message("Fetch issues from JIRA project '#{project}', version '#{version}'")

  begin
    if version.kind_of?(Regexp)
      versions = client.Project.find(project).versions
                       .select { |v| version.match(v.name) }
                       .map { |v| "'#{v.name}'" } .join(', ')
      issues = client.Issue.jql("PROJECT = '#{project}' AND fixVersion in (#{versions})",
                                max_results: max_results)
    else
      issues = client.Issue.jql("PROJECT = '#{project}' AND fixVersion = '#{version}'",
                                max_results: max_results)
    end
  rescue JIRA::HTTPError => e
    fields = [e.code, e.message]
    fields << e.response.body if e.response.content_type == "application/json"
    UI.user_error!("#{e} #{fields.join(', ')}")
  end

  UI.success("📝  #{issues.count} issues from JIRA project '#{project}', version '#{version}'")

  case params[:format]
  when "plain"
    Helper::JiraReleaseNotesHelper.plain_format(issues)
  when "html"
    Helper::JiraReleaseNotesHelper.html_format(issues, params[:url])
  else
    issues
  end
end