forked from alphagov/govuk-dependencies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
61 lines (51 loc) · 1.89 KB
/
app.rb
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
require "sinatra"
require_relative "lib/loader"
class GovukDependencies < Sinatra::Base
get "/" do
cache :pull_requests_by_application do
erb :index, layout: :layout, locals: {
pull_requests_by_application: UseCases::Group::PullRequestsByApplication.new.execute,
}
end
end
get "/gem" do
cache :pull_requests_by_gem do
erb :gem, layout: :layout, locals: {
pull_requests_by_gem: UseCases::Group::PullRequestsByGem.new.execute,
}
end
end
get "/team" do
cache :pull_requests_by_team do
pull_requests = UseCases::PullRequests::Fetch.new.execute
teams = UseCases::Teams::Fetch.new.execute
applications_by_team = UseCases::Group::ApplicationsByTeam.new.execute(pull_requests: pull_requests, teams: teams)
erb :team, locals: { pull_requests_by_team: applications_by_team }, layout: :layout
end
end
get "/stats" do
cache :stats do
erb :stats, locals: {
pull_request_count: UseCases::PullRequests::FetchCount.new.execute,
}, layout: :layout
end
end
get "/team/:team_name" do
cache :"pull_requests_by_team_#{params.fetch(:team_name)}" do
pull_requests = UseCases::PullRequests::Fetch.new.execute
teams = UseCases::Teams::Fetch.new.execute
applications_by_team = UseCases::Group::ApplicationsByTeam.new.execute(pull_requests: pull_requests, teams: teams)
applications_for_team = applications_by_team.select do |team|
team.fetch(:team_name) == params.fetch(:team_name)
end
erb :team, locals: { pull_requests_by_team: applications_for_team }, layout: :layout
end
end
post "/slack/notify/:team/:secret" do
return "[unauthorised]" unless params[:secret] == ENV["DEPENDAPANDA_SECRET"]
UseCases::Slack::SendMessages.new(
message_presenter: Presenters::Slack::FullMessage.new,
).execute(team: params.fetch(:team))
"[ok]"
end
end