fastlane-plugin-jira_issues_release_notes 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8d2ba687d45982c92cee3cb3d66ac7874a194b8c8963f0c316bfa374dd73ea6
4
- data.tar.gz: abf29aeeec5877d64d466afb3687d8ecdf6669493971d957c4ad338200d257b8
3
+ metadata.gz: d8d5984ded8d97d30b8df79c68c103e923911c516829f203fd1d6b475368f783
4
+ data.tar.gz: b6262045d8f11134a0c1037004115b7c17a19e86f1264c2dc69b63d9173743ce
5
5
  SHA512:
6
- metadata.gz: ca3984c1624c8b032edd133c9f6ed01249aa490d18e7249cfded4135ade09195e4a4356b984c2371346408aefeabf0b21c61c04bfc6fefe6bca55efa104687a9
7
- data.tar.gz: 8a1ecf4d4207423978077008f516930c17f3182d029a675d768f21fdc5ccbe6df5303087d6fce644d178bb8a488b3f835eb1a2e077a5a2d7ebddaac1b09a34b4
6
+ metadata.gz: e075f8823aad025a3280acab73817ef50161a14003f6dfa76f2a81f9b6ee2dc24664c94fc6345bd7e1d123fe58586f3624a7e8fd1ba44d851ada7f1003f3e7ae
7
+ data.tar.gz: 6c841d6bda953fabf5d2ff0f75d4f3e372c6e5b891179df98ca12f8246243d0fdef9f66910d1859fa20268a04b3bdfc00bdb59456f5f13c9d1df4259381d6048
@@ -0,0 +1,255 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/jira_issues_release_notes_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class BranchJiraIssuesReleaseNotesAction < Action
7
+ def self.run(params)
8
+ branch = other_action.git_branch
9
+ regex = Regexp.new("(#{params[:ticket_prefix]}-\\d+)")
10
+
11
+ @format = params[:format]
12
+ @extra_fields = params[:extra_fields]
13
+
14
+ ticket_code = regex.match branch
15
+
16
+ return ticket_not_found unless ticket_code
17
+
18
+ UI.message "Found ticket code: #{ticket_code}"
19
+
20
+
21
+ @jira_helper = Helper::JiraIssuesReleaseNotesHelper.jira_helper(
22
+ host: params[:host],
23
+ username: params[:username],
24
+ password: params[:password],
25
+ context_path: params[:context_path],
26
+ disable_ssl_verification: params[:disable_ssl_verification]
27
+ )
28
+
29
+ issue = @jira_helper.get(issues: [ticket_code], extra_fields: @extra_fields.values).first
30
+
31
+ return ticket_not_found ticket_code unless issue
32
+
33
+ generate_message_with(issue: issue)
34
+
35
+ # tickets = tickets(commits: commits, regex: regex)
36
+ # UI.important("Jira tickets: #{tickets}")
37
+
38
+ # @jira_helper = Helper::JiraIssuesReleaseNotesHelper.jira_helper(
39
+ # host: params[:host],
40
+ # username: params[:username],
41
+ # password: params[:password],
42
+ # context_path: params[:context_path],
43
+ # disable_ssl_verification: params[:disable_ssl_verification]
44
+ # )
45
+ # issues = @jira_helper.get(issues: tickets)
46
+
47
+ # to_validate = issues.select { |issue| params[:to_validate_status].include?(issue.status.name) }
48
+ # validated = issues.select { |issue| params[:validated_status].include?(issue.status.name) }
49
+
50
+ # generate_changelog(to_validate: to_validate, validated: validated, format: params[:format], url: params[:build_url])
51
+ # end
52
+
53
+ # def self.generate_changelog(to_validate:, validated:, format:, url:)
54
+ # changelog = []
55
+ # changelog.concat(format_issues(label: 'Tasks to validate', issues: to_validate, format: format)) unless to_validate.empty?
56
+ # changelog.concat(['']) unless changelog.to_s.empty?
57
+ # changelog.concat(format_issues(label: 'Validated tasks', issues: validated, format: format)) unless validated.empty?
58
+ # # changes = format_issues(issues: issues)
59
+ # changelog = ['No changes included.'] if changelog.to_s.empty?
60
+
61
+ # changelog.join("\n")
62
+ end
63
+
64
+ def self.ticket_not_found(ticket_code = "")
65
+
66
+ UI.important "No ticket code could be extracted from git branch name."
67
+ UI.message "Trying to use latest git commit"
68
+ last_commit = other_action.last_git_commit
69
+ return UI.error "There is no commit" unless last_commit
70
+ header_text = ticket_code ? "😅 Jira issue with key '#{ticket_code}' could not be found" : "😅 Jira issue could not be detected"
71
+
72
+ return [
73
+ style_text(text: header_text, style: 'heading'),
74
+ style_text(text: "► Latest Commit:", style: 'bold'),
75
+ last_commit[:message]
76
+ ].join("\n")
77
+ end
78
+
79
+ def self.style_text(text:, style:)
80
+ # formats the text according to the style we're looking to use
81
+
82
+ # Skips all styling
83
+ case style
84
+ when "title"
85
+ case @format
86
+ when "markdown"
87
+ "# #{text}"
88
+ when "slack"
89
+ "*#{text}*"
90
+ else
91
+ text
92
+ end
93
+ when "heading"
94
+ case format
95
+ when "markdown"
96
+ "### #{text}"
97
+ when "slack"
98
+ "*#{text}*"
99
+ else
100
+ "#{text}:"
101
+ end
102
+ when "bold"
103
+ case format
104
+ when "markdown"
105
+ "**#{text}**"
106
+ when "slack"
107
+ "*#{text}*"
108
+ else
109
+ text
110
+ end
111
+ else
112
+ text # catchall, shouldn't be needed
113
+ end
114
+ end
115
+
116
+ def self.generate_message_with(issue:)
117
+ link = @jira_helper.url(issue: issue)
118
+ issue_type = issue.issuetype ? issue.issuetype.name : ''
119
+ status = issue.status.name
120
+ issue.attrs["fields"][:customfield_10040.to_s]
121
+ case @format
122
+ when "slack"
123
+ extra = @extra_fields.map { |key, value| ["", "*► #{key.to_s}*", issue.attrs["fields"][value.to_s]] }
124
+ [
125
+ "*► #{issue_type}: <#{link}|#{issue.summary}>* (#{status})",
126
+ issue.description,
127
+ extra.flatten!
128
+ ]
129
+ .flatten!
130
+ .join("\n")
131
+ when "markdown"
132
+ extra = @extra_fields.map { |key, value| ["", "**► #{key.to_s}**", issue.attrs["fields"][value.to_s]] }
133
+ [
134
+ "**► #{issue_type}: [#{issue.summary}](#{link})** (#{status})",
135
+ issue.description,
136
+ extra.flatten!
137
+ ]
138
+ .flatten!
139
+ .join("\n")
140
+ else
141
+ extra = @extra_fields.map { |key, value| ["", "► #{key.to_s}", issue.attrs["fields"][value.to_s]] }
142
+ [
143
+ "► #{issue_type}: #{issue.summary}(#{status}) #{link}",
144
+ issue.description,
145
+ extra.flatten!
146
+ ]
147
+ .flatten!
148
+ .join("\n")
149
+ end
150
+ end
151
+
152
+ def self.description
153
+ "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
154
+ end
155
+
156
+ def self.authors
157
+ ["Erick Martins"]
158
+ end
159
+
160
+ def self.return_value
161
+ # If your method provides a return value, you can describe here what it does
162
+ end
163
+
164
+ def self.details
165
+ # Optional:
166
+ "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
167
+ end
168
+
169
+ def self.available_options
170
+ [
171
+ FastlaneCore::ConfigItem.new(
172
+ key: :ticket_prefix,
173
+ env_name: 'FL_FIND_TICKETS_MATCHING',
174
+ description: 'regex to extract ticket numbers',
175
+ default_value: '[A-Z]+',
176
+ optional: true
177
+ ),
178
+ FastlaneCore::ConfigItem.new(
179
+ key: :build_url,
180
+ env_name: 'FL_RELEASE_NOTES_BUILD_URL',
181
+ description: 'Link to the ci build',
182
+ optional: true,
183
+ default_value: ENV['BUILD_URL']
184
+ ),
185
+ FastlaneCore::ConfigItem.new(
186
+ key: :format,
187
+ description: "You can use either markdown, slack or plain",
188
+ default_value: "markdown",
189
+ optional: true,
190
+ verify_block: proc do |value|
191
+ UI.user_error!("Invalid format! You can use either markdown, slack or plain") unless ['markdown', 'slack', 'plain'].include?(value)
192
+ end
193
+ ),
194
+ FastlaneCore::ConfigItem.new(
195
+ key: :extra_fields,
196
+ description: "Extra jira fields",
197
+ type: Hash,
198
+ optional: true,
199
+ default_value: {},
200
+ ),
201
+
202
+ # Jira Client options
203
+ FastlaneCore::ConfigItem.new(
204
+ key: :username,
205
+ env_name: 'FL_JIRA_USERNAME',
206
+ description: 'Jira user',
207
+ optional: false
208
+ ),
209
+ FastlaneCore::ConfigItem.new(
210
+ key: :password,
211
+ env_name: 'FL_JIRA_PASSWORD',
212
+ description: 'Jira user',
213
+ optional: false
214
+ ),
215
+ FastlaneCore::ConfigItem.new(
216
+ key: :host,
217
+ env_name: 'FL_JIRA_HOST',
218
+ description: 'Jira location',
219
+ optional: false
220
+ ),
221
+ FastlaneCore::ConfigItem.new(
222
+ key: :context_path,
223
+ env_name: 'FL_JIRA_CONTEXT_PATH',
224
+ description: 'Jira context path',
225
+ optional: true,
226
+ default_value: ''
227
+ ),
228
+ FastlaneCore::ConfigItem.new(
229
+ key: :disable_ssl_verification,
230
+ env_name: 'FL_JIRA_DISABLE_SSL_VERIFICATION',
231
+ description: 'Jira SSL Verification mode',
232
+ optional: true,
233
+ default_value: false,
234
+ type: Boolean
235
+ ),
236
+ FastlaneCore::ConfigItem.new(
237
+ key: :debug,
238
+ description: "True if you want to log out a debug info",
239
+ default_value: false,
240
+ type: Boolean,
241
+ optional: true
242
+ )
243
+ ]
244
+ end
245
+
246
+ def self.is_supported?(platform)
247
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
248
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
249
+ #
250
+ # [:ios, :mac, :android].include?(platform)
251
+ true
252
+ end
253
+ end
254
+ end
255
+ end
@@ -61,11 +61,14 @@ module Fastlane
61
61
  @client = jira_client_helper
