Class: Fastlane::Helper::ChangelogHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::ChangelogHelper
- Defined in:
- lib/fastlane/plugin/changelog/helper/changelog_helper.rb
Overview
TODO: Add unit tests for methods in this class
Class Method Summary collapse
-
.compose_comparison_link(repo_url) ⇒ Object
Composes link for tag comparison for GitHub or Bitbucket.
-
.ensure_changelog_exists(path) ⇒ Object
Ensures CHANGELOG.md exists at given path.
-
.generate_changelog ⇒ Object
Generates CHANGELOG.md in project root.
-
.generate_comparison_link ⇒ Object
Generates link for tag comparison.
- .get_line_separator(file_path) ⇒ Object
-
.write_to_changelog(changelog) ⇒ Object
Writes given content to CHANGELOG.md in project root.
Class Method Details
.compose_comparison_link(repo_url) ⇒ Object
Composes link for tag comparison for GitHub or Bitbucket
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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.('Creating CHANGELOG.md without links for comparing tags') write_to_changelog(DEFAULT_CHANGELOG) end end |
.ensure_changelog_exists(path) ⇒ Object
Ensures CHANGELOG.md exists at given path. If not, offers to create a default one. Returns path to CHANGELOG.md to be used
18 19 20 21 22 23 24 25 26 27 |
# 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.("Cannot find CHANGELOG.md at #{path}") generate_changelog CHANGELOG_PATH end end |
.generate_changelog ⇒ Object
Generates CHANGELOG.md in project root
30 31 32 33 34 35 36 37 |
# 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 ⇒ Object
Generates link for tag comparison
40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/changelog/helper/changelog_helper.rb', line 40 def self.generate_comparison_link FastlaneCore::UI.('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) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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) ⇒ Object
Writes given content to CHANGELOG.md in project root
66 67 68 69 |
# 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 |