Module: Ask::GitHub

Defined in:
lib/ask/github/client.rb,
lib/ask/github/context.rb,
lib/ask/github/version.rb,
lib/ask/github/error_guide.rb

Defined Under Namespace

Modules: Errors Classes: ClientProxy, Content

Constant Summary collapse

DESCRIPTION =

Human-readable description of the GitHub service context.

"GitHub — code hosting, issues, pull requests, actions, packages"
DOCS_URL =

Base URL for GitHub REST API documentation.

"https://docs.github.com/en/rest"
OPENAPI_URL =

URL for the GitHub OpenAPI specification.

"https://api.github.com/openapi.json"
AUTH_NAME =

Credential name used with Ask::Auth.resolve.

:github_token
AUTH_HOW =

Instructions for obtaining a GitHub personal access token.

"https://github.com/settings/tokens — scopes: repo, read:org"
GEM_NAME =

Gem name for the GitHub API client.

"octokit"
GEM_VERSION =

Required gem version constraint.

"~> 9.0"
GEM_DOCS =

URL for Octokit Ruby library documentation.

"https://octokit.github.io/octokit.rb"
QUICK_START =

Quick-start Ruby code snippet for agents to copy-paste.

<<~RUBY
  client = Ask::GitHub.client
  client.issues("owner/repo")
  client.create_issue("owner/repo", "Title", "Body")
  client.pull_requests("owner/repo")
  client.contents("owner/repo", path: "Gemfile")
  client.search_issues("query")
RUBY
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.client(token: nil) ⇒ ClientProxy

Returns an authenticated Octokit client configured for an AI agent or a content connector.

Resolves the GitHub token via Ask::Auth.resolve(:github_token), or uses the token: given explicitly (the connector path — the token comes from the host app's own credential store). Configures the client with sensible defaults:

  • auto_paginate: true (collects all pages automatically)
  • per_page: 100 (maximum items per page)
  • middleware: Faraday retry middleware (3 retries, exponential backoff)

The client is wrapped in a ClientProxy that converts Octokit::Unauthorized into Ask::Auth::InvalidCredential, and exposes the repo-content helpers (+default_branch+, tree, file, license) for docs-as-code sources.

Examples:

client = Ask::GitHub.client
client.issues("owner/repo")

connector with an explicit token

client = Ask::GitHub.client(token: credential.token)
client.default_branch("owner/repo")

Returns:

Raises:

  • (Ask::Auth::MissingCredential)

    if no GitHub token is configured

  • (Ask::Auth::InvalidCredential)

    if the token is rejected (401)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ask/github/client.rb', line 36

def self.client(token: nil)
  token ||= Ask::Auth.resolve(:github_token)

  client = Octokit::Client.new(access_token: token, auto_paginate: true, per_page: 100)

  # Configure Faraday retry middleware for transient failures
  client.middleware = Faraday::RackBuilder.new do |builder|
    builder.request :retry, max: 3, interval: 1, backoff_factor: 2,
                            retry_statuses: [429, 500, 502, 503]
    builder.adapter Faraday.default_adapter
  end

  ClientProxy.new(client)
end