Class: ReleaseNotes::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/release_notes/cli.rb,
lib/release_notes/cli/helpers.rb

Defined Under Namespace

Classes: Helpers

Instance Method Summary collapse

Instance Method Details

#newObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/release_notes/cli.rb', line 21

def new
  if options[:version].nil?
    last_version = ReleaseNotes::Versioning.current_version_number(options[:destination])
    update_version = ReleaseNotes::Versioning::Semantic.increment(last_version, options[:increment])
  else
    update_version = options[:version]
  end

  message = ReleaseNotes::CLI::Helpers.setup_message_obj

  if options[:message]
    message = ReleaseNotes::CLI::Helpers.interactive_bullets(message)        
  end

  ReleaseNotes::Generators::ReleaseNote.start([options[:destination],
                                               message,
                                               update_version,
                                               "--force=#{options[:force] || false}"])
end

#updateObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/release_notes/cli.rb', line 47

def update
  # If reset option is passed delete all release notes in model
  if options[:reset]
    stamp = nil
    release_log = ""

    begin
      File.delete("#{options[:destination]}/README.md")
    rescue Errno::ENOENT
      # Nothing to see here... move along.
    end

    ReleaseNotes.release_note_model.constantize.all.each do |rn|
      rn.destroy
    end
  else
    # Checks timestamp of last release note stored
    begin
      stamp = File.read("#{options[:destination]}/stamp")
    rescue Errno::ENOENT
      stamp = nil
    end

    # Reads contents of release note compilation file
    begin
      release_log = File.read("#{options[:destination]}/README.md")
    rescue Errno::ENOENT
      release_log = ""
    end
  end

  # Collects relevant files and saves version and content to db
  update_files = collect_update_files(options[:destination])
  update_files.reverse if options[:reset]
  
  update_files.each do |file|
    timestamp = file[0].to_i

    if !stamp.nil? and timestamp <= stamp.to_i
      next
    end 

    version = file[1..4].join('.')[0..-4]

    file = file.join('_')
    markdown = File.read("#{options[:destination]}/#{file}")
    ReleaseNotes.release_note_model.constantize.create(version: version,
                                                       markdown: markdown)

    release_log.insert(0, "#{markdown}\n\n---\n\n") unless options[:no_log]
  end

  # Store the timestamp of the last release note
  new_stamp = latest_update_file(options[:destination])
  File.write("#{options[:destination]}/stamp", "#{new_stamp}", mode: 'w')

  # Store release note compilation file
  File.write("#{options[:destination]}/README.md", "#{release_log}", mode: 'w') unless options[:no_log]

  say "#{ReleaseNotes.release_note_model} model successfully updated.", :green
  say "ReleaseNotes log successfully updated (see #{options[:destination]}/README.md).", :green unless options[:no_log]
end

#versionObject



113
114
115
# File 'lib/release_notes/cli.rb', line 113

def version
  puts "ReleaseNotes v#{ReleaseNotes::VERSION}"
end