Package detail

octokit-from-auth

JoshuaKGoldberg55.1kMIT0.3.2

Creates a GitHub Octokit instance from any available auth token. πŸ™

readme

Octokit From Auth

Creates a GitHub Octokit instance from any available auth token. πŸ™

πŸ‘ͺ All Contributors: 1 🀝 Code of Conduct: Kept πŸ§ͺ Coverage πŸ“ License: MIT πŸ“¦ npm version πŸ’ͺ TypeScript: Strict

Usage

npm i octokit-from-auth

Two functions are exported by the octokit-from-auth package. Both are asynchronous and take in the same constructor parameters as the Octokit class:

  • octokitFromAuth: rejects if an auth token isn't provided and can't be resolved by get-github-auth-token
  • octokitFromAuthSafe: resolves an Octokit with no authentication if an auth token isn't provided and can't be resolved by get-github-auth-token

Both return a new Octokit instance.

import { octokitFromAuth } from "octokit-from-auth";

// auth token used:
// process.env.GH_TOKEN ?? (await $`gh auth token`)
await octokitFromAuth();

The Octokit's auth is retrieved with get-github-auth-token, which defaults to process.env.GH_TOKEN, or failing that, gh auth token. If neither is available then an auth token must be provided as an option:

import { octokitFromAuth } from "octokit-from-auth";

// auth token used:
// "gho_..."
await octokitFromAuth({ auth: "gho_..." });

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! πŸ™

Contributors

Josh Goldberg ✨
Josh Goldberg ✨

πŸ’» πŸ–‹ πŸ“– πŸ€” πŸš‡ 🚧 πŸ“† πŸ”§

πŸ’ This package was templated with create-typescript-app using the Bingo framework.

changelog

Changelog

0.3.1 (2025-04-01)

Bug Fixes

  • bump to create-typescript-app@2 with transitions action (#19) (1d3d7fe), closes #18

0.3.0 (2024-12-16)

Features

  • added octokitFromAuthSafe function (17a7a21)

0.2.0 (2024-12-15)

Bug Fixes

  • empty commit to trigger release (30843b4)

Features

  • initialized repo ✨ (14c3f22)