6.1.0 • Published 28 days ago

@octokit/action v6.1.0

Weekly downloads
8,815
License
MIT
Repository
github
Last release
28 days ago

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

const { Octokit } = require("@octokit/action");
// or: import { Octokit } from "@octokit/action";

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
const { Octokit } = require("@octokit/action");

const octokit = new Octokit();

// `octokit` is now authenticated using GITHUB_TOKEN

Create an issue using REST API

const { Octokit } = require("@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

const { Octokit } = require("@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.agent using proxy-agent. If you need to supply a different request.agent 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

6.1.0

28 days ago

6.0.7

5 months ago

6.0.6

7 months ago

6.0.5

10 months ago

5.0.6

11 months ago

5.0.5

11 months ago

5.0.4

12 months ago

5.0.3

12 months ago

6.0.1

11 months ago

6.0.0

11 months ago

6.0.3

11 months ago

6.0.2

11 months ago

6.0.4

11 months ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

4.0.9

2 years ago

4.0.10

2 years ago

4.0.7

2 years ago

4.0.8

2 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.6

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.18.1

2 years ago

3.18.0

3 years ago

3.17.3

3 years ago

3.17.2

3 years ago

3.17.1

3 years ago

3.17.0

3 years ago

3.16.0

3 years ago

3.15.8

3 years ago

3.15.7

3 years ago

3.15.6

3 years ago

3.15.5

3 years ago

3.15.4

3 years ago

3.15.3

3 years ago

3.15.2

3 years ago

3.15.1

3 years ago

3.15.0

3 years ago

3.14.1

3 years ago

3.14.0

3 years ago

3.13.0

3 years ago

3.12.0

3 years ago

3.11.2

3 years ago

3.11.1

3 years ago

3.10.11

3 years ago

3.11.0

3 years ago

3.10.10

3 years ago

3.10.9

3 years ago

3.10.8

3 years ago

3.10.7

3 years ago

3.10.6

3 years ago

3.10.5

3 years ago

3.10.4

3 years ago

3.10.3

3 years ago

3.10.1

3 years ago

3.10.2

3 years ago

3.7.3

3 years ago

3.9.0

3 years ago

3.8.0

3 years ago

3.10.0

3 years ago

3.8.1

3 years ago

3.7.2

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.6.0

3 years ago

3.5.5

3 years ago

3.5.4

3 years ago

3.5.3

3 years ago

3.5.2

3 years ago

3.5.1

3 years ago

3.5.0

3 years ago

3.4.1

3 years ago

3.4.0

3 years ago

3.3.2

3 years ago

3.3.1

3 years ago

3.2.7

3 years ago

3.3.0

3 years ago

3.2.6

3 years ago

3.2.5

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.7

3 years ago

3.1.6

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.9.0

4 years ago

2.8.0

4 years ago

2.7.2

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago