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
|
# File 'lib/underway/sinatra/app_info.rb', line 17
def self.registered(app)
app.get "/info" do
erb <<~EOS
<h1>Underway</h1>
<h2>Interesting routes:</h2>
<pre>
<li>/info => This page</li>
<li><a href="/info/app">/info/app</a> => Information about the configured GitHub App</li>
<li><a href="/info/app/jwt">/info/app/jwt</a> => Generates a JWT for authentication as this App</li>
<li><a href="/info/app/installations">/info/app/installations</a> => A list of installations associated with this App</li>
<li><a href="/info/app/installations/1">/info/app/installations/:id</a> => Information about the given installation of this App</li>
<li><a href="/info/app/installations/1/access_token">/info/app/installations/:id/access_token</a> => A valid access token for accessing the given installation as this App</li>
<li><a href="/info/app/installations/1/repositories">/info/app/installations/:id/repositories</a> => A list of all repositories accessible to the installation of this App</li>
</pre>
<h2>Private PEM file</h2>
<pre>
#{::Underway::Settings.config.private_key_filename}
</pre>
EOS
end
app.get "/info/app/jwt" do
content_type :json
::Underway::Api.generate_jwt
end
app.get "/info/app" do
content_type :json
::Underway::SawyerToJson.convert(gh_api("/app"))
end
app.get "/info/app/installations" do
content_type :json
::Underway::SawyerToJson.convert(gh_api("/app/installations"))
end
app.get "/info/app/installations/:installation_id" do
content_type :json
::Underway::SawyerToJson.convert(gh_api("/app/installations/#{params["installation_id"]}"))
end
app.get "/info/app/installations/:installation_id/access_token" do
content_type :json
::Underway::SawyerToJson.convert(
gh_api(
"/app/installations/#{params["installation_id"]}/access_tokens",
method: :post
)
)
end
app.get "/info/app/installations/:installation_id/repositories" do
content_type :json
::Underway::SawyerToJson.convert(
gh_api(
"/installation/repositories",
headers: { authorization: "token #{::Underway::Api.installation_token(id: params[:installation_id])}" }
)
)
end
end
|