Commit f8f6ff065eccc6ede4d35ed87a09bb962b84ca25
1 parent
2cf80107
Exists in
master
and in
4 other branches
add projects atom feed
Showing
4 changed files
with
53 additions
and
4 deletions
Show diff stats
app/controllers/projects_controller.rb
| ... | ... | @@ -14,6 +14,11 @@ class ProjectsController < ApplicationController |
| 14 | 14 | @projects = current_user.projects.includes(:events).order("events.created_at DESC") |
| 15 | 15 | @projects = @projects.page(params[:page]).per(40) |
| 16 | 16 | @events = Event.where(:project_id => current_user.projects.map(&:id)).recent.limit(20) |
| 17 | + | |
| 18 | + respond_to do |format| | |
| 19 | + format.html | |
| 20 | + format.atom { render :layout => false } | |
| 21 | + end | |
| 17 | 22 | end |
| 18 | 23 | |
| 19 | 24 | def new |
| ... | ... | @@ -31,7 +36,7 @@ class ProjectsController < ApplicationController |
| 31 | 36 | @project.save! |
| 32 | 37 | @project.users_projects.create!(:project_access => UsersProject::MASTER, :user => current_user) |
| 33 | 38 | |
| 34 | - # when project saved no team member exist so | |
| 39 | + # when project saved no team member exist so | |
| 35 | 40 | # project repository should be updated after first user add |
| 36 | 41 | @project.update_repository |
| 37 | 42 | end |
| ... | ... | @@ -72,7 +77,7 @@ class ProjectsController < ApplicationController |
| 72 | 77 | @events = @project.events.recent.limit(limit) |
| 73 | 78 | |
| 74 | 79 | respond_to do |format| |
| 75 | - format.html do | |
| 80 | + format.html do | |
| 76 | 81 | if @project.repo_exists? && @project.has_commits? |
| 77 | 82 | render :show |
| 78 | 83 | else | ... | ... |
app/views/layouts/_head.html.haml
| ... | ... | @@ -8,10 +8,11 @@ |
| 8 | 8 | = javascript_include_tag "application" |
| 9 | 9 | |
| 10 | 10 | -# Atom feed |
| 11 | + - if controller_name == 'projects' && action_name == 'index' | |
| 12 | + = auto_discovery_link_tag :atom, projects_url(:atom, :private_token => current_user.private_token), :title => "Dashboard feed" | |
| 11 | 13 | - if @project && !@project.new_record? |
| 12 | 14 | - if current_page?(tree_project_ref_path(@project, @project.root_ref)) || current_page?(project_commits_path(@project)) |
| 13 | 15 | = auto_discovery_link_tag(:atom, project_commits_url(@project, :atom, :ref => @ref, :private_token => current_user.private_token), :title => "Recent commits to #{@project.name}:#{@ref}") |
| 14 | 16 | - if request.path == project_issues_path(@project) |
| 15 | 17 | = auto_discovery_link_tag(:atom, project_issues_url(@project, :atom, :private_token => current_user.private_token), :title => "#{@project.name} issues") |
| 16 | 18 | = csrf_meta_tags |
| 17 | - | ... | ... |
| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | +xml.instruct! | |
| 2 | +xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do | |
| 3 | + xml.title "Dashboard feed#{" - #{current_user.name}" if current_user.name.present?}" | |
| 4 | + xml.link :href => projects_url(:atom), :rel => "self", :type => "application/atom+xml" | |
| 5 | + xml.link :href => projects_url, :rel => "alternate", :type => "text/html" | |
| 6 | + xml.id projects_url | |
| 7 | + xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any? | |
| 8 | + | |
| 9 | + @events.each do |event| | |
| 10 | + if event.allowed? | |
| 11 | + xml.entry do | |
| 12 | + if event.issue? | |
| 13 | + event_link = project_issue_url(event.project, event.issue) | |
| 14 | + event_title = event.issue_title | |
| 15 | + elsif event.merge_request? | |
| 16 | + event_link = project_merge_request_url(event.project, event.merge_request) | |
| 17 | + event_title = event.merge_request_title | |
| 18 | + elsif event.push? | |
| 19 | + event_link = project_commits_url(event.project, :ref => event.ref_name) | |
| 20 | + event_title = event.ref_name | |
| 21 | + end | |
| 22 | + | |
| 23 | + xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}" | |
| 24 | + xml.link :href => event_link | |
| 25 | + xml.title truncate(event_title, :length => 80) | |
| 26 | + xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ") | |
| 27 | + xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email) | |
| 28 | + xml.author do |author| | |
| 29 | + xml.name event.author_name | |
| 30 | + xml.email event.author_email | |
| 31 | + end | |
| 32 | + xml.summary event_title | |
| 33 | + end | |
| 34 | + end | |
| 35 | + end | |
| 36 | +end | ... | ... |
spec/requests/projects_spec.rb
| ... | ... | @@ -18,9 +18,16 @@ describe "Projects" do |
| 18 | 18 | page.should have_content("New Project") |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | - it "should have project" do | |
| 21 | + it "should have project" do | |
| 22 | 22 | page.should have_content(@project.name) |
| 23 | 23 | end |
| 24 | + | |
| 25 | + it "should render projects atom feed via private token" do | |
| 26 | + logout | |
| 27 | + | |
| 28 | + visit projects_path(:atom, :private_token => @user.private_token) | |
| 29 | + page.body.should have_selector("feed title") | |
| 30 | + end | |
| 24 | 31 | end |
| 25 | 32 | |
| 26 | 33 | describe "GET /projects/new" do | ... | ... |