#!/usr/bin/env ruby require 'bundler/inline' require 'openssl' gemfile do source 'https://rubygems.org' gem 'jwt' gem 'net-hippie' end private_pem = IO.read('config/gh-app.pem') private_key = OpenSSL::PKey::RSA.new(private_pem) jwt = JWT.encode( { iat: Time.now.to_i - 60, exp: Time.now.to_i + (10 * 60), iss: 125988 }, private_key, "RS256" ) client = Net::Hippie::Client.new(logger: Logger.new('/dev/null'), headers: { 'Accept' => 'application/vnd.github.v3+json', 'Authorization' => "Bearer #{jwt}", }) 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