Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GitHub API client for GitHub Actions

License

NotificationsYou must be signed in to change notification settings

octokit/action.js

Repository files navigation

GitHub API client for GitHub Actions

@latestBuild Status

Usage

Browsers

@octokit/action is not meant for browser usage.

Node

Install withnpm install @octokit/action

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

Important

As we useconditional exports, you will need to adapt yourtsconfig.json by setting"moduleResolution": "node16", "module": "node16".

See the TypeScript docs onpackage.json "exports".
See thishelpful guide on transitioning to ESM from@sindresorhus

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

name:My Node Actionon:  -pull_requestjobs:my-action:runs-on:ubuntu-lateststeps:# Check out code using git      -uses:actions/checkout@v4# Install Node 20      -uses:actions/setup-node@v4with: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.jsenv:GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}

SettingGITHUB_TOKEN on eitherwith: orenv: will work.

// .github/actions/my-script.jsimport{Octokit}from"@octokit/action";constoctokit=newOctokit();// `octokit` is now authenticated using GITHUB_TOKEN

Create an issue using REST API

import{Octokit}from"@octokit/action";constoctokit=newOctokit();const[owner,repo]=process.env.GITHUB_REPOSITORY.split("/");// See https://developer.github.com/v3/issues/#create-an-issueconst{ data}=awaitoctokit.request("POST /repos/{owner}/{repo}/issues",{  owner,  repo,title:"My test issue",});console.log("Issue created: %s",data.html_url);

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

Create an issue using GraphQL

import{Octokit}from"@octokit/action";constoctokit=newOctokit();consteventPayload=require(process.env.GITHUB_EVENT_PATH);constrepositoryId=eventPayload.repository.node_id;constresponse=awaitoctokit.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 toits README for the full API documentation.

TypeScript: Endpoint method parameters and responses

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

import{RestEndpointMethodTypes}from`@octokit/action`;typeChecksCreateParams=RestEndpointMethodTypes["checks"]["create"]["parameters"];typeChecksCreateResponse=RestEndpointMethodTypes["checks"]["create"]["response"];

Proxy Servers

If you useself-hosted runners and require a proxy server to access internet resources then you will need to ensure that you have correctly configured the runner forproxy servers.@octokit/action will pick up the configured proxy server environment variables and configure@octokit/core with the correctrequest.dispatcher usingProxyAgent. If you need to supply a differentrequest.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

About

GitHub API client for GitHub Actions

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors20


[8]ページ先頭

©2009-2025 Movatter.jp