Module: Wrongdoc::History

Included in:
Changelog, NewsAtom, NewsRdoc, Release
Defined in:
lib/wrongdoc/history.rb

Instance Method Summary collapse

Instance Method Details

#initialize_historyObject



2
3
4
# File 'lib/wrongdoc/history.rb', line 2

def initialize_history
  @tags = @old_summaries = nil
end

#old_summariesObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wrongdoc/history.rb', line 39

def old_summaries
  @old_summaries ||= if File.exist?(".CHANGELOG.old")
    File.readlines(".CHANGELOG.old").inject({}) do |hash, line|
      version, summary = line.split(/ - /, 2)
      hash[version] = summary
      hash
    end
  else
    {}
  end
end

#tag_uri(tag_name) ⇒ Object

returns a cgit URI for a given tag_name



7
8
9
10
11
12
# File 'lib/wrongdoc/history.rb', line 7

def tag_uri(tag_name)
  uri = @cgit_uri.dup
  uri.path += "/tag/"
  uri.query = "id=#{tag_name}"
  uri
end

#tagsObject

TODO: investigate Ruby git libraries



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wrongdoc/history.rb', line 15

def tags
  timefmt = '%Y-%m-%dT%H:%M:%SZ'
  @tags ||= `git tag -l`.split(/\n/).map do |tag|
    next if tag == "v0.0.0"
    if %r{\Av[\d\.]+} =~ tag
      header, subject, body = `git cat-file tag #{tag}`.split(/\n\n/, 3)
      header = header.split(/\n/)
      tagger = header.grep(/\Atagger /).first
      body ||= "initial"
      time = Time.at(tagger.split(/ /)[-2].to_i).utc
      {
        :time => time.strftime(timefmt),
        :ruby_time => time,
        :tagger_name => %r{^tagger ([^<]+)}.match(tagger)[1].strip,
        :tagger_email => %r{<([^>]+)>}.match(tagger)[1].strip,
        :id => `git rev-parse refs/tags/#{tag}`.chomp!,
        :tag => tag,
        :subject => subject,
        :body => (old = old_summaries[tag]) ? "#{old}\n#{body}" : body,
      }
    end
  end.compact.sort { |a,b| b[:time] <=> a[:time] }
end