From 3a9ea26425ab57f1686fdaa78372c8253586b8e0 Mon Sep 17 00:00:00 2001 From: Adonis Peralta <1881038+donileo@users.noreply.github.com> Date: Sat, 6 Mar 2021 13:04:20 -0500 Subject: [PATCH] Refactor to allow passing in a datetime format instead. Date time format is in Ruby's strftime format and is not required. If not passed no date is stamped on the changelog section. --- .../changelog/actions/stamp_changelog.rb | 26 ++++++----------- .../changelog/actions/update_changelog.rb | 29 +++++++------------ 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/lib/fastlane/plugin/changelog/actions/stamp_changelog.rb b/lib/fastlane/plugin/changelog/actions/stamp_changelog.rb index 30fe2f6..21ba7ec 100644 --- a/lib/fastlane/plugin/changelog/actions/stamp_changelog.rb +++ b/lib/fastlane/plugin/changelog/actions/stamp_changelog.rb @@ -14,22 +14,20 @@ def self.run(params) UI.important("WARNING: No changes in [Unreleased] section to stamp!") else section_identifier = params[:section_identifier] unless params[:section_identifier].to_s.empty? - stamp_date_time = params[:stamp_date_time] - stamp_date = params[:stamp_date_time] ? false : params[:stamp_date] + stamp_datetime_format = params[:stamp_datetime_format] git_tag = params[:git_tag] placeholder_line = params[:placeholder_line] - stamp(changelog_path, section_identifier, stamp_date, stamp_date_time, git_tag, placeholder_line) + stamp(changelog_path, section_identifier, stamp_datetime_format, git_tag, placeholder_line) end end - def self.stamp(changelog_path, section_identifier, stamp_date, stamp_date_time, git_tag, placeholder_line) + def self.stamp(changelog_path, section_identifier, stamp_datetime_format, git_tag, placeholder_line) # 1. Update [Unreleased] section with given identifier Actions::UpdateChangelogAction.run(changelog_path: changelog_path, section_identifier: UNRELEASED_IDENTIFIER, updated_section_identifier: section_identifier, - append_date: stamp_date, - append_date_time: stamp_date_time, + append_datetime_format: stamp_datetime_format, excluded_placeholder_line: placeholder_line) file_content = "" @@ -131,17 +129,11 @@ def self.available_options env_name: "FL_STAMP_CHANGELOG_SECTION_IDENTIFIER", description: "The unique section identifier to stamp the [Unreleased] section with", is_string: true), - FastlaneCore::ConfigItem.new(key: :stamp_date, - env_name: "FL_STAMP_CHANGELOG_SECTION_STAMP_DATE", - description: "Specifies whether the current UTC date should be appended to section identifier", - default_value: true, - is_string: false, - optional: true), - FastlaneCore::ConfigItem.new(key: :stamp_date_time, - env_name: "FL_STAMP_CHANGELOG_SECTION_STAMP_DATE_TIME", - description: "Specifies whether the current UTC date and time should be appended to section identifier", - default_value: false, - is_string: false, + FastlaneCore::ConfigItem.new(key: :append_datetime_format, + env_name: "FL_STAMP_CHANGELOG_DATETIME_FORMAT", + description: "The strftime format string to use for the date in the stamped section", + default_value: '%Y-%m-%dZ', + is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :git_tag, env_name: "FL_STAMP_CHANGELOG_GIT_TAG", diff --git a/lib/fastlane/plugin/changelog/actions/update_changelog.rb b/lib/fastlane/plugin/changelog/actions/update_changelog.rb index 0347bcd..d6fed78 100644 --- a/lib/fastlane/plugin/changelog/actions/update_changelog.rb +++ b/lib/fastlane/plugin/changelog/actions/update_changelog.rb @@ -48,14 +48,11 @@ def self.run(params) line_old = line.dup line.sub!(section_name, new_section_identifier) - if params[:append_date_time] || params[:append_date] - if params[:append_date_time] - now = Time.now.utc.iso8601 - ENV["FL_UPDATE_APPEND_DATE_TIME_VAL"] = now - else - now = Time.now.utc.strftime("%Y-%m-%d") - ENV["FL_UPDATE_APPEND_DATE_VAL"] = now - end + append_datetime_format = params[:append_datetime_format] + + if append_datetime_format + now = Time.now.utc.strftime(append_datetime_format) + ENV["FL_UPDATE_APPEND_DATETIME_VAL"] = now line.concat(" - " + now) line.delete!(line_separator) # remove line break, because concatenation adds line break between section identifer & date @@ -121,17 +118,11 @@ def self.available_options description: "The updated unique section identifier (without square brackets)", is_string: true, optional: true), - FastlaneCore::ConfigItem.new(key: :append_date, - env_name: "FL_UPDATE_CHANGELOG_APPEND_DATE", - description: "Appends the current UTC date in YYYY-MM-DD format after the section identifier", - default_value: true, - is_string: false, - optional: true), - FastlaneCore::ConfigItem.new(key: :append_date_time, - env_name: "FL_UPDATE_CHANGELOG_APPEND_DATE_TIME", - description: "Appends the current UTC date in YYYY-MM-DDTHH:MM:SSZ format after the section identifier", - default_value: false, - is_string: false, + FastlaneCore::ConfigItem.new(key: :append_datetime_format, + env_name: "FL_UPDATE_CHANGELOG_APPEND_DATETIME_FORMAT", + description: "The strftime format string to use for the date after the section identifier", + default_value: '%Y-%m-%dZ', + is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :excluded_placeholder_line, env_name: "FL_UPDATE_CHANGELOG_EXCLUDED_PLACEHOLDER_LINE",