Class: Fastlane::Actions::ConventionalChangelogAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::ConventionalChangelogAction
- Defined in:
- lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb
Overview
TODO Add version_override param
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .return_value ⇒ Object
Class Method Summary collapse
- .build_commit_link(commit, commit_url, format) ⇒ Object
- .get_commits_from_hash(params) ⇒ Object
- .note_builder(format, commits, version, commit_url, params) ⇒ Object
- .parse_commits(squashed_commits, params) ⇒ Object
- .run(params) ⇒ Object
- .style_text(text, format, style) ⇒ Object
Class Method Details
.authors ⇒ Object
361 362 363 364 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 361 def self. # So no one will ever forget your contribution to fastlane :) You are awesome btw! ["xotahal"] end |
.available_options ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 260 def self. # Define all options your action supports. # Below a few examples [ FastlaneCore::ConfigItem.new( key: :format, description: "You can use either markdown, slack or plain", default_value: "markdown", optional: true ), FastlaneCore::ConfigItem.new( key: :title, description: "Title for release notes", optional: true ), FastlaneCore::ConfigItem.new( key: :commit_url, description: "Uses as a link to the commit", optional: true ), FastlaneCore::ConfigItem.new( key: :order, description: "You can change the order of groups in release notes", default_value: ["feat", "fix", "refactor", "perf", "chore", "style", "test", "docs", "no_type"], type: Array, optional: true ), FastlaneCore::ConfigItem.new( key: :sections, description: "Map type to section title", default_value: { build: "Building system", ci: "CICD", feat: "Features", fix: "Bug fixes", refactor: "Code refactoring", perf: "Performance improvements", chore: "Chores", test: "Testing", docs: "Documentation", style: "Stylistic", no_type: "Other work" }, type: Hash, optional: true ), FastlaneCore::ConfigItem.new( key: :display_author, description: "Whether you want to show the author of the commit", default_value: false, type: Boolean, optional: true ), FastlaneCore::ConfigItem.new( key: :display_title, description: "Whether you want to hide the title/header with the version details at the top of the changelog", default_value: true, type: Boolean, optional: true ), FastlaneCore::ConfigItem.new( key: :display_links, description: "Whether you want to display the links to commit IDs", default_value: false, type: Boolean, optional: true ), FastlaneCore::ConfigItem.new( key: :ignore_scopes, description: "To ignore certain scopes when calculating releases", default_value: [], type: Array, optional: true ), FastlaneCore::ConfigItem.new( key: :debug, description: "True if you want to log out a debug info", default_value: false, type: Boolean, optional: true ), FastlaneCore::ConfigItem.new( key: :version_override, description: "Allow overriding version number rather than letting it be calculated here. Useful for prod build matching beta version", optional: true ) ] end |
.build_commit_link(commit, commit_url, format) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 160 def self.build_commit_link(commit, commit_url, format) # formats the link according to the output format we need short_hash = commit[:short_hash] hash = commit[:hash] url = "#{commit_url}/#{hash}" case format when "slack" "<#{url}|#{short_hash}>" when "markdown" "[#{short_hash}](#{url})" else url end end |
.description ⇒ Object
252 253 254 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 252 def self.description "Get commits since last version and generates release notes" end |
.details ⇒ Object
256 257 258 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 256 def self.details "Uses conventional commits. It groups commits by their types and generates release notes in markdown or slack format." end |
.get_commits_from_hash(params) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 11 def self.get_commits_from_hash(params) commits = Helper::BetterSemanticReleaseHelper.git_log( pretty: '%s|%b|%H|%h|%an|%at|>', start: params[:hash], debug: params[:debug] ) commits.split("|>") end |
.is_supported?(platform) ⇒ Boolean
366 367 368 369 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 366 def self.is_supported?(platform) # you can do things like true end |
.note_builder(format, commits, version, commit_url, params) ⇒ Object
49 50 51 52 53 54 55 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 49 def self.note_builder(format, commits, version, commit_url, params) sections = params[:sections] result = "" # Begining of release notes if params[:display_title] == true title = version title += " #{params[:title]}" if params[:title] title += " (#{Date.today})" result = style_text(title, format, "title").to_s result += "\n\n" end params[:order].each do |type| # write section only if there is at least one commit next if commits.none? { |commit| commit[:type] == type } result += style_text(sections[type.to_sym], format, "heading").to_s result += "\n" commits.each do |commit| next if commit[:type] != type || commit[:is_merge] result += "-" unless commit[:scope].nil? formatted_text = style_text("#{commit[:scope]}:", format, "bold").to_s result += " #{formatted_text}" end result += " #{commit[:subject]}" if params[:display_links] == true styled_link = build_commit_link(commit, commit_url, format).to_s result += " (#{styled_link})" end if params[:display_author] result += " - #{commit[:author_name]}" end result += "\n" end result += "\n" end if commits.any? { |commit| commit[:is_breaking_change] == true } result += style_text("BREAKING CHANGES", format, "heading").to_s result += "\n" commits.each do |commit| next unless commit[:is_breaking_change] result += "- #{commit[:breaking_change]}" # This is the only unique part of this loop if params[:display_links] == true styled_link = build_commit_link(commit, commit_url, format).to_s result += " (#{styled_link})" end if params[:display_author] result += " - #{commit[:author_name]}" end result += "\n" end result += "\n" end # Trim any trailing newlines result = result.rstrip! result end |
.output ⇒ Object
350 351 352 353 354 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 350 def self.output # Define the shared values you are going to provide # Example [] end |
.parse_commits(squashed_commits, params) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 176 def self.parse_commits(squashed_commits, params) parsed = [] # %s|%b|%H|%h|%an|%at format_pattern = lane_context[SharedValues::CONVENTIONAL_CHANGELOG_ACTION_FORMAT_PATTERN] squashed_commits.each do |squashed_commit| commits = squashed_commit.split("*") # This works for Bitbucket #commits.drop(1).each do |line| # This works for Gitlab commits.each do |line| splitted = line.split("|") # This is a regular commit # every `line` in commits array has it's own hash and other info if splitted.length() > 1 commit = Helper::BetterSemanticReleaseHelper.parse_commit( commit_subject: splitted[0], commit_body: splitted[1], pattern: format_pattern ) unless commit[:scope].nil? # if this commit has a scope, then we need to inspect to see if that is one of the scopes we're trying to exclude scope = commit[:scope] scopes_to_ignore = params[:ignore_scopes] # if it is, we'll skip this commit when bumping versions next if scopes_to_ignore.include?(scope) #=> true end commit[:hash] = splitted[2] commit[:short_hash] = splitted[3] commit[:author_name] = splitted[4] commit[:commit_date] = splitted[5] parsed.push(commit) # This is a rebased-squash commit # Every line is one commit message but hash and other details # are on the very last `line` in the commits array. elsif # Skip any empty space unless line.to_s.strip.empty? # Split last commit since that's the squashed commit that has the extra details on it for all these commits splitted = commits[commits.length() -1] commit = Helper::BetterSemanticReleaseHelper.parse_commit( commit_subject: line.to_s.strip, commit_body: "", pattern: format_pattern ) unless commit[:scope].nil? # if this commit has a scope, then we need to inspect to see if that is one of the scopes we're trying to exclude scope = commit[:scope] scopes_to_ignore = params[:ignore_scopes] # if it is, we'll skip this commit when bumping versions next if scopes_to_ignore.include?(scope) #=> true end commit[:hash] = splitted[2] commit[:short_hash] = splitted[3] commit[:author_name] = splitted[4] commit[:commit_date] = splitted[5] parsed.push(commit) end end end end parsed end |
.return_value ⇒ Object
356 357 358 359 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 356 def self.return_value # If your method provides a return value, you can describe here what it does "Returns generated release notes as a string" end |
.run(params) ⇒ Object
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 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 20 def self.run(params) # Get next version number from shared values analyzed = lane_context[SharedValues::RELEASE_ANALYZED] # If analyze commits action was not run there will be no version in shared # values. We need to run the action to get next version number unless analyzed UI.user_error!("Release hasn't been analyzed yet. Run analyze_commits action first please.") # version = other_action.analyze_commits(match: params[:match]) end last_tag_hash = lane_context[SharedValues::RELEASE_LAST_TAG_HASH] version = params[:version_override] ? params[:version_override] : lane_context[SharedValues::RELEASE_NEXT_VERSION] # Get commits log between last version and head commits = get_commits_from_hash( hash: last_tag_hash, debug: params[:debug] ) parsed = parse_commits(commits, params) commit_url = params[:commit_url] format = params[:format] result = note_builder(format, parsed, version, commit_url, params) result end |
.style_text(text, format, style) ⇒ Object
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 |
# File 'lib/fastlane/plugin/better_semantic_release/actions/conventional_changelog.rb', line 126 def self.style_text(text, format, style) # formats the text according to the style we're looking to use # Skips all styling case style when "title" if format == "markdown" "# #{text}" elsif format == "slack" "*#{text}*" else text end when "heading" if format == "markdown" "### #{text}" elsif format == "slack" "*#{text}*" else "#{text}:" end when "bold" if format == "markdown" "**#{text}**" elsif format == "slack" "*#{text}*" else text end else text # catchall, shouldn't be needed end end |