-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathapp.rb
104 lines (82 loc) · 2.58 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'octokit'
require 'omniauth'
require 'omniauth-github'
require 'rdiscount'
require 'sinatra/base'
module Kobol
class App < Sinatra::Base
helpers Kobol::Helpers::Authentication
helpers Kobol::Helpers::Pagination
helpers Kobol::Helpers::Requests
helpers Kobol::Helpers::FormHelpers
use Rack::Session::Cookie, :key => 'rack.session',
:domain => ENV['KOBOL_DOMAIN'],
:path => '/',
:expire_after => 2592000,
:secret => ENV['KOBOL_SECRET']
use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
end
enable :sessions
set :session_secret, ENV["KOBOL_SECRET"]
set :public_folder, APP_ROOT + '/public'
set :views, APP_ROOT + "/views"
get '/' do
retrieve_issues(page)
erb :issues
end
get '/label-guide' do
erb :label_guide
end
get '/privacy-policy' do
erb :privacy_policy
end
post '/labels' do
repository = params[:project]
create_or_update_labels(repository)
erb :label_guide
end
%w(get post).each do |method|
send(method, "/auth/:provider/callback") do
session[:token] = env['omniauth.auth']['credentials']['token']
session[:uid] = env['omniauth.auth']['uid']
session[:nickname] = env['omniauth.auth']['info']['nickname']
redirect "/"
end
end
get '/auth/failure' do
redirect '/'
end
get '/logout' do
session.clear
redirect "/"
end
def retrieve_issues(page=1)
@issues = []
github { issues_request.search(parameters(params), page) }
@total = issues_request.total rescue nil
@issues = issues_request.issues rescue []
end
protected
def issues_request
@issues_request ||= Kobol::Requests::Issues.new(login_params)
end
def create_or_update_labels(repository)
message = "Labels have been created for <a href='http://github.com/#{repository}/issues'>#{repository}</a>!"
labels = Kobol::Requests::Labels.new(login_params, repository)
github(message, "#{repository} not found!") { labels.create_or_update_labels(LABELS) }
end
def parameters(hash={}, properties)
Kobol::Requests::Issues::PERMITTED.each do |key|
hash[key] = []
properties[key.to_s].each do |value|
hash[key] << value
end rescue ""
properties[key.to_s].split(",").each do |value|
hash[key] << value
end rescue ""
end
hash
end
end
end