summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2021-07-12 21:29:03 -0600
committermo khan <mo@mokhan.ca>2021-07-12 21:29:03 -0600
commitd7452426c5ef645cf991e5ee27d995ba2313edde (patch)
tree9eb9106c0921fc7a1f86d1a1cde954c5ce88d020
parent82b4957275813de22b4b8817ef2720494411aa34 (diff)
list each of the repositories for each installationHEADmain
-rwxr-xr-xbin/jwt34
1 files changed, 20 insertions, 14 deletions
diff --git a/bin/jwt b/bin/jwt
index cee1813..8b8c1f7 100755
--- a/bin/jwt
+++ b/bin/jwt
@@ -6,6 +6,7 @@ require 'openssl'
gemfile do
source 'https://rubygems.org'
gem 'jwt'
+ gem 'net-hippie'
end
private_pem = IO.read('config/gh-app.pem')
@@ -21,18 +22,23 @@ jwt = JWT.encode(
"RS256"
)
-system([
- :curl,
- '-i',
- "-H 'Authorization: Bearer #{jwt}'",
- "-H 'Accept: application/vnd.github.v3+json'",
- "https://api.github.com/app"
-].map(&:to_s).join(' '))
+client = Net::Hippie::Client.new(logger: Logger.new('/dev/null'), headers: {
+ 'Accept' => 'application/vnd.github.v3+json',
+ 'Authorization' => "Bearer #{jwt}",
+})
-system([
- :curl,
- '-i',
- "-H 'Authorization: Bearer #{jwt}'",
- "-H 'Accept: application/vnd.github.v3+json'",
- "https://api.github.com/app/installations"
-].map(&:to_s).join(' '))
+response = client.get("https://api.github.com/app")
+puts JSON.pretty_generate(JSON.parse(response.body))
+
+response = client.get("https://api.github.com/app/installations")
+json = JSON.parse(response.body)
+json.each do |installation|
+ installation_id = installation['id']
+ response = client.post("https://api.github.com/app/installations/#{installation_id}/access_tokens")
+ json = JSON.parse(response.body)
+ token = json['token']
+ response = client.get("https://api.github.com/installation/repositories", headers:{
+ 'Authorization': "token #{token}"
+ })
+ puts JSON.pretty_generate(JSON.parse(response.body))
+end