- Notifications
You must be signed in to change notification settings - Fork52
GitHub API client for GitHub Actions
License
octokit/action.js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
GitHub API client for GitHub Actions
| Browsers |
|
|---|---|
| Node | Install with 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
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.
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",},);
@octokit/action is build upon@octokit/core. Refer toits README for the full API documentation.
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"];
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.
@octokit/action is simply a@octokit/core constructor, pre-authenticate using@octokit/auth-action.
The source code is … simple:src/index.ts.
About
GitHub API client for GitHub Actions
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.