-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
octobox.rb
71 lines (55 loc) 路 1.49 KB
/
octobox.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
require 'octobox/configurator'
module Octobox
class << self
def config
@config ||= Configurator.new
if block_given?
yield @config
end
@config
end
def refresh_interval_enabled?
config.minimum_refresh_interval && config.minimum_refresh_interval > 0
end
def personal_access_tokens_enabled?
config.personal_access_tokens_enabled
end
def restricted_access_enabled?
config.restricted_access_enabled
end
def github_app?
config.github_app
end
def io?
config.octobox_io
end
def fetch_subject?
config.fetch_subject
end
def background_jobs_enabled?
config.background_jobs_enabled
end
def include_comments?
config.include_comments
end
def github_app_client
Octokit::Client.new(bearer_token: generate_jwt, auto_paginate: true)
end
def installation_client(app_installation_id)
Octokit::Client.new(access_token: installation_access_token(app_installation_id), auto_paginate: true)
end
def installation_access_token(app_installation_id)
Octobox.github_app_client.create_installation_access_token(app_installation_id).token
end
private
def generate_jwt
private_key = OpenSSL::PKey::RSA.new(config.github_app_jwt)
payload = {
iat: Time.now.to_i,
exp: Time.now.to_i + (10 * 60),
iss: Octobox.config.github_app_id
}
JWT.encode(payload, private_key, "RS256")
end
end
end