summaryrefslogtreecommitdiff
blob: ed1851bdcd265dd65bbc322efef96529a5ebcc2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# infra-status.gentoo.org
# Alex Legler <a3li@gentoo.org>
# AGPLv3

require 'bundler/setup'
require 'sinatra'
require 'sinatra/partial'
require 'redcarpet'
require 'rss'
require 'socket'

require_relative 'lib/notice_store'
require_relative 'lib/service_registry'
require_relative 'lib/helpers'

MY_URL = 'https://infra-status.gentoo.org/'

configure do
  NoticeStore.instance.update!
  ServiceRegistry.instance.update!
  set :partial_template_engine, :erb
  mime_type :atom, 'application/atom+xml'
  set :bind, '0.0.0.0'
end

get '/' do
  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
    @title = notice['title']
    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.link    = MY_URL
    maker.channel.id      = MY_URL
    maker.channel.updated = Time.now.to_s

    NoticeStore.instance.visible_notices.each do |notice|
      maker.items.new_item do |item|
        item.link = MY_URL + 'notice/' + notice['id']
        item.title = notice['title']
        item.updated = notice['updated_at'].to_s
        item.description = markdown(notice.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