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

@octokit/action

v7.0.0

Published

GitHub API client for GitHub Actions

Downloads

143,297

Readme

action.js

GitHub API client for GitHub Actions

@latest Build Status

Usage

@octokit/action is not meant for browser usage.

Install with npm install @octokit/action

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

[!IMPORTANT] As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports". See this helpful guide on transitioning to ESM from @sindresorhus

You can pass secret.GITHUB_TOKEN or any of your own secrets to a Node.js script. For example

name: My Node Action
on:
  - pull_request
jobs:
  my-action:
    runs-on: ubuntu-latest
    steps:
      # Check out code using git
      - uses: actions/checkout@v4
      # Install Node 20
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm install @octokit/action
      # Node.js script can be anywhere. A good convention is to put local GitHub Actions
      # into the `.github/actions` folder
      - run: node .github/actions/my-script.js
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Setting GITHUB_TOKEN on either with: or env: will work.

// .github/actions/my-script.js
import { Octokit } from "@octokit/action";

const octokit = new Octokit();

// `octokit` is now authenticated using GITHUB_TOKEN

Create an issue using REST API

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

const octokit = new Octokit();
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");

// See https://developer.github.com/v3/issues/#create-an-issue
const { data } = await octokit.request("POST /repos/{owner}/{repo}/issues", {
  owner,
  repo,
  title: "My test issue",
});
console.log("Issue created: %s", data.html_url);

You can also use octokit.issues.create({ owner, repo, title }). See the REST endpoint methods plugin for a list of all available methods.

Create an issue using GraphQL

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

const octokit = new Octokit();
const eventPayload = require(process.env.GITHUB_EVENT_PATH);
const repositoryId = eventPayload.repository.node_id;

const response = await octokit.graphql(
  `
  mutation($repositoryId:ID!, $title:String!) {
    createIssue(input:{repositoryId: $repositoryId, title: $title}) {
      issue {
        number
      }
    }
  }
  `,
  {
    repositoryId,
    title: "My test issue",
  },
);

Hooks, plugins, and more

@octokit/action is build upon @octokit/core. Refer to its README for the full API documentation.

TypeScript: Endpoint method parameters and responses

Types for endpoint method parameters and responses are exported as RestEndpointMethodTypes. They keys are the same as the endpoint methods. Here is an example to retrieve the parameter and response types for octokit.checks.create()

import { RestEndpointMethodTypes } from `@octokit/action`;

type ChecksCreateParams =
  RestEndpointMethodTypes["checks"]["create"]["parameters"];
type ChecksCreateResponse =
  RestEndpointMethodTypes["checks"]["create"]["response"];

Proxy Servers

If you use self-hosted runners and require a proxy server to access internet resources then you will need to ensure that you have correctly configured the runner for proxy servers. @octokit/action will pick up the configured proxy server environment variables and configure @octokit/core with the correct request.dispatcher using ProxyAgent. If you need to supply a different request.dispatcher then you should ensure that it handles proxy servers if needed.

How it works

@octokit/action is simply a @octokit/core constructor, pre-authenticate using @octokit/auth-action.

The source code is … simple: src/index.ts.

License

MIT