summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNihad Abbasov <narkoz.2008@gmail.com>2011-11-11 12:11:27 +0400
committerNihad Abbasov <narkoz.2008@gmail.com>2011-11-11 12:11:27 +0400
commit2b04c2a67fb981a1ef3491be4d7775de7f2a221d (patch)
tree380484485fe1fa450af1d42a2da13f33abd7b809
parent3f70316c5f264948d74eb9080079be4c78f5aaa9 (diff)
downloadgitlab-ce-2b04c2a67fb981a1ef3491be4d7775de7f2a221d.tar.gz
create atom feed for commits
-rw-r--r--app/controllers/commits_controller.rb5
-rw-r--r--app/views/commits/index.atom.builder23
-rw-r--r--app/views/layouts/project.html.haml2
-rw-r--r--spec/requests/commits_spec.rb9
4 files changed, 37 insertions, 2 deletions
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 79703cf104a..1afe25a745c 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -13,7 +13,7 @@ class CommitsController < ApplicationController
load_refs # load @branch, @tag & @ref
@repo = project.repo
- limit, offset = (params[:limit] || 20), (params[:offset] || 0)
+ limit, offset = (params[:limit] || 20), (params[:offset] || 0)
if params[:path]
@commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
@@ -24,6 +24,7 @@ class CommitsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
format.js
+ format.atom { render :layout => false }
end
end
@@ -32,7 +33,7 @@ class CommitsController < ApplicationController
@notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20)
@note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit")
- respond_to do |format|
+ respond_to do |format|
format.html
format.js { respond_with_notes }
end
diff --git a/app/views/commits/index.atom.builder b/app/views/commits/index.atom.builder
new file mode 100644
index 00000000000..2a352dac1b7
--- /dev/null
+++ b/app/views/commits/index.atom.builder
@@ -0,0 +1,23 @@
+xml.instruct!
+xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do
+ xml.title "Recent commits to #{@project.name}:#{@ref}"
+ xml.link :href => project_commits_url(@project, :atom, :ref => @ref), :rel => "self", :type => "application/atom+xml"
+ xml.link :href => project_commits_url(@project), :rel => "alternate", :type => "text/html"
+ xml.id project_commits_url(@project)
+ xml.updated @commits.first.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") if @commits.any?
+
+ @commits.each do |commit|
+ xml.entry do
+ xml.id project_commit_url(@project, :id => commit.id)
+ xml.link :href => project_commit_url(@project, :id => commit.id)
+ xml.title truncate(commit.safe_message, :length => 80)
+ xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ")
+ xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email)
+ xml.author do |author|
+ xml.name commit.author_name
+ xml.email commit.author_email
+ end
+ xml.summary commit.safe_message
+ end
+ end
+end
diff --git a/app/views/layouts/project.html.haml b/app/views/layouts/project.html.haml
index 0550d89e207..927d62db295 100644
--- a/app/views/layouts/project.html.haml
+++ b/app/views/layouts/project.html.haml
@@ -5,6 +5,8 @@
GitLab #{" - #{@project.name}" if @project && !@project.new_record?}
= stylesheet_link_tag "application"
= javascript_include_tag "application"
+ - if current_page?(tree_project_path(@project)) || current_page?(project_commits_path(@project))
+ = auto_discovery_link_tag(:atom, project_commits_url(@project, :atom, :ref => @ref), :title => "Recent commits to #{@project.name}:#{@ref}")
= csrf_meta_tags
= javascript_tag do
REQ_URI = "#{request.env["REQUEST_URI"]}";
diff --git a/spec/requests/commits_spec.rb b/spec/requests/commits_spec.rb
index 79bb03f53b6..2bbd6b9f104 100644
--- a/spec/requests/commits_spec.rb
+++ b/spec/requests/commits_spec.rb
@@ -25,6 +25,15 @@ describe "Commits" do
page.should have_content(commit.author)
page.should have_content(commit.message)
end
+
+ it "should render atom feed" do
+ visit project_commits_path(project, :atom)
+
+ page.response_headers['Content-Type'].should have_content("application/atom+xml")
+ page.body.should have_selector("title", :text => "Recent commits to #{project.name}")
+ page.body.should have_selector("author email", :text => commit.author_email)
+ page.body.should have_selector("entry summary", :text => commit.message)
+ end
end
describe "GET /commits/:id" do