diff options
| author | mo khan <mo@mokhan.ca> | 2021-07-12 21:29:03 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-07-12 21:29:03 -0600 |
| commit | d7452426c5ef645cf991e5ee27d995ba2313edde (patch) | |
| tree | 9eb9106c0921fc7a1f86d1a1cde954c5ce88d020 | |
| parent | 82b4957275813de22b4b8817ef2720494411aa34 (diff) | |
| -rwxr-xr-x | bin/jwt | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -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 |
