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 options[:reset]
stamp = nil
release_log = ""
begin
File.delete("#{options[:destination]}/README.md")
rescue Errno::ENOENT
end
ReleaseNotes.release_note_model.constantize.all.each do |rn|
rn.destroy
end
else
begin
stamp = File.read("#{options[:destination]}/stamp")
rescue Errno::ENOENT
stamp = nil
end
begin
release_log = File.read("#{options[:destination]}/README.md")
rescue Errno::ENOENT
release_log = ""
end
end
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
new_stamp = latest_update_file(options[:destination])
File.write("#{options[:destination]}/stamp", "#{new_stamp}", mode: 'w')
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
|