Class: CiToolkit::GithubBot

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_toolkit/github_bot.rb

Overview

Utility class that provides an access token that can be used with the Github API

Defined Under Namespace

Classes: Credentials

Instance Method Summary collapse

Constructor Details

#initialize(credentials = CiToolkit::GithubBot::Credentials.new, client = Octokit::Client.new(bearer_token: credentials.jwt_token, auto_paginate: true)) ⇒ GithubBot

stack = Faraday::RackBuilder.new do |builder|

builder.response :logger
builder.use Octokit::Response::RaiseError
builder.adapter Faraday.default_adapter

end Octokit.middleware = stack



40
41
42
43
44
45
46
# File 'lib/ci_toolkit/github_bot.rb', line 40

def initialize(
  credentials = CiToolkit::GithubBot::Credentials.new,
  client = Octokit::Client.new(bearer_token: credentials.jwt_token, auto_paginate: true)
)
  @app_id = credentials.app_id
  @client = client
end

Instance Method Details

#create_tokenObject



48
49
50
51
52
53
54
55
# File 'lib/ci_toolkit/github_bot.rb', line 48

def create_token
  return unless (installation_id = find_app_installation)

  @client.create_app_installation_access_token(
    installation_id,
    { accept: Octokit::Preview::PREVIEW_TYPES[:integrations] }
  )[:token]
end