feat: expose getOctokit in script context for multi-token workflows#700
Open
feat: expose getOctokit in script context for multi-token workflows#700
getOctokit in script context for multi-token workflows#700Conversation
|
Hello from actions/github-script! (f1b2597) |
There was a problem hiding this comment.
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
getOctokitinto the script execution context insrc/main.ts. - Extends the
AsyncFunctionArgumentsTypeScript type to includegetOctokitwith 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
getOctokitis 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-urlfor GHES,user-agentwith orchestration ID,retries/request options, and the installedretry/requestLogplugins). This can lead to surprising differences betweengithubandgetOctokit(...)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., typegetOctokitastypeof 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expose
getOctokitfrom@actions/githubin the script execution context, enabling workflows that need to interact with multiple tokens without relying onrequire.Motivation
It's common for workflows to juggle multiple authentication tokens — for example, a
GITHUB_TOKENfor 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 ingithub-scriptis viarequire('@actions/github'), which is an undocumented implementation detail.This change makes
getOctokita first-class part of the script context alongsidegithub,context,core, etc.Changes
src/main.ts— AddedgetOctokitto the object passed tocallAsyncFunctionsrc/async-function.ts— AddedgetOctokitto theAsyncFunctionArgumentstype definition (with proper signature includingOctokitOptionsandOctokitPluginsupport)Usage
Checklist
getOctokitadded to script execution contextAsyncFunctionArguments) updatedgetOctokitdist/rebuilt