Class: Fastlane::Helper::ChangelogHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/changelog/helper/changelog_helper.rb

Overview

TODO: Add unit tests for methods in this class

Class Method Summary collapse

Class Method Details

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.message('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.message("Cannot find CHANGELOG.md at #{path}")
    generate_changelog
    CHANGELOG_PATH
  end
end

.generate_changelogObject

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

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.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) ⇒ 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