npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@octoherd/octokit

v5.0.0

Published

Customized Octokit for Octoherd

Downloads

3,517

Readme

@octoherd/octokit

Customized Octokit for Octoherd

Usage

Load @octoherd/octokit directly from cdn.skypack.dev

<script type="module">
  import { Octokit } from "https://cdn.skypack.dev/@octoherd/octokit";
</script>

Install with npm install @octoherd/octokit

import { Octokit } from "@octoherd/octokit";

Load @octoherd/octokit directly from cdn.skypack.dev with the ?dts query

import { Octokit } from "https://cdn.skypack.dev/@octoherd/octokit?dts";
import { Octokit } from "@octoherd/octokit";

const octokit = new Octokit({
  auth: /* token here, create one at https://github.com/settings/tokens/new */,
});

const { data: me } = await octokit.request("GET /user")
console.log(me)

By default you authenticate using a token, but you can use any authentication strategy.

REST API requests and GraphQL queries

@octokit/octokit is built on @octokit/core. You can send requests to GitHub's REST API using octokit.request and GraphQL queries octokit.graphql.

Logging

By default, messages are logged with meta data using console.info, console.warn, and console.error. octokit.log.debug is a no-op, unless options.octoherd.debug is set to true.

Important: options.log is ignored. Setting it has no effect.

You can log simple messages, interpolation is supported.

octokit.log.info("Checking repository %s", repository.full_name);

You can pass extra meta information as the first argument

octokit.log.info(
  { id: repository.id },
  "Checking repository %s",
  repository.full_name
);

You can also just log meta information for reporting later

octokit.log.info({
  id: repository.id,
  owner: repositor.owner.login,
  repo: repository.name,
  private: repository.private,
});

The way data is logged can be customized using options.octoherd.onLogMessage and options.octoherd.onLogData.

const octokit = new Octokit({
  octoherd: {
    onLogData(data) {
      // e.g. write data as JSON line to debug log file
      // data always has `.level`, and `.time` properties. `.msg` is set from the log message if set.
    },
    onLogMessage(level, message, additionalData) {
      // level is one of: debug, info, warn, error.
      // message is the log message
      // additionalData is any data that was passed as first argument to the log methods. It defaults to {}
      console.log(
        `[%s]`,
        level.toUpperCase(),
        Object.keys(additionalData).length
          ? `${message} ${chalk.gray(JSON.stringify(additionalData))}`
          : message
      );
    },
  },
});

Additional context can be changed at runtime using octokit.log.setContext(context). The additional context is only passed to options.octoherd.onLogData

octokit.log.setContext({ repo_id: 123 });
octokit.log.info("test");
// data passed to `onLogData` will be { repo_id: 123, msg: "test", level: "info", time: 0 }
// additionalData passed to `onLogMessage` will not have the `.repo_id` property

Built-in plugins

@octoherd/octokit comes with a few plugins out of the box:

You can use octokit.paginate() or octokit.paginate.iterator() for paginating REST API requests.

The retry & throttling plugins hook into the request lifecycle, retries requests in case of unrelated server errors, and throttles requests to avoid hitting rate or abuse limits.

Extending

You can extend @octoherd/octokit with hooks and plugins

License

ISC