Sha256: 4b0b295e7bf73c133dea4c3ea0e86f12b24a3ca9c04804ffc4265b04a6ca1f5e

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'rss/maker'
require 'rscm/logging'
require 'rscm/time_ext'
require 'damagecontrol/project'

module DamageControl
  # Persists standard stuff like changesets, diffs and RSS.
  # Typically used within a block passed to a Poller. See App.
  class StandardPersister
    
    # Save the changesets to disk as YAML
    def save_changesets(project, changesets)
      Log.info "Saving changesets for #{project.name}"
      changesets.accept(project.changesets_persister)
    end
    
    # Get the diffs for each change and save them.
    def save_diffs(project, changesets)
      Log.info "Getting diffs for #{project.name}"
      dp = DamageControl::Visitor::DiffPersister.new(project.scm, project.name)
      changesets.accept(dp)
      Log.info "Saved diffs for #{project.name}"
    end
    
    # Save RSS to disk. The RSS spec says max 15 items in a channel,
    # (http://www.chadfowler.com/ruby/rss/)
    # We'll get upto the latest 15 changesets and turn them into RSS.
    def save_rss(project)
      Log.info "Generating RSS for #{project.name}"
      last_15_changesets = project.changesets_persister.load_upto(project.changesets_persister.latest_identifier, 15)
      RSS::Maker.make("2.0") do |rss|
        FileUtils.mkdir_p(File.dirname(project.changesets_rss_file))
        File.open(project.changesets_rss_file, "w") do |io|
          rss_writer = DamageControl::Visitor::RssWriter.new(
            rss,
            "Changesets for #{@name}",
            "http://localhost:4712/", # TODO point to web version of changeset
            project.description, 
            project.tracker || Tracker::Null.new, 
            project.scm_web || SCMWeb::Null.new        
          )
          last_15_changesets.accept(rss_writer)
          io.write(rss.to_rss)
        end
      end
      Log.info "Saved RSS for #{project.name} to #{project.changesets_rss_file}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
damagecontrol-0.5.0 lib/damagecontrol/standard_persister.rb