Class: Fastlane::Actions::JiraFeatureValidationAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



105
106
107
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 105

def self.authors
  ["Erick Martins"]
end

.available_optionsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 118

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :ticket_prefix,
      env_name: 'FL_FIND_TICKETS_MATCHING',
      description:  'regex to extract ticket numbers',
      default_value: '[A-Z]+',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :format,
      description: "You can use either markdown, slack, html or plain",
      default_value: "markdown",
      optional: true,
      verify_block: proc do |value|
        UI.user_error!("Invalid format! You can use either markdown, slack, html or plain") unless ['markdown', 'html', 'slack', 'plain'].include?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :extra_fields,
      description: "Extra jira fields",
      type: Hash,
      optional: true,
      default_value: {},
    ),

    # Jira Client options
    FastlaneCore::ConfigItem.new(
      key: :username,
      env_name: 'FL_JIRA_USERNAME',
      description:  'Jira user',
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :password,
      env_name: 'FL_JIRA_PASSWORD',
      description:  'Jira user',
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :host,
      env_name: 'FL_JIRA_HOST',
      description:  'Jira location',
      optional: false
    ),
    FastlaneCore::ConfigItem.new(
      key: :api_version,
      env_name: 'FL_JIRA_API_VERSION',
      description:  'Jira api version',
      default_value: '2',
      optional: true,
    ),
    FastlaneCore::ConfigItem.new(
      key: :context_path,
      env_name: 'FL_JIRA_CONTEXT_PATH',
      description:  'Jira context path',
      optional: true,
      default_value: ''
    ),
    FastlaneCore::ConfigItem.new(
      key: :disable_ssl_verification,
      env_name: 'FL_JIRA_DISABLE_SSL_VERIFICATION',
      description:  'Jira SSL Verification mode',
      optional: true,
      default_value: false,
      type: Boolean
    ),
    FastlaneCore::ConfigItem.new(
      key: :debug,
      description: "True if you want to log out a debug info",
      default_value: false,
      type: Boolean,
      optional: true
    )
  ]
end

.descriptionObject



101
102
103
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 101

def self.description
  "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
end

.detailsObject



113
114
115
116
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 113

def self.details
  # Optional:
  "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
end

.generate_message_with(issue:) ⇒ Object



56
57
58
59
60
61
62
63
64
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
94
95
96
97
98
99
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 56

def self.generate_message_with(issue:)
  link = @jira_helper.url(issue: issue)
  issue_type = issue.issuetype ? issue.issuetype.name : ''
  status = issue.status.name
  issue.attrs["fields"][:customfield_10040.to_s]
  case @format
  when "slack"
    extra = @extra_fields.map { |key, value| ["", "*► #{key.to_s}*", issue.attrs["fields"][value.to_s]] }
    [
      "*► #{issue_type}: <#{link}|#{issue.summary}>* (#{status})", 
      issue.description,
      extra.flatten!
    ]
    .flatten!
    .join(@format_line_break)
  when "markdown"
    extra = @extra_fields.map { |key, value| ["", "**► #{key.to_s}**", issue.attrs["fields"][value.to_s]] }
    [
      "**► #{issue_type}: [#{issue.summary}](#{link})** (#{status})", 
      issue.description, 
      extra.flatten!
    ]
    .flatten!
    .join(@format_line_break)
  when "html"
    extra = @extra_fields.map { |key, value| ["", "<strong>&#9658; #{key.to_s}</strong>", issue.attrs["fields"][value.to_s]] }
    [
      "<strong>&#9658; #{issue_type}: <a href=\"#{link}\" target=\"_blank\">#{issue.summary}</a></strong> (#{status})", 
      issue.description, 
      extra.flatten!
    ]
    .flatten!
    .join(@format_line_break)
  else
    extra = @extra_fields.map { |key, value| ["", "#{key.to_s}", issue.attrs["fields"][value.to_s]] }
    [
      "#{issue_type}: #{issue.summary}(#{status}) #{link}", 
      issue.description, 
      extra.flatten!
    ]
    .flatten!
    .join(@format_line_break)
  end
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


195
196
197
198
199
200
201
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 195

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



109
110
111
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 109

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



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

def self.run(params)
  branch = other_action.git_branch
  ticket_key = Helper::JiraIssuesReleaseNotesHelper.extract_key_from_branch(
    branch: branch,
    ticket_prefix: params[:ticket_prefix]
  )

  @format = params[:format]
  @extra_fields = params[:extra_fields]
  @format_line_break = @format === 'html' ? '<br />' : "\n"


  return ticket_not_found unless ticket_code

  UI.message "Found ticket code: #{ticket_code}"
  

  @jira_helper = Helper::JiraIssuesReleaseNotesHelper.jira_helper(
    host: params[:host],
    api_version: params[:api_version],
    username: params[:username],
    password: params[:password],
    context_path: params[:context_path],
    disable_ssl_verification: params[:disable_ssl_verification]
  )

  issue = @jira_helper.get(issues: [ticket_code], extra_fields: @extra_fields.values).first

  return ticket_not_found ticket_code unless issue

  generate_message_with(issue: issue)
end

.ticket_not_found(ticket_code = "") ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/jira_issues_release_notes/actions/jira_feature_validation_action.rb', line 40

def self.ticket_not_found(ticket_code = "")

  UI.important "No ticket code could be extracted from git branch name."
  UI.message "Trying to use latest git commit"
  last_commit = other_action.last_git_commit
  return UI.error "There is no commit" unless last_commit
  header_text = ticket_code ? "😅 Jira issue with key '#{ticket_code}' could not be found" : "😅 Jira issue could not be detected"

  return [
    Helper::JiraIssuesReleaseNotesHelper.style_text(text: header_text, style: 'heading'),
    Helper::JiraIssuesReleaseNotesHelper.style_text(text: "► Latest Commit:", style: 'bold'),
    last_commit[:message]
  ].join("\n")
end