Class: Fastlane::Helper::JiraIssuesReleaseNotesHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::JiraIssuesReleaseNotesHelper
show all
- Defined in:
- lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb
Defined Under Namespace
Classes: JiraClientHelper, JiraHelper
Class Method Summary
collapse
-
.extract_key_from_branch(branch:, ticket_prefix:) ⇒ Object
-
.format_issue_link(issue:) ⇒ Object
-
.format_issues(label:, issues:) ⇒ Object
-
.generate_changelog(groups:, line_break_format:) ⇒ Object
-
.get_commit_after_latest_tag(tag_regex:, tag_version_match:, debug:) ⇒ Object
-
.get_issues_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:) ⇒ Object
-
.get_key_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:) ⇒ Object
-
.git_log(params) ⇒ Object
-
.initialize_jira(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:) ⇒ Object
-
.jira_helper(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:) ⇒ Object
-
.style_text(text:, style:) ⇒ Object
Class Method Details
183
184
185
186
187
188
189
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 183
def self.(branch:, ticket_prefix:)
regex = Regexp.new("(#{ticket_prefix}-\\d+)")
ticket_code = regex.match branch
ticket_code
end
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 10
def self.format_issue_link(issue:)
link = @jira_helper.url(issue: issue)
case @format
when "slack"
"*<#{link}|#{issue.key}>*: #{issue.summary}"
when "markdown"
"- **[#{issue.key}](#{link})**: #{issue.summary}"
when "html"
" - <strong><a href=\"#{link}\" target=\"_blank\">#{issue.key}</a><strong>: #{issue.summary}"
else
"- #{issue.key}: #{issue.summary} (#{link})"
end
end
|
176
177
178
179
180
181
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 176
def self.format_issues(label:, issues:)
[
style_text(text: "► #{label}", style: 'heading'),
issues.map { |issue| format_issue_link(issue: issue) }
].flatten!
end
|
.generate_changelog(groups:, line_break_format:) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 164
def self.generate_changelog(groups:, line_break_format:)
changelog = []
groups.each do |label, issues|
changelog.concat(['']) unless changelog.to_s.empty?
changelog.concat(format_issues(label: label, issues: issues)) unless issues.empty?
end
changelog.join(line_break_format)
end
|
.get_commit_after_latest_tag(tag_regex:, tag_version_match:, debug:) ⇒ Object
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_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 68
def self.get_commit_after_latest_tag(tag_regex:, tag_version_match:, debug:)
unless Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_COMMITS_FROM_HASH] then
command = "git describe --tags --match=#{tag_regex}"
tag = Actions.sh(command, log: debug)
if tag.empty?
UI.message("First commit of the branch is taken as a begining of next release")
hash = Actions.sh('git rev-list --max-parents=0 HEAD', log: debug).chomp
else
tag_name = tag.split('-')[0...-2].join('-').strip
parsed_version = tag_name.match(tag_version_match)
if parsed_version.nil?
UI.user_error!("Error while parsing version from tag #{tag_name} by using tag_version_match - #{tag_version_match}. Please check if the tag contains version as you expect and if you are using single brackets for tag_version_match parameter.")
end
version = parsed_version[0]
command = "git rev-list -n 1 refs/tags/#{tag_name}"
hash = Actions.sh(command, log: debug).chomp
UI.message("Found a tag #{tag_name} associated with version #{version}")
end
commits = git_log(
pretty: '%s|%b|>',
start: hash,
debug: debug
)
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_TAG] = tag
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_TAG_HASH] = hash
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_COMMITS_FROM_HASH] = commits
end
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_COMMITS_FROM_HASH]
rescue StandardError => error
UI.error error.message
UI.message("Tag was not found for match pattern - #{tag_regex}")
nil
end
|
.get_issues_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 139
def self.get_issues_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:)
unless Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_ISSUES_FROM_COMMITS] then
unless @jira_helper then
UI.user_error! "Uninitialized jira client"
end
keys = get_key_from_commit_after_latest_tag(
tag_regex: tag_regex,
tag_version_match: tag_version_match,
issue_key_regex: issue_key_regex,
debug: debug
)
issues = @jira_helper.get(keys: keys)
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_ISSUES_FROM_COMMITS] = issues
end
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_ISSUES_FROM_COMMITS]
end
|
.get_key_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 117
def self.get_key_from_commit_after_latest_tag(tag_regex:, tag_version_match:, issue_key_regex:, debug:)
unless Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_KEYS_FROM_COMMITS] then
commits = get_commit_after_latest_tag(
tag_regex: tag_regex,
tag_version_match: tag_version_match,
debug: debug,
)
return nil unless commits
last_keys_from_commits = commits
.to_enum(:scan, issue_key_regex)
.map { $& }
.reject(&:empty?)
.uniq
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_KEYS_FROM_COMMITS] = last_keys_from_commits
end
Actions.lane_context[Fastlane::Actions::SharedValues::FL_JIRA_LAST_KEYS_FROM_COMMITS]
end
|
.git_log(params) ⇒ Object
159
160
161
162
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 159
def self.git_log(params)
command = "git log --pretty='#{params[:pretty]}' --reverse #{params[:start]}..HEAD"
Actions.sh(command, log: params[:debug]).chomp
end
|
.initialize_jira(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 192
def self.initialize_jira(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:)
unless @jira_helper then
@jira_helper = jira_helper(
host: host,
api_version: api_version,
username: username,
password: password,
context_path: context_path,
disable_ssl_verification: disable_ssl_verification
)
end
@jira_helper
end
|
.jira_helper(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:) ⇒ Object
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 207
def self.jira_helper(host:, api_version:, username:, password:, context_path:, disable_ssl_verification:)
JiraHelper.new(
host: host,
api_version: api_version,
username: username,
password: password,
context_path: context_path,
disable_ssl_verification: disable_ssl_verification
)
end
|
.style_text(text:, style:) ⇒ Object
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/fastlane/plugin/jira_issues_release_notes/helper/jira_issues_release_notes_helper.rb', line 25
def self.style_text(text:, style:)
case style
when "title"
case @format
when "markdown"
"# #{text}"
when "slack"
"*#{text}*"
when "html"
"<h1>#{text}</h1>"
else
text
end
when "heading"
case @format
when "markdown"
"### #{text}"
when "slack"
"*#{text}*"
when "html"
"<h3>#{text}</h3>"
else
"#{text}:"
end
when "bold"
case @format
when "markdown"
"**#{text}**"
when "slack"
"*#{text}*"
when "html"
"<strong>#{text}</strong>"
else
text
end
else
text end
end
|