• Stars
    star
    369
  • Rank 115,686 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GitHub Action to send arbitrary requests to GitHub's REST API

Octokit Request Action

A GitHub Action to send arbitrary requests to GitHub's REST API

Build Status

Usage

Minimal example

name: Log latest release
on:
  push:
    branches:
      - main

jobs:
  logLatestRelease:
    runs-on: ubuntu-latest
    steps:
      - uses: octokit/[email protected]
        id: get_latest_release
        with:
          route: GET /repos/{owner}/{repo}/releases/latest
          owner: octokit
          repo: request-action
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - run: "echo latest release: '${{ steps.get_latest_release.outputs.data }}'"

More complex examples involving POST, setting custom media types, and parsing output data

name: Check run
on:
  push:
    branches:
      - main

jobs:
  create-file:
    runs-on: ubuntu-latest
    steps:
      # Create check run
      - uses: octokit/[email protected]
        id: create_check_run
        with:
          route: POST /repos/{owner}/{repo}/check-runs
          owner: octokit
          repo: request-action
          name: "Test check run"
          head_sha: ${{ github.sha }}
          output: | # The | is significant!
            title: Test check run title
            summary: A summary of the test check run
            images:
              - alt: Test image
                image_url: https://octodex.github.com/images/jetpacktocat.png
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      # Download file
      - uses: octokit/[email protected]
        id: download_file
        with:
          route: GET /repos/OWNER/REPO/contents/README.md
          owner: octokit
          repo: request-action
          mediaType: | # The | is significant!
            format: raw
         env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      # Update check run to completed, successful status
      - uses: octokit/[email protected]
        id: update_check_run
        with:
          route: PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}
          owner: octokit
          repo: request-action
          check_run_id: ${{ fromJson(steps.create_check_run.outputs.data).id }}
          conclusion: "success"
          status: "completed"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Handle errors

name: Log latest release
on:
  push:
    branches:
      - main

jobs:
  handleError:
    runs-on: ubuntu-latest
    steps:
      - uses: octokit/[email protected]
        id: get_release
        with:
          route: GET /repos/{owner}/{repo}/releases/v0.9.9
          owner: octokit
          repo: request-action
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - run: "echo Release found: '${{ steps.get_release.outputs.data }}'"
      - run: "echo Release could not be found. Request failed with status '${{ steps.get_release.outputs.status }}'"
        if: ${{ failure() }}

Inputs

To use request body parameters, simply pass in an input matching the parameter name. See previous examples.

Due to how request parameters are processed, it may be necessary in some cases to first encode the value as either JSON or a block scalar:

env:
  REQUEST_BODY: |
    Multi-line string with *special* characters:
    - "'`
with:
  # As JSON
  body: ${{ toJSON(env.REQUEST_BODY) }}

  # As block scalar
  body: |
    |
    ${{ env.REQUEST_BODY }}

Debugging

To see additional debug logs, create a secret with the name: ACTIONS_STEP_DEBUG and value true.

How it works

octokit/request-action is using @octokit/request internally with the addition that requests are automatically authenticated using the GITHUB_TOKEN environment variable. It is required to prevent rate limiting, as all anonymous requests from the same origin count against the same low rate.

The actions sets data output to the response data. The action also sets the headers (again, to a JSON string) and status output properties.

To access deep values of outputs.data and outputs.headers, check out the fromJson function.

Warnings

The GitHub Actions runners are currently showing warnings when using this action that look like:

##[warning]Unexpected input 'repository', valid inputs are ['route', 'mediaType']

The reason for this warning is because the repository key is not listed as a possible value in actions.yml. This warning will appear for any key used under the with except route and mediaType. Due to the flexible nature of the required inputs depending on the route, not all of the possible parameters can be listed in actions.yml, so you will see this warning under normal usage of the action. As long as you see a 200 response code at the bottom of the output, everything should have worked properly and you can ignore the warnings. The response code will appear at the bottom of the output from the action and looks like:

< 200 451ms

See Issue #26 for more information.

License

MIT

More Repositories

1

octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
TypeScript
6,955
star
2

octokit.rb

Ruby toolkit for the GitHub API
Ruby
3,848
star
3

octokit.net

A GitHub API client library for .NET
C#
2,679
star
4

octokit.objc

GitHub API client for Objective-C
Objective-C
1,838
star
5

core.js

Extendable client for GitHub's REST & GraphQL APIs
TypeScript
1,184
star
6

rest.js

GitHub REST API client for JavaScript
TypeScript
548
star
7

graphql.js

GitHub GraphQL API client for browsers and Node
TypeScript
465
star
8

authentication-strategies.js

GitHub API authentication strategies for Browsers, Node.js, and Deno
318
star
9

webhooks.js

GitHub webhook events toolset for Node.js
TypeScript
307
star
10

go-octokit

Simple Go wrapper for the GitHub API
Go
258
star
11

request.js

Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
TypeScript
228
star
12

webhooks

machine-readable, always up-to-date GitHub Webhooks specifications
TypeScript
225
star
13

action.js

GitHub API client for GitHub Actions
TypeScript
185
star
14

graphql-schema

GitHub’s GraphQL Schema with validation. Automatically updated.
JavaScript
176
star
15

app.js

GitHub Apps toolset for Node.js
TypeScript
157
star
16

auth-app.js