62
62
  end
63
63
 
64
- def get(issues:)
64
+ def get(issues:, extra_fields: [])
65
65
  return [] if issues.to_a.empty?
66
66
 
67
+ fields = [:key, :summary, :status, :issuetype, :description]
68
+ fields.concat extra_fields
69
+
67
70
  begin
68
- @client.Issue.jql("KEY IN (#{issues.join(',')})", fields: [:key, :summary, :status], validate_query: false)
71
+ @client.Issue.jql("KEY IN (#{issues.join(',')})", fields: fields, validate_query: false)
69
72
  rescue StandardError => e
70
73
  UI.important('Jira Client: Failed to get issue.')
71
74
  UI.important("Jira Client: Reason - #{e.message}")
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module JiraIssuesReleaseNotes
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-jira_issues_release_notes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erick Martins
@@ -159,6 +159,7 @@ files:
159
159
  - LICENSE
160
160
  - README.md
161
161
  - lib/fastlane/plugin/jira_issues_release_notes.rb
162
+ - lib/fastlane/plugin/jira_issues_release_notes/actions/branch_jira_issues_release_notes_action.rb
162
163
  - lib/fastlane/plugin/jira_issues_release_notes/actions/jira_issues_release_notes_action.rb
163
164
  - lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb
164
165
  - lib/fastlane/plugin/jira_issues_release_notes/version.rb