class Fastlane::Helper::ChangelogHelper
TODO: Add unit tests for methods in this class
Public Class Methods
compose_comparison_link(repo_url)
click to toggle source
Composes link for tag comparison for GitHub or Bitbucket
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 51 def self.compose_comparison_link(repo_url) if repo_url.start_with?('https://github.com') output = DEFAULT_CHANGELOG + "\n\n[Unreleased]: #{repo_url}/compare/master...HEAD" write_to_changelog(output) elsif repo_url.start_with?('https://bitbucket.org') output = DEFAULT_CHANGELOG + "\n\n[Unreleased]: #{repo_url}/compare/master..HEAD" write_to_changelog(output) else FastlaneCore::UI.error('Unknown repository host') FastlaneCore::UI.message('Creating CHANGELOG.md without links for comparing tags') write_to_changelog(DEFAULT_CHANGELOG) end end
ensure_changelog_exists(path)
click to toggle source
Ensures CHANGELOG.md exists at given path. If not, offers to create a default one. Returns path to CHANGELOG.md to be used
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 18 def self.ensure_changelog_exists(path) if File.exist?(path) FastlaneCore::UI.success "Found CHANGELOG.md at #{path}" path else FastlaneCore::UI.message("Cannot find CHANGELOG.md at #{path}") generate_changelog CHANGELOG_PATH end end
generate_changelog()
click to toggle source
Generates CHANGELOG.md in project root
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 30 def self.generate_changelog if FastlaneCore::UI.confirm('Do you want to generate default CHANGELOG.md in the project root?') FileUtils.touch 'CHANGELOG.md' generate_comparison_link else FastlaneCore::UI.error("Cannot continue without CHANGELOG.md file") end end
generate_comparison_link()
click to toggle source
Generates link for tag comparison
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 40 def self.generate_comparison_link FastlaneCore::UI.message('Changelog plugin can automaticaly create a link for comparison between two tags (see https://github.com/pajapro/fastlane-plugin-changelog#--stamp_changelog)') if FastlaneCore::UI.confirm('Do you want to create links for comparing tags?') repo_url = FastlaneCore::UI.input('Enter your GitHub or Bitbucket repository URL (e.g.: https://github.com/owner/project or https://bitbucket.org/owner/project):') compose_comparison_link(repo_url) else write_to_changelog(DEFAULT_CHANGELOG) end end
get_line_separator(file_path)
click to toggle source
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 71 def self.get_line_separator(file_path) f = File.open(file_path) enum = f.each_char c = enum.next loop do case c[/\r|\n/] when "\n" then break when "\r" c << "\n" if enum.peek == "\n" break end c = enum.next end c[0][/\r|\n/] ? c : "\n" end
write_to_changelog(changelog)
click to toggle source
Writes given content to CHANGELOG.md in project root
# File lib/fastlane/plugin/changelog/helper/changelog_helper.rb, line 66 def self.write_to_changelog(changelog) File.open(CHANGELOG_PATH, 'w') { |f| f.write(changelog) } FastlaneCore::UI.success('Successfully created CHANGELOG.md') end