Commit d745242

mo khan <mo@mokhan.ca>
2021-07-13 03:29:03
list each of the repositories for each installation
1 parent 82b4957
Changed files (1)
bin
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