Class: Gitfeed

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

Overview

A Git to RSS converter

Defined Under Namespace

Classes: Server

Constant Summary collapse

RSS_VERSION =
'2.0'

Instance Method Summary collapse

Constructor Details

#initialize(repository_path, options = {}) ⇒ Gitfeed

Creates a Gitfeed instance for a specific Git repository where each change is an RSS entry.

Parameters:

  • repository_path (String)

    Path to a Git repository

  • options (Hash) (defaults to: {})

    Options for the created RSS feed

Options Hash (options):

  • :title (String) — default: "Gitfeed for Repository"

    Title for the RSS feed

  • :url (String) — default: "http://github.com/scotchi.net/gitfeed"

    Base URL for the RSS feed and all links

  • :description (String) — default: repository_path

    Description of the RSS feed

  • :template (String) — default: "entry.haml"

    Path to a Haml template for the individual entries

  • :include_diffs (Boolean) — default: true

    Include diffs in the RSS output



30
31
32
33
34
35
36
37
38
# File 'lib/gitfeed.rb', line 30

def initialize(repository_path, options = {})
  @git = Git.open(repository_path)
  @title = options[:title] || "Gitfeed for #{repository_path.sub(/.*\//, '')}"
  @url = options[:url] || 'http://github.com/scotchi/gitfeed'
  @description = options[:description] || repository_path
  @template = options[:template] || File.expand_path('../entry.haml',  __FILE__)
  @include_diffs = options[:include_diffs].nil? ? true : options[:include_diffs]
  @haml = Haml::Engine.new(File.read(@template))
end

Instance Method Details

#feedString

Returns An RSS v2 XML stream of the most recent git commits.

Returns:

  • (String)

    An RSS v2 XML stream of the most recent git commits



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gitfeed.rb', line 42

def feed
  RSS::Maker.make(RSS_VERSION) do |maker|
    maker.channel.title = @title
    maker.channel.link = @url
    maker.channel.description = @description
    maker.items.do_sort = true
    @git.log(20).each do |entry|
      item = maker.items.new_item
      item.title = entry.message.sub(/\n.*/m, '')
      item.link = @url
      item.date = entry.date
      item.description = description(entry)
    end
  end.to_s
end