Skip to content
Browse files

Added RSS feeds for projects

  • Loading branch information...
1 parent b18f264 commit 4ea43ba0c4e2188b9712d1c73bb1abbafa5d2b22 @antekpiechnik antekpiechnik committed
View
1 Gemfile
@@ -16,4 +16,5 @@ group :development, :test do
gem "nokogiri"
gem "mocha"
gem "database_cleaner"
+ gem "crack"
end
View
2 Gemfile.lock
@@ -44,6 +44,7 @@ GEM
ffi (~> 0.6.3)
columnize (0.3.2)
configuration (1.2.0)
+ crack (0.1.8)
culerity (0.2.12)
daemons (1.1.0)
database_cleaner (0.6.0)
@@ -118,6 +119,7 @@ PLATFORMS
DEPENDENCIES
capybara
+ crack
database_cleaner
delayed_job
faker
View
9 app/controllers/projects_controller.rb
@@ -1,5 +1,5 @@
class ProjectsController < ApplicationController
- before_filter :locate_project, :only => [:show, :build, :edit, :update, :remove, :destroy, :arrange]
+ before_filter :locate_project, :only => [:show, :build, :edit, :update, :remove, :destroy, :arrange, :feed]
def index
@projects = Project.order("position ASC")
end
@@ -7,6 +7,13 @@ def index
def show
@builds = @project.builds.order("created_at DESC").limit(@project.max_builds)
end
+
+ def feed
+ @builds = @project.builds.order("created_at DESC").limit(@project.max_builds)
+ respond_to do |format|
+ format.atom
+ end
+ end
def build
@project.build!
View
1 app/views/builds/show.html.haml
@@ -32,3 +32,4 @@
%li= link_to("Hide stderr", build_path(@build), :class => "black_button")
%li= link_to("All builds", project_path(@build.project), :class => "black_button")
%li= link_to("Build now", build_project_path(@build.project), :class => "black_button")
+ %li= link_to("Feed", feed_project_path(@build.project)+".atom", :class => "rss")
View
15 app/views/projects/feed.atom.builder
@@ -0,0 +1,15 @@
+atom_feed do |feed|
+ feed.title("#{@project.name} CI")
+ feed.updated(@builds.first.updated_at)
+
+ @builds.each do |build|
+ feed.entry(build, :published => build.created_at) do |entry|
+ entry.title("#{build.display_name} - #{build.status == Build::STATUS_OK ? "SUCCESS" : "FAILED"}")
+ entry.content(build.commit_message)
+ entry.updated(build.updated_at)
+ entry.author do |author|
+ author.name(build.author)
+ end
+ end
+ end
+end
View
1 app/views/projects/show.html.haml
@@ -14,3 +14,4 @@
%li= link_to("Edit", edit_project_path(@project), :class => "black_button")
%li= link_to("Remove project", remove_project_path(@project), :class => "black_button")
%li= link_to("Build now", build_project_path(@project), :class => "black_button")
+ %li= link_to("Feed", feed_project_path(@project)+".atom", :class => "rss")
View
2 config/routes.rb
@@ -1,6 +1,6 @@
BigTuna::Application.routes.draw do
resources :projects do
- member { get "build"; get "remove"; get "arrange" }
+ member { get "build"; get "remove"; get "arrange"; get "feed" }
end
resources :builds
match "/hooks/:hook_name", :to => "hooks#post_commit"
View
18 test/integration/projects_test.rb
@@ -86,4 +86,22 @@ def teardown
click_link build.display_name
assert page.has_content?("Could not switch to 'no/such'")
end
+
+ test "project should have a link to the atom feed" do
+ project = Project.make(:steps => "echo 'ha'", :name => "Atom project", :vcs_source => "no/such/repo", :vcs_type => "git")
+ visit "/projects/#{[project.id, project.name.to_url].join("-")}"
+ assert page.has_link?("Feed")
+ end
+
+ test "project should have an atom feed" do
+ project = Project.make(:steps => "echo 'ha'", :name => "Atom project 2", :vcs_source => "no/such/repo", :vcs_type => "git")
+ build_1 = Build.make(:project => project, :created_at => 2.weeks.ago)
+ build_2 = Build.make(:project => project, :created_at => 1.week.ago)
+ visit "/projects/#{[project.id, project.name.to_url].join("-")}/feed.atom"
+ parsed = Crack::XML.parse(page.body)
+ assert_equal "Atom project 2 CI", parsed["feed"]["title"]
+ assert_equal 2, parsed["feed"]["entry"].size
+ assert_equal "#{build_1.display_name} - #{build_1.status == Build::STATUS_OK ? "SUCCESS" : "FAILED"}", parsed["feed"]["entry"][0]["title"]
+ assert_equal "#{build_2.display_name} - #{build_2.status == Build::STATUS_OK ? "SUCCESS" : "FAILED"}", parsed["feed"]["entry"][1]["title"]
+ end
end

0 comments on commit 4ea43ba

Please sign in to comment.
Something went wrong with that request. Please try again.