GitHub App authentication for JavaScript
TypeScript
146
star
17

octokit.graphql.net

A GitHub GraphQL client library for .NET
C#
143
star
18

types.ts

Shared TypeScript definitions for Octokit projects
TypeScript
133
star
19

graphql-action

A GitHub Action to send queries to GitHub's GraphQL API
JavaScript
121
star
20

plugin-rest-endpoint-methods.js

Octokit plugin adding one method for all of api.github.com REST API endpoints
TypeScript
114
star
21

plugin-throttling.js

Octokit plugin for GitHub’s recommended request throttling
TypeScript
105
star
22

fixtures

Fixtures for all the octokittens
JavaScript
102
star
23

auth-token.js

GitHub API token authentication for browsers and Node.js
TypeScript
99
star
24

routes

machine-readable, always up-to-date GitHub REST API route specifications
JavaScript
84
star
25

oauth-app.js

GitHub OAuth toolset for Node.js
TypeScript
81
star
26

auth-oauth-app.js

GitHub OAuth App authentication for JavaScript
TypeScript
65
star
27

go-sdk

A generated Go SDK from GitHub's OpenAPI specification. Built on Kiota.
Go
64
star
28

endpoint.js

Turns REST API endpoints into generic request options
TypeScript
57
star
29

dotnet-sdk

C#
55
star
30

webhooks.net

GitHub webhook events toolset for .NET
C#
51
star
31

plugin-paginate-rest.js

Octokit plugin to paginate REST API endpoint responses
TypeScript
46
star
32

octopoller.rb

A micro gem for polling and retrying. Perfect for making repeating requests.
Ruby
45
star
33

auth-action.js

GitHub API token authentication for GitHub Actions
TypeScript
43
star
34

openapi

GitHub's official OpenAPI spec with Octokit extensions
JavaScript
43
star
35

plugin-paginate-graphql.js

Octokit plugin to paginate GraphQL Query responses
TypeScript
42
star
36

openapi-types.ts

Generated TypeScript definitions based on GitHub's OpenAPI spec
JavaScript
40
star
37

plugin-retry.js

Octokit plugin for GitHub’s recommended request retries
TypeScript
36
star
38

fixtures-server

Fixtures server for browser & language agnositic octokit testing
JavaScript
28
star
39

webhooks-methods.js

Methods to handle GitHub Webhook requests
TypeScript
23
star
40

octokit-next.js

JavaScript
21
star
41

plugin-enterprise-server.js

Octokit plugin for GitHub Enterprise REST APIs
TypeScript
19
star
42

auth-oauth-user-client.js

OAuth user authentication without exposing client secret
18
star
43

auth-oauth-user.js

Octokit authentication strategy for OAuth clients
TypeScript
17
star
44

create-octokit-project.js

"npm init" script to create a new Octokit JS module
JavaScript
16
star
45

oauth-authorization-url.js

Universal library to retrieve GitHub’s identity URL for the OAuth web flow
TypeScript
16
star
46

plugin-create-or-update-text-file.js

Convenience method to create/edit/delete a text file based on its current content
TypeScript
13
star
47

request-error.js

Error class for Octokit request errors
TypeScript
13
star
48

app-permissions

machine-readable, always up-to-date GitHub App permissions
JavaScript
12
star
49

auth-oauth-device.js

GitHub OAuth Device authentication strategy for JavaScript
TypeScript
10
star
50

handbook

Handbook for Octokit maintainers and GitHub integrators
9
star
51

auth-basic.js

GitHub API Basic authentication for browsers and Node.js
TypeScript
8
star
52

source-generator

Generates SDKs from GitHub's OpenAPI specification. Built on Kiota.
C#
8
star
53

discussions

discussions and planning for Octokit clients
7
star
54

plugin-request-log.js

Log all requests and request errors
TypeScript
7
star
55

plugin-enterprise-cloud.js

Octokit plugin for GitHub Enterprise Cloud REST APIs
TypeScript
7
star
56

.github

6
star
57

tsconfig

TypeScript configuration for Octokit packages
JavaScript
5
star
58

oauth-methods.js

Request methods to create and refresh user access tokens for OAuth and GitHub Apps
TypeScript
5
star
59

auth-callback.js

GitHub API authentication using a callback method
TypeScript
5
star
60

auth-unauthenticated.js

strategy for explicitly unauthenticated Octokit instances
TypeScript
5
star
61

tf-acc-test-empty-f89p1

Terraform acceptance test f89p1
2
star
62

plugin-enterprise-compatibility.js

Octokit plugin for improving GHE compatibility
TypeScript
2
star
63

openapi-webhooks

JavaScript
2
star
64

go-sdk-enterprise-server

A generated Go SDK from GitHub's OpenAPI specification, for the Enterprise Server product. Built on Kiota.
1
star
65

dotnet-sdk-enterprise-cloud

A generated .NET SDK from GitHub's OpenAPI specification, for the Enterprise Cloud product. Built on Kiota.
C#
1
star
66

go-sdk-enterprise-cloud

A generated Go SDK from GitHub's OpenAPI specification, for the Enterprise Cloud product. Built on Kiota.
Go
1
star
67

dotnet-sdk-enterprise-server

A generated .NET SDK from GitHub's OpenAPI specification, for the Enterprise Server product. Built on Kiota.
1
star