Created
July 1, 2020 13:35
-
-
Save jpignata/7859c7c3b6302e2126561ab591d2d18d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fastlane/action' | |
require_relative '../helper/git' | |
require_relative '../helper/changelog/document' | |
module Fastlane | |
module Actions | |
class BuildChangelogAction < Action | |
def self.run(params) | |
version = params[:version] | |
commits = params[:commits] | |
features = commits.select(&:feat?) | |
fixes = commits.select(&:fix?) | |
breaking_changes = commits.select(&:breaking_change?) | |
changelog = Changelog::Document.new | |
changelog.header(2) { link("https://github.com/#{Git.repo_name}/releases/tag/#{version}", version) } | |
if features.any? | |
changelog.header(3) { 'Features' } | |
changelog.unordered_list do | |
features.map do |change| | |
change.scope ? "#{bold(change.scope)}: #{change.subject}" : change.subject | |
end | |
end | |
end | |
if fixes.any? | |
changelog.header(3) { 'Fixes' } | |
changelog.unordered_list do | |
fixes.map do |change| | |
change.scope ? "#{bold(change.scope)}: #{change.subject}" : change.subject | |
end | |
end | |
end | |
if breaking_changes.any? | |
changelog.header(3) { 'BREAKING CHANGES' } | |
changelog.unordered_list { breaking_changes.map(&:breaking_change) } | |
end | |
changelog | |
end | |
def self.description | |
'Builds a changelog from conventional commits.' | |
end | |
def self.authors | |
['John Pignata', 'Ivan Artemiev'] | |
end | |
def self.available_options | |
[ | |
FastlaneCore::ConfigItem.new( | |
key: :version, | |
description: 'The version with which the changelog is associated', | |
optional: false, | |
type: String | |
), | |
FastlaneCore::ConfigItem.new( | |
key: :commits, | |
description: 'The commits to use to build the changelog', | |
optional: false, | |
type: Commits | |
) | |
] | |
end | |
def self.is_supported?(platform) | |
true | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment