Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Basic working git-to-rss + sinatra for ruby

  • Loading branch information...
commit 54e1a34a5212efdea122b4975d85db6ad8af903b 1 parent d8010be
@scotchi authored committed
Showing with 105 additions and 0 deletions.
  1. +34 −0 bin/gitfeed
  2. +19 −0 lib/entry.haml
  3. +52 −0 lib/gitfeed.rb
View
34 bin/gitfeed
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'gitfeed'
+
+unless ARGV.size >= 1
+ warn <<END
+Usage: gitfeed [options] /path/to/git/repository
+
+Options:
+ --title="RSS Feed Title"
+ --url=http://base.url.com/
+ --description="RSS Feed Descrption"
+ --template=/path/to/haml/template/for/entries
+ --include-diffs=false
+END
+ exit! 1
+end
+
+options = {}
+
+until ARGV.size <= 1 do
+ kv = ARGV.shift.split('=')
+ key = kv.first.sub(/^--/, '').gsub('-', '_').to_sym
+ value = kv.last
+ value = false if value == 'false'
+ value = true if value == 'true'
+ options[key] = value
+end
+
+repository = ARGV.shift
+
+Gitfeed::Server.start(repository, options)
+
View
19 lib/entry.haml
@@ -0,0 +1,19 @@
+%p
+ %strong Author:
+ = entry.author.name
+ &lt;
+ %a{ :href => "mailto:#{entry.author.email}" }
+ = entry.author.email
+ &gt;
+%p
+ %strong Date:
+ = entry.author.date
+%p
+ %strong Message:
+ = entry.message
+%p
+ %strong SHA:
+ = entry.objectish
+- if @include_diffs && !entry.parents.empty?
+ %pre
+ = @git.diff(entry.parents.first.objectish, entry.objectish)
View
52 lib/gitfeed.rb
@@ -0,0 +1,52 @@
+require 'rubygems'
+require 'git'
+require 'haml'
+require 'rss/maker'
+require 'sinatra'
+
+class Gitfeed
+ RSS_VERSION = '2.0'
+
+ 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
+
+ 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
+ end
+
+ class Server < Sinatra::Base
+ def self.start(*args)
+ @@gitfeed = Gitfeed.new(*args)
+ get '/' do
+ content_type('text/xml')
+ @@gitfeed.feed.to_s
+ end
+ self.run!
+ end
+ end
+
+ private
+
+ def description(entry)
+ @haml.render(self, :entry => entry)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.