lib/github_bot/github/client.rb
# Gets the private key associated to the GitHub application
Gets the private key associated to the GitHub application
Gets the private key associated to the GitHub application
def private_key
        private_pem =
          if ENV['GITHUB_APP_PEM_PATH']
            File.read(Rails.root.join(ENV['GITHUB_APP_PEM_PATH']))
          elsif ENV['GITHUB_APP_PEM_V2']
            ENV['GITHUB_APP_PEM_V2'].gsub('\\\n', "\n")
          elsif ENV['GITHUB_APP_PEM']
            ENV['GITHUB_APP_PEM'].gsub('\n', "\n")
          else
            raise StandardError, "'GITHUB_APP_PEM_PATH' or 'GITHUB_APP_PEM' needs to be set"
          end
        private_key = OpenSSL::PKey::RSA.new(private_pem)
        current = Time.current.to_i
        payload = {
          iat: current,
          exp: current + (10 * 60),
          iss: ENV['GITHUB_APP_IDENTIFIER']
        }
        ::JWT.encode(payload, private_key, 'RS256')
      end
def private_key private_pem = if ENV [ 'GITHUB_APP_PEM_PATH' ] File . read ( Rails . root . join ( ENV [ 'GITHUB_APP_PEM_PATH' ] ) ) elsif ENV [ 'GITHUB_APP_PEM_V2' ] ENV [ 'GITHUB_APP_PEM_V2' ] . gsub ( '\\\n' , "\n" ) elsif ENV [ 'GITHUB_APP_PEM' ] ENV [ 'GITHUB_APP_PEM' ] . gsub ( '\n' , "\n" ) else raise StandardError , "'GITHUB_APP_PEM_PATH' or 'GITHUB_APP_PEM' needs to be set" end private_key = OpenSSL :: PKey :: RSA . new ( private_pem ) current = Time . current . to_i payload = { iat : current , exp : current + ( 10 * 60 ) , iss : ENV [ 'GITHUB_APP_IDENTIFIER' ] } :: JWT . encode ( payload , private_key , 'RS256' ) end
Gets the private key associated to the GitHub application
Gets the private key associated to the GitHub application