GithubHelp home page GithubHelp logo

nickfnblum / action.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from octokit/action.js

0.0 0.0 0.0 4.16 MB

GitHub API client for GitHub Actions

License: MIT License

JavaScript 19.84% TypeScript 80.16%

action.js's Introduction

action.js

GitHub API client for GitHub Actions

@latest Build Status

Usage

Browsers

@octokit/action is not meant for browser usage.

Node

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@v2
      # Install Node 12
      - uses: actions/setup-node@v1
        with:
          version: 12
      - 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

action.js's People

Contributors

renovate[bot] avatar dependabot[bot] avatar gr2m avatar greenkeeper[bot] avatar wolfy1339 avatar octokitbot avatar nickfloyd avatar kfcampbell avatar oscard0m avatar zegl avatar ataylorme avatar copperwall avatar therealketo avatar imichka avatar steve-norman-rft avatar thomas-maqua-db avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.