Skip to content

feat: expose getOctokit in script context for multi-token workflows#700

Open
salmanmkc wants to merge 2 commits intomainfrom
salmanmkc/expose-getoctokit
Open

feat: expose getOctokit in script context for multi-token workflows#700
salmanmkc wants to merge 2 commits intomainfrom
salmanmkc/expose-getoctokit

Conversation

@salmanmkc
Copy link
Contributor

Summary

Expose getOctokit from @actions/github in the script execution context, enabling workflows that need to interact with multiple tokens without relying on require.

Motivation

It's common for workflows to juggle multiple authentication tokens — for example, a GITHUB_TOKEN for the current repo and a separate PAT or GitHub App installation token for cross-repo operations. Currently, the only way to create additional Octokit clients in github-script is via require('@actions/github'), which is an undocumented implementation detail.

This change makes getOctokit a first-class part of the script context alongside github, context, core, etc.

Changes

  • src/main.ts — Added getOctokit to the object passed to callAsyncFunction
  • src/async-function.ts — Added getOctokit to the AsyncFunctionArguments type definition (with proper signature including OctokitOptions and OctokitPlugin support)

Usage

- uses: actions/github-script@v8
  env:
    APP_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
  with:
    script: |
      // Default client using github-token input
      const { data: issue } = await github.rest.issues.get({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: context.issue.number
      })

      // Second client using a different token
      const appOctokit = getOctokit(process.env.APP_TOKEN)
      await appOctokit.rest.repos.createDispatchEvent({
        owner: 'my-org',
        repo: 'another-repo',
        event_type: 'trigger-deploy',
        client_payload: { issue: issue.number }
      })

Checklist

  • getOctokit added to script execution context
  • TypeScript type (AsyncFunctionArguments) updated
  • README updated to document getOctokit
  • dist/ rebuilt
  • Tests for multi-token usage

Copilot AI review requested due to automatic review settings March 1, 2026 00:26
@salmanmkc salmanmkc requested a review from a team as a code owner March 1, 2026 00:26
@salmanmkc salmanmkc temporarily deployed to debug-integration-test March 1, 2026 00:26 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Mar 1, 2026

Hello from actions/github-script! (f1b2597)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes getOctokit in the github-script runtime context so user scripts can create additional authenticated Octokit clients (e.g., for multi-token workflows) without relying on require('@actions/github').

Changes:

  • Passes getOctokit into the script execution context in src/main.ts.
  • Extends the AsyncFunctionArguments TypeScript type to include getOctokit with an Octokit-typed signature.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main.ts Adds getOctokit to the object passed into callAsyncFunction so scripts can access it.
src/async-function.ts Updates the script context type (AsyncFunctionArguments) to type getOctokit and imports Octokit types.
Comments suppressed due to low confidence (2)

src/main.ts:71

  • getOctokit is being passed through directly from @actions/github, so any Octokit clients created inside the user script won’t automatically inherit this action’s configured defaults (e.g., base-url for GHES, user-agent with orchestration ID, retries/request options, and the installed retry/requestLog plugins). This can lead to surprising differences between github and getOctokit(...) behavior. Consider exposing a wrapper that pre-applies the same options/plugins by default (while still allowing callers to override/extend options/plugins when needed).
      github,
      octokit: github,
      getOctokit,
      context,
      core,

src/async-function.ts:20

  • This adds a new deep import from @octokit/core/types, but the codebase already imports Octokit types via @octokit/core/dist-types/types (e.g. src/retry-options.ts). To stay consistent (and to reduce the risk of relying on a non-exported subpath), align the import path with the existing convention or derive the type directly from @actions/github (e.g., type getOctokit as typeof import('@actions/github').getOctokit) so the signature can’t drift from the actual implementation.
import {GitHub} from '@actions/github/lib/utils'
import * as glob from '@actions/glob'
import * as io from '@actions/io'
import type {OctokitOptions, OctokitPlugin} from '@octokit/core/types'

const AsyncFunction = Object.getPrototypeOf(async () => null).constructor

export declare type AsyncFunctionArguments = {
  context: Context
  core: typeof core
  github: InstanceType<typeof GitHub>
  octokit: InstanceType<typeof GitHub>
  getOctokit: (
    token: string,
    options?: OctokitOptions,
    ...additionalPlugins: OctokitPlugin[]
  ) => InstanceType<typeof GitHub>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@salmanmkc salmanmkc deployed to debug-integration-test March 1, 2026 01:30 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants