fastlane-plugin-jira_issues_release_notes 0.3.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,18 @@ require_relative '../helper/jira_issues_release_notes_helper'
3
3
 
4
4
  module Fastlane
5
5
  module Actions
6
- class BranchJiraIssuesReleaseNotesAction < Action
6
+ class JiraFeatureValidationAction < Action
7
7
  def self.run(params)
8
8
  branch = other_action.git_branch
9
- regex = Regexp.new("(#{params[:ticket_prefix]}-\\d+)")
9
+ ticket_key = Helper::JiraIssuesReleaseNotesHelper.extract_key_from_branch(
10
+ branch: branch,
11
+ ticket_prefix: params[:ticket_prefix]
12
+ )
10
13
 
11
14
  @format = params[:format]
12
15
  @extra_fields = params[:extra_fields]
16
+ @format_line_break = @format === 'html' ? '<br />' : "\n"
13
17
 
14
- ticket_code = regex.match branch
15
18
 
16
19
  return ticket_not_found unless ticket_code
17
20
 
@@ -20,6 +23,7 @@ module Fastlane
20
23
 
21
24
  @jira_helper = Helper::JiraIssuesReleaseNotesHelper.jira_helper(
22
25
  host: params[:host],
26
+ api_version: params[:api_version],
23
27
  username: params[:username],
24
28
  password: params[:password],
25
29
  context_path: params[:context_path],
@@ -42,48 +46,12 @@ module Fastlane
42
46
  header_text = ticket_code ? "😅 Jira issue with key '#{ticket_code}' could not be found" : "😅 Jira issue could not be detected"
43
47
 
44
48
  return [
45
- style_text(text: header_text, style: 'heading'),
46
- style_text(text: "► Latest Commit:", style: 'bold'),
49
+ Helper::JiraIssuesReleaseNotesHelper.style_text(text: header_text, style: 'heading'),
50
+ Helper::JiraIssuesReleaseNotesHelper.style_text(text: "► Latest Commit:", style: 'bold'),
47
51
  last_commit[:message]
48
52
  ].join("\n")
49
53
  end
50
-
51
- def self.style_text(text:, style:)
52
- # formats the text according to the style we're looking to use
53
-
54
- # Skips all styling
55
- case style
56
- when "title"
57
- case @format
58
- when "markdown"
59
- "# #{text}"
60
- when "slack"
61
- "*#{text}*"
62
- else
63
- text
64
- end
65
- when "heading"
66
- case format
67
- when "markdown"
68
- "### #{text}"
69
- when "slack"
70
- "*#{text}*"
71
- else
72
- "#{text}:"
73
- end
74
- when "bold"
75
- case format
76
- when "markdown"
77
- "**#{text}**"
78
- when "slack"
79
- "*#{text}*"
80
- else
81
- text
82
- end
83
- else
84
- text # catchall, shouldn't be needed
85
- end
86
- end
54
+
87
55
 
88
56
  def self.generate_message_with(issue:)
89
57
  link = @jira_helper.url(issue: issue)
@@ -99,7 +67,7 @@ module Fastlane
99
67
  extra.flatten!
100
68
  ]
101
69
  .flatten!
102
- .join("\n")
70
+ .join(@format_line_break)
103
71
  when "markdown"
104
72
  extra = @extra_fields.map { |key, value| ["", "**► #{key.to_s}**", issue.attrs["fields"][value.to_s]] }
105
73
  [
@@ -108,7 +76,16 @@ module Fastlane
108
76
  extra.flatten!
109
77
  ]
110
78
  .flatten!
111
- .join("\n")
79
+ .join(@format_line_break)
80
+ when "html"
81
+ extra = @extra_fields.map { |key, value| ["", "<strong>&#9658; #{key.to_s}</strong>", issue.attrs["fields"][value.to_s]] }
82
+ [
83
+ "<strong>&#9658; #{issue_type}: <a href=\"#{link}\" target=\"_blank\">#{issue.summary}</a></strong> (#{status})",
84
+ issue.description,
85
+ extra.flatten!
86
+ ]
87
+ .flatten!
88
+ .join(@format_line_break)
112
89
  else
113
90
  extra = @extra_fields.map { |key, value| ["", "► #{key.to_s}", issue.attrs["fields"][value.to_s]] }
114
91
  [
@@ -117,7 +94,7 @@ module Fastlane
117
94
  extra.flatten!
118
95
  ]
119
96
  .flatten!
120
- .join("\n")
97
+ .join(@format_line_break)
121
98
  end
