Commit 2b04c2a67fb981a1ef3491be4d7775de7f2a221d
1 parent
3f70316c
Exists in
master
and in
4 other branches
create atom feed for commits
Showing
4 changed files
with
37 additions
and
2 deletions
Show diff stats
app/controllers/commits_controller.rb
| @@ -13,7 +13,7 @@ class CommitsController < ApplicationController | @@ -13,7 +13,7 @@ class CommitsController < ApplicationController | ||
| 13 | load_refs # load @branch, @tag & @ref | 13 | load_refs # load @branch, @tag & @ref |
| 14 | 14 | ||
| 15 | @repo = project.repo | 15 | @repo = project.repo |
| 16 | - limit, offset = (params[:limit] || 20), (params[:offset] || 0) | 16 | + limit, offset = (params[:limit] || 20), (params[:offset] || 0) |
| 17 | 17 | ||
| 18 | if params[:path] | 18 | if params[:path] |
| 19 | @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset) | 19 | @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset) |
| @@ -24,6 +24,7 @@ class CommitsController < ApplicationController | @@ -24,6 +24,7 @@ class CommitsController < ApplicationController | ||
| 24 | respond_to do |format| | 24 | respond_to do |format| |
| 25 | format.html # index.html.erb | 25 | format.html # index.html.erb |
| 26 | format.js | 26 | format.js |
| 27 | + format.atom { render :layout => false } | ||
| 27 | end | 28 | end |
| 28 | end | 29 | end |
| 29 | 30 | ||
| @@ -32,7 +33,7 @@ class CommitsController < ApplicationController | @@ -32,7 +33,7 @@ class CommitsController < ApplicationController | ||
| 32 | @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20) | 33 | @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20) |
| 33 | @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit") | 34 | @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit") |
| 34 | 35 | ||
| 35 | - respond_to do |format| | 36 | + respond_to do |format| |
| 36 | format.html | 37 | format.html |
| 37 | format.js { respond_with_notes } | 38 | format.js { respond_with_notes } |
| 38 | end | 39 | end |
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +xml.instruct! | ||
| 2 | +xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do | ||
| 3 | + xml.title "Recent commits to #{@project.name}:#{@ref}" | ||
| 4 | + xml.link :href => project_commits_url(@project, :atom, :ref => @ref), :rel => "self", :type => "application/atom+xml" | ||
| 5 | + xml.link :href => project_commits_url(@project), :rel => "alternate", :type => "text/html" | ||
| 6 | + xml.id project_commits_url(@project) | ||
| 7 | + xml.updated @commits.first.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") if @commits.any? | ||
| 8 | + | ||
| 9 | + @commits.each do |commit| | ||
| 10 | + xml.entry do | ||
| 11 | + xml.id project_commit_url(@project, :id => commit.id) | ||
| 12 | + xml.link :href => project_commit_url(@project, :id => commit.id) | ||
| 13 | + xml.title truncate(commit.safe_message, :length => 80) | ||
| 14 | + xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
| 15 | + xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email) | ||
| 16 | + xml.author do |author| | ||
| 17 | + xml.name commit.author_name | ||
| 18 | + xml.email commit.author_email | ||
| 19 | + end | ||
| 20 | + xml.summary commit.safe_message | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | +end |
app/views/layouts/project.html.haml
| @@ -5,6 +5,8 @@ | @@ -5,6 +5,8 @@ | ||
| 5 | GitLab #{" - #{@project.name}" if @project && !@project.new_record?} | 5 | GitLab #{" - #{@project.name}" if @project && !@project.new_record?} |
| 6 | = stylesheet_link_tag "application" | 6 | = stylesheet_link_tag "application" |
| 7 | = javascript_include_tag "application" | 7 | = javascript_include_tag "application" |
| 8 | + - if current_page?(tree_project_path(@project)) || current_page?(project_commits_path(@project)) | ||
| 9 | + = auto_discovery_link_tag(:atom, project_commits_url(@project, :atom, :ref => @ref), :title => "Recent commits to #{@project.name}:#{@ref}") | ||
| 8 | = csrf_meta_tags | 10 | = csrf_meta_tags |
| 9 | = javascript_tag do | 11 | = javascript_tag do |
| 10 | REQ_URI = "#{request.env["REQUEST_URI"]}"; | 12 | REQ_URI = "#{request.env["REQUEST_URI"]}"; |
spec/requests/commits_spec.rb
| @@ -25,6 +25,15 @@ describe "Commits" do | @@ -25,6 +25,15 @@ describe "Commits" do | ||
| 25 | page.should have_content(commit.author) | 25 | page.should have_content(commit.author) |
| 26 | page.should have_content(commit.message) | 26 | page.should have_content(commit.message) |
| 27 | end | 27 | end |
| 28 | + | ||
| 29 | + it "should render atom feed" do | ||
| 30 | + visit project_commits_path(project, :atom) | ||
| 31 | + | ||
| 32 | + page.response_headers['Content-Type'].should have_content("application/atom+xml") | ||
| 33 | + page.body.should have_selector("title", :text => "Recent commits to #{project.name}") | ||
| 34 | + page.body.should have_selector("author email", :text => commit.author_email) | ||
| 35 | + page.body.should have_selector("entry summary", :text => commit.message) | ||
| 36 | + end | ||
| 28 | end | 37 | end |
| 29 | 38 | ||
| 30 | describe "GET /commits/:id" do | 39 | describe "GET /commits/:id" do |