Top Level Namespace

Defined Under Namespace

Modules: OS Classes: GemspecVersioner, JsonVersioner, TomlVersioner, Version, Versioner

Instance Method Summary collapse

Instance Method Details

#assert_tag_exists(version) ⇒ Object



235
236
237
# File 'lib/rake-extensions.rb', line 235

def assert_tag_exists(version)
  raise "tag #{version} missing" if `git tag -l #{version}`.length == 0
end

#create_changelog(current_version, next_version) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/rake-extensions.rb', line 238

def create_changelog(current_version, next_version)
  sha1s = `git log #{current_version}..HEAD --oneline`.strip.split(/\n/).collect { |line| line.split(' ').first }
  log_entries = []
  sha1s.each do |sha1|
    raw_log = `git log --format=%B -n 1 #{sha1}`.strip
    log_lines = raw_log.split(/\n/)
    first_line = true
    entry = log_lines
        .reject{|x| x.strip == ""}
        .collect do |line|
          if line =~ /^\s*\*/
            "#{line.sub(/\s*\*/, "  *")}"
          else
            res = first_line ? "* #{line}" : "  #{line}"
            first_line = false
            res
          end
        end
    log_entries << entry
  end
  log = log_entries.join("\n")

  date = Time.now.strftime("%m/%d/%Y")
  log_entry = "### [#{next_version}] - #{date}\n#{log}"
  puts "logmessages:\n#{log}"
  ['CHANGELOG.md'].each do |file|
    if !File.exist?(file)
      File.open(file, 'w') {|f| f.write("# Changelog") }
    end
    text = File.read(file)
    new_contents = text.gsub(/^#\sChangelog/, "# Changelog\n\n#{log_entry}")
    File.open(file, "w") { |f| f.puts new_contents }
  end
end