class Crackin::Changelog

Public Class Methods

new(file, version, options={}) click to toggle source
# File lib/crackin/changelog.rb, line 3
def initialize(file, version, options={})
  @options = {
      first: false
  }.merge(options)
  @output = file
  @version = version
  @config = Crackin.config
  @source = @config.source
  @data = {}
end

Public Instance Methods

full() click to toggle source
# File lib/crackin/changelog.rb, line 32
def full
  tags = ordered_tags
  to = 'HEAD'
  name = @version
  tags.reverse_each do |from|
    @data[name] = between(from, to).uniq
    to = from
    name = from
  end
end
save() click to toggle source
# File lib/crackin/changelog.rb, line 43
def save
  File.open(@output, "w+") {|f| f.write(to_s)}
end
to_s() click to toggle source
# File lib/crackin/changelog.rb, line 14
def to_s
  tags = order_tags([@version, source_tags, @data.keys].flatten.uniq).reverse
  out = "### Changelog\n\n"
  tags.each do |section|
    lines = @data[section]
    out += "##### #{section}:\n"
    out += lines.join("\n") if lines
    out += "\n\n"
  end
  out
end
update() click to toggle source
# File lib/crackin/changelog.rb, line 26
def update
  tags = ordered_tags
  load
  @data[@version] = between(tags.last, 'HEAD').uniq
end

Protected Instance Methods

between(from, to) click to toggle source
# File lib/crackin/changelog.rb, line 94
def between(from, to)
  log = @source.between(from, to)
  out = []
  log.each do |c|
    m = message(c.message)
    out << m if m
  end
  out
end
load() click to toggle source
# File lib/crackin/changelog.rb, line 77
def load
  return unless File.exists?(@output)
  file = File.open(@output).read
  section = nil
  file.lines.each do |line|
    next if line =~ /^$/
    if line =~ /^#####\s+(.*):/
      section = $1
      next
    end
    if section
      @data[section] ||= []
      @data[section] << line.chomp
    end
  end
end
message(m) click to toggle source
# File lib/crackin/changelog.rb, line 104
def message(m)
  out = nil
  if m !~ /^(merge|v|version|changelog|crackin)/i
    out = "* #{m}"
  end
  out
end
order_tags(list) click to toggle source
# File lib/crackin/changelog.rb, line 53
def order_tags(list)
  ordered = list.sort_by { |e| tag_to_number(e) }
  ordered #.reject { |e| (a, b, c, d) = e.split("."); !d.nil? }
end
ordered_tags() click to toggle source
# File lib/crackin/changelog.rb, line 49
def ordered_tags
  order_tags(source_tags)
end
source_tags() click to toggle source
# File lib/crackin/changelog.rb, line 73
def source_tags
  @source.tags.all.map(&:name)
end
tag_to_number(tag) click to toggle source
# File lib/crackin/changelog.rb, line 58
def tag_to_number(tag)
  (a, b, c, d) = tag.gsub(/^v/, "").split(".")
  tags = {'rc' => 3, 'beta' => 2, 'alpha' => 1}
  t = 4
  n = 0
  if d && d =~ /(\w+)(\d+)/
    t = tags[$1]
    n = $2
  end
  str = ("%03d%03d%03d%03d%03d" % [a, b, c, t, n])
  number = str.to_i
  #puts "## #{tag} => #{str} => #{number}"
  number
end