octokit-from-auth
v0.3.0
Published
Creates a GitHub Octokit instance from any available auth token. π
Downloads
17,653
Readme
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 byget-github-auth-token
octokitFromAuthSafe
: resolves anOctokit
with no authentication if an auth token isn't provided and can't be resolved byget-github-auth-token
import { octokitFromAuth } from "octokit-from-auth";
// auth token used:
// process.env.GH_TOKEN ?? (await $`gh auth token`)
const octokit = 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_..."
const octokit = await octokitFromAuth({ auth: "gho_..." });
Development
See .github/CONTRIBUTING.md
, then .github/DEVELOPMENT.md
.
Thanks! π
Contributors
π This package was templated with
create-typescript-app
using thecreate
engine.