Project

General

Profile

RE: "Invalid RSS Feed" on Simple CI plugin to TeamCity feed. ยป simple_ci_controller.rb

modified file - Mark B, 2009-09-12 22:31

 
1
require 'feed-normalizer'
2
require 'open-uri'
3

    
4
class SimpleCiController < ApplicationController
5
  layout 'base'
6
  before_filter :find_project, :authorize
7

    
8
  def show
9
    # Build the regular expression used to detect successfull builds
10
    success_re = Regexp.new(Setting.plugin_simple_ci['success_keyword'].strip, Regexp::IGNORECASE)
11
    # Find the project's CI RSS feed URL
12
    # This URL is stored in a 'regular' project custom field
13
    feed_url = @project.custom_values.detect {|v| v.custom_field_id == Setting.plugin_simple_ci['feed_url_custom_field'].to_i}
14
    feed_url = feed_url.value if feed_url
15
    if !feed_url.blank?
16
      begin
17
        content = ''
18
        # Open the feed and parse it
19
        rss = FeedNormalizer::FeedNormalizer.parse open(feed_url.strip)
20
        if rss
21
          @builds = rss.entries.collect do |item|
22
            build = {
23
              :time => item.date_published,
24
              :title => item.title,
25
              :description => item.description,
26
              :link => item.url
27
            }
28
            build[:success] = (success_re.match(item.title) ? true : false)
29
            build
30
          end
31
        else
32
          flash.now[:error] = 'Invalid RSS feed.' unless @builds
33
        end
34
      rescue SocketError
35
        flash.now[:error] = 'Unable to connect to remote host.'
36
      end
37
    @show_descriptions = Setting.plugin_simple_ci[:show_descriptions].to_i
38
    else
39
      flash.now[:error] = 'The feed URL is not defined for this project.'
40
    end
41
  end
42

    
43
private
44
  def find_project
45
    @project = Project.find(params[:id])
46
  rescue ActiveRecord::RecordNotFound
47
    render_404
48
  end
49
end
50

    
    (1-1/1)