122
99
  end
123
100
 
@@ -149,11 +126,11 @@ module Fastlane
149
126
  ),
150
127
  FastlaneCore::ConfigItem.new(
151
128
  key: :format,
152
- description: "You can use either markdown, slack or plain",
129
+ description: "You can use either markdown, slack, html or plain",
153
130
  default_value: "markdown",
154
131
  optional: true,
155
132
  verify_block: proc do |value|
156
- UI.user_error!("Invalid format! You can use either markdown, slack or plain") unless ['markdown', 'slack', 'plain'].include?(value)
133
+ UI.user_error!("Invalid format! You can use either markdown, slack, html or plain") unless ['markdown', 'html', 'slack', 'plain'].include?(value)
157
134
  end
158
135
  ),
159
136
  FastlaneCore::ConfigItem.new(
@@ -183,6 +160,13 @@ module Fastlane
183
160
  description: 'Jira location',
184
161
  optional: false
185
162
  ),
163
+ FastlaneCore::ConfigItem.new(
164
+ key: :api_version,
165
+ env_name: 'FL_JIRA_API_VERSION',
166
+ description: 'Jira api version',
167
+ default_value: '2',
168
+ optional: true,
169
+ ),
186
170
  FastlaneCore::ConfigItem.new(
187
171
  key: :context_path,
188
172
  env_name: 'FL_JIRA_CONTEXT_PATH',
@@ -0,0 +1,134 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/jira_issues_release_notes_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ FL_JIRA_LAST_TAG ||= :S3_APK_OUTPUT_PATH
8
+ FL_JIRA_LAST_TAG_HASH ||= :FL_JIRA_LAST_TAG_HASH
9
+ FL_JIRA_COMMITS_FROM_HASH ||= :FL_JIRA_COMMITS_FROM_HASH
10
+ FL_JIRA_LAST_KEYS_FROM_COMMITS ||= :FL_JIRA_LAST_KEYS_FROM_COMMITS
11
+ FL_JIRA_LAST_ISSUES_FROM_COMMITS ||= :FL_JIRA_LAST_ISSUES_FROM_COMMITS
12
+ end
13
+
14
+ class JiraIssuesKeysFromCommitsAction < Action
15
+ def self.run(params)
16
+ Helper::JiraIssuesReleaseNotesHelper.initialize_jira(
17
+ host: params[:host],
18
+ api_version: params[:api_version],
19
+ username: params[:username],
20
+ password: params[:password],
21
+ context_path: params[:context_path],
22
+ disable_ssl_verification: params[:disable_ssl_verification]
23
+ )
24
+
25
+ issue_key_regex = Regexp.new("(#{params[:ticket_prefix]}-\\d+)")
26
+
27
+ Helper::JiraIssuesReleaseNotesHelper.get_keys_from_commit_after_latest_tag(
28
+ tag_regex: params[:tag_prefix],
29
+ tag_version_match: params[:tag_version_match],
30
+ issue_key_regex: issue_key_regex,
31
+ debug: params[:debug]
32
+ )
33
+ end
34
+
35
+ def self.description
36
+ "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
37
+ end
38
+
39
+ def self.authors
40
+ ["Erick Martins"]
41
+ end
42
+
43
+ def self.return_value
44
+ ["ABC-123", "ABC-321"]
45
+ end
46
+
47
+ def self.details
48
+ # Optional:
49
+ "It generates a release note based on the issues keys found in branch name and descriptions found in the commits"
50
+ end
51
+
52
+ def self.available_options
53
+ [
54
+ FastlaneCore::ConfigItem.new(
55
+ key: :tag_prefix,
56
+ description: "Match parameter of git describe. See man page of git describe for more info",
57
+ verify_block: proc do |value|
58
+ UI.user_error!("No match for analyze_commits action given, pass using `match: 'expr'`") unless value && !value.empty?
59
+ end
60
+ ),
61
+ FastlaneCore::ConfigItem.new(
62
+ key: :ticket_prefix,
63
+ env_name: 'FL_FIND_TICKETS_MATCHING',
64
+ description: 'regex to extract ticket numbers',
65
+ default_value: '[A-Z]+',
66
+ optional: true
67
+ ),
68
+ FastlaneCore::ConfigItem.new(
69
+ key: :tag_version_match,
70
+ description: "To parse version number from tag name",
71
+ default_value: '\d+\.\d+\.\d+'
72
+ ),
73
+
74
+ # Jira Client options
75
+ FastlaneCore::ConfigItem.new(
76
+ key: :username,
77
+ env_name: 'FL_JIRA_USERNAME',
78
+ description: 'Jira user',
79
+ optional: false
80
+ ),
81
+ FastlaneCore::ConfigItem.new(
82
+ key: :password,
83
+ env_name: 'FL_JIRA_PASSWORD',
84
+ description: 'Jira user',
85
+ optional: false
86
+ ),
87
+ FastlaneCore::ConfigItem.new(
88
+ key: :host,
89
+ env_name: 'FL_JIRA_HOST',
90
+ description: 'Jira location',
91
+ optional: false
92
+ ),
93
+ FastlaneCore::ConfigItem.new(
94
+ key: :api_version,
95
+ env_name: 'FL_JIRA_API_VERSION',
96
+ description: 'Jira api version',
97
+ default_value: '2',
98
+ optional: true,
99
+ ),
100
+ FastlaneCore::ConfigItem.new(
101
+ key: :context_path,
102
+ env_name: 'FL_JIRA_CONTEXT_PATH',
103
+ description: 'Jira context path',
104
+ optional: true,
105
+ default_value: ''
106
+ ),
107
+ FastlaneCore::ConfigItem.new(
108
+ key: :disable_ssl_verification,
109
+ env_name: 'FL_JIRA_DISABLE_SSL_VERIFICATION',
110
+ description: 'Jira SSL Verification mode',
111
+ optional: true,
112
+ default_value: false,
113
+ type: Boolean
114
+ ),
115
+ FastlaneCore::ConfigItem.new(
116
+ key: :debug,
117
+ description: "True if you want to log out a debug info",
118
+ default_value: false,
119
+ type: Boolean,
120
+ optional: true
121
+ )
122
+ ]
123
+ end
124
+
125
+ def self.is_supported?(platform)
126
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
127
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
128
+ #
129
+ # [:ios, :mac, :android].include?(platform)
130
+ true
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,182 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/jira_issues_release_notes_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+
7
+ module SharedValues
8
+ FL_JIRA_LAST_TAG ||= :S3_APK_OUTPUT_PATH
9
+ FL_JIRA_LAST_TAG_HASH ||= :FL_JIRA_LAST_TAG_HASH
10
+ FL_JIRA_COMMITS_FROM_HASH ||= :FL_JIRA_COMMITS_FROM_HASH
11
+ FL_JIRA_LAST_KEYS_FROM_COMMITS ||= :FL_JIRA_LAST_KEYS_FROM_COMMITS
12
+ FL_JIRA_LAST_ISSUES_FROM_COMMITS ||= :FL_JIRA_LAST_ISSUES_FROM_COMMITS
13
+ end
14
+
15
+ class JiraReleaseChangelogAction < Action
16
+ def self.run(params)
17
+ Helper::JiraIssuesReleaseNotesHelper.initialize_jira(
18
+ host: params[:host],
19
+ api_version: params[:api_version],
20
+ username: params[:username],
21
+ password: params[:password],
22
+ context_path: params[:context_path],
23
+ disable_ssl_verification: params[:disable_ssl_verification]
24
+ )
25
+
26
+ issue_key_regex = Regexp.new("(#{params[:ticket_prefix]}-\\d+)")
27
+
28
+ issues = Helper::JiraIssuesReleaseNotesHelper.get_issues_from_commit_after_latest_tag(
29
+ tag_regex: params[:tag_prefix],
30
+ tag_version_match: params[:tag_version_match],
31
+ issue_key_regex: issue_key_regex,
32
+ debug: params[:debug]
33
+ )
34
+
35
+ return '' unless issues
36
+
37
+ @format = params[:format]
38
+ @format_line_break = @format === 'html' ? '<br />' : "\n"
39
+
40
+ grouped_by_types = params[:grouped_by_types]
41
+
42
+ grouped_issues = {}
43
+
44
+ group_key_for_any = nil
45
+
46
+ grouped_by_types.each do |key, value|
47
+ matched_issues = issues.select {|issue| value.include?(issue.issuetype.name) }
48
+ not_matched_issues = issues.select {|issue| !value.include?(issue.issuetype.name) }
49
+
50
+ grouped_issues[key] = matched_issues
51
+
52
+ issues = not_matched_issues
53
+
54
+ group_key_for_any = key if value.include? "ANY_TYPE"
55
+ end
56
+
57
+ if group_key_for_any and issues then
58
+ grouped_issues[group_key_for_any].concat issues
59
+ end
60
+
61
+ Helper::JiraIssuesReleaseNotesHelper.generate_changelog(
62
+ groups: grouped_issues,
63
+ line_break_format: @format_line_break
64
+ )
65
+ end
66
+
67
+ def self.description
68
+ "It generates a release note based on the issues keys and descriptions found in the commits"
69
+ end
70
+
71
+ def self.authors
72
+ ["Erick Martins"]
73
+ end
74
+
75
+ def self.return_value
76
+ # If your method provides a return value, you can describe here what it does
77
+ end
78
+
79
+ def self.details
80
+ # Optional:
81
+ "It generates a release note based on the issues keys and descriptions found in the commits"
82
+ end
83
+
84
+ def self.available_options
85
+ [
86
+ FastlaneCore::ConfigItem.new(
87
+ key: :tag_prefix,
88
+ description: "Match parameter of git describe. See man page of git describe for more info",
89
+ verify_block: proc do |value|
90
+ UI.user_error!("No match for analyze_commits action given, pass using `match: 'expr'`") unless value && !value.empty?
91
+ end
92
+ ),
93
+ FastlaneCore::ConfigItem.new(
94
+ key: :ticket_prefix,
95
+ env_name: 'FL_FIND_TICKETS_MATCHING',
96
+ description: 'regex to extract ticket numbers',
97
+ default_value: '[A-Z]+',
98
+ optional: true
99
+ ),
100
+ FastlaneCore::ConfigItem.new(
101
+ key: :tag_version_match,
102
+ description: "To parse version number from tag name",
103
+ default_value: '\d+\.\d+\.\d+'
104
+ ),
105
+ FastlaneCore::ConfigItem.new(
106
+ key: :grouped_by_types,
107
+ env_name: 'FL_JIRA_RELESE_GROUPED_TYPES',
108
+ description: 'Hash with grouped types with names by issue type. Use de key work "ANY_TYPE" as fallback. Example: { "Fixed" => ["Bug"], "Added/Changed" => ["Story", "Task"], "Others" => ["ANY_TYPE"] } ',
109
+ optional: false,
110
+ type: Hash
111
+ ),
112
+ FastlaneCore::ConfigItem.new(
113
+ key: :format,
114
+ description: "You can use either markdown, slack, html or plain",
115
+ default_value: "markdown",
116
+ optional: true,
117
+ verify_block: proc do |value|
118
+ UI.user_error!("Invalid format! You can use either markdown, slack, html or plain") unless ['markdown', 'html', 'slack', 'plain'].include?(value)
119
+ end
120
+ ),
121
+
122
+ # Jira Client options
123
+ FastlaneCore::ConfigItem.new(
124
+ key: :username,
125
+ env_name: 'FL_JIRA_USERNAME',
126
+ description: 'Jira user',
127
+ optional: false
128
+ ),
129
+ FastlaneCore::ConfigItem.new(
130
+ key: :password,
131
+ env_name: 'FL_JIRA_PASSWORD',
132
+ description: 'Jira user password',
133
+ optional: false
134
+ ),
135
+ FastlaneCore::ConfigItem.new(
136
+ key: :host,
137
+ env_name: 'FL_JIRA_HOST',
138
+ description: 'Jira location',
139
+ optional: false
140
+ ),
141
+ FastlaneCore::ConfigItem.new(
142
+ key: :api_version,
143
+ env_name: 'FL_JIRA_API_VERSION',
144
+ description: 'Jira api version',
145
+ default_value: '2',
146
+ optional: true,
147
+ ),
148
+ FastlaneCore::ConfigItem.new(
149
+ key: :context_path,
150
+ env_name: 'FL_JIRA_CONTEXT_PATH',
151
+ description: 'Jira context path',
152
+ optional: true,
153
+ default_value: ''
154
+ ),
155
+ FastlaneCore::ConfigItem.new(
156
+ key: :disable_ssl_verification,
157
+ env_name: 'FL_JIRA_DISABLE_SSL_VERIFICATION',
158
+ description: 'Jira SSL Verification mode',
159
+ optional: true,
160
+ default_value: false,
161
+ type: Boolean
162
+ ),
163
+ FastlaneCore::ConfigItem.new(
164
+ key: :debug,
165
+ description: "True if you want to log out a debug info",
166
+ default_value: false,
167
+ type: Boolean,
168
+ optional: true
169
+ )
170
+ ]
171
+ end
172
+
173
+ def self.is_supported?(platform)
174
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
175
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
176
+ #
177
+ # [:ios, :mac, :android].include?(platform)
178
+ true
179
+ end
180
+ end
181
+ end
182
+ end