diff options
author | 2013-11-11 11:33:12 +0100 | |
---|---|---|
committer | 2013-11-11 11:33:12 +0100 | |
commit | d733c0abf2d568319d3b19e8806816346760737e (patch) | |
tree | 446dcee6f606ecc95db2e66ad393925d89372622 /infra-status.rb | |
parent | .gitignore (diff) | |
download | infra-status-d733c0abf2d568319d3b19e8806816346760737e.tar.gz infra-status-d733c0abf2d568319d3b19e8806816346760737e.tar.bz2 infra-status-d733c0abf2d568319d3b19e8806816346760737e.zip |
v2
Diffstat (limited to 'infra-status.rb')
-rw-r--r-- | infra-status.rb | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/infra-status.rb b/infra-status.rb index ff654d9..1e6c6f3 100644 --- a/infra-status.rb +++ b/infra-status.rb @@ -1,6 +1,64 @@ -require "bundler/setup" -require "sinatra" +require 'bundler/setup' +require 'sinatra' +require 'sinatra/partial' +require 'redcarpet' +require 'rss' + +require_relative 'lib/notice_store' +require_relative 'lib/service_registry' +require_relative 'lib/helpers' + +MY_URL = 'http://localhost:4567/' + +configure do + NoticeStore.instance.update! + ServiceRegistry.instance.update! + set :partial_template_engine, :erb + mime_type :atom, 'application/atom+xml' +end get '/' do - "Hello World!" -end
\ No newline at end of file + erb :index +end + +get '/notice/:id' do + notice = NoticeStore.instance.notice(params[:id]) + + if notice.nil? + status 404 + erb :layout, :layout => false do + '<h1>No such notice</h1><p>The notice you have requested does not exist or has been removed as it was resolved long ago.</p>' + end + else + erb :notice, :locals => { :notice => notice } + end +end + +get '/feed.atom' do + rss = RSS::Maker.make('atom') do |maker| + maker.channel.author = 'Gentoo Infrastructure Team' + maker.channel.title = 'Gentoo Infrastructure Notices' + maker.channel.id = MY_URL + maker.channel.updated = Time.now.to_s + + NoticeStore.instance.active_notices.each do |notice| + maker.items.new_item do |item| + item.link = MY_URL + 'notice/' + notice['id'] + item.title = notice['title'] + item.updated = notice['created_at'].to_s + item.description = markdown(notice.get_content) + end + end + end + + content_type :atom + body rss.to_s +end + +# Forcibly update the notice store +get '/force_update' do + NoticeStore.instance.update! + ServiceRegistry.instance.update! + redirect '/#ok' +end + |