Class: PTLog::ChangeLog

Inherits:
Object
  • Object
show all
Defined in:
lib/ptlog/change_log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChangeLog



49
50
51
52
53
# File 'lib/ptlog/change_log.rb', line 49

def initialize
  @git ||= Git.open(Dir.getwd)
  @start = ENV['PTLOG_SINCE'] || git.lib.ordered_tags[-1]
  @tags = PTLog::TagList.new(@git, @start)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



47
48
49
# File 'lib/ptlog/change_log.rb', line 47

def git
  @git
end

#tagsObject (readonly)

Returns the value of attribute tags.



47
48
49
# File 'lib/ptlog/change_log.rb', line 47

def tags
  @tags
end

Class Method Details

.generateObject

Raises:



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
109
# File 'lib/ptlog/change_log.rb', line 70

def self.generate
  raise GeneralError, "You have to specify Pivotal token with export PIVOTAL_TOKEN=xyz" unless ENV.has_key?('PIVOTAL_TOKEN')

  changelog = new

  @builder = Nokogiri::HTML::Builder.new(:encoding => 'UTF-8') do |doc|
    doc.body do
      doc.h1 "Change Log @ #{Time.new.utc.strftime('%I:%M%P %D UTC')}"
      changelog.tags.each do |tag|
        doc.h2 do
          doc.text "Release #{tag} "
          doc.text changelog.git.gcommit(tag).date.utc.strftime('(%I:%M%P %D UTC)')
        end

        changelog.stories(changelog.tags.prev_to(tag), tag).each do |num, messages|
          doc.div(class: 'story') do
            story = Pivotal::Story.get(num)
            doc.h3 do
              if story.valid?
                doc.a(href: story.url) do
                  doc.text "##{num}"
                end
                doc.text " - #{story.name}"
              else
                doc.text "##{num} - #{story.error}"
              end
            end
            doc.ul(class: 'commits') do
              messages.each do |message|
                doc.li message
              end
            end
          end
        end
      end
    end
  end

  @builder.to_html
end

Instance Method Details

#log(from, to) ⇒ Object



55
56
57
# File 'lib/ptlog/change_log.rb', line 55

def log(from, to)
  git.log.between(from, to)
end

#stories(from, to) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/ptlog/change_log.rb', line 59

def stories(from, to)
  output = {}
  log(from, to).each do |commit|
    commit.message.scan(/\#(\d+)/).flatten.each do |num|
      output[num] ||= []
      output[num] << commit.message
    end
  end
  output
end