Skip to content

Fix ReferenceError: import Octokit on GHES in REST scripting guide - #47109

Open
ShakilUrRehman21 wants to merge 1 commit into
github:mainfrom
ShakilUrRehman21:fix/rest-scripting-guide-ghes-octokit-import
Open

ShakilUrRehman21 wants to merge 1 commit into
github:mainfrom
ShakilUrRehman21:fix/rest-scripting-guide-ghes-octokit-import

Conversation

@ShakilUrRehman21

Copy link
Copy Markdown
Contributor

Why:

In content/rest/guides/scripting-with-the-rest-api-and-javascript.md, the example for authenticating with a GitHub App configures Octokit.defaults({ baseUrl: ... }) when targeting GitHub Enterprise Server (ghes):

import { App } from "octokit";

const app = new App({
  appId: APP_ID,
  privateKey: PRIVATE_KEY,{% ifversion ghes %}
  Octokit: Octokit.defaults({
    baseUrl: "{% data variables.product.rest_url %}",
  }),{% endif %}
});

Because line 59 only imports App from "octokit", referencing Octokit.defaults on GHES causes a runtime error:

ReferenceError: Octokit is not defined

This PR updates the import statement to conditionally import Octokit when on GHES (import { App{% ifversion ghes %}, Octokit{% endif %} } from "octokit";), matching the established pattern in content/apps/creating-github-apps/writing-code-for-a-github-app/building-a-github-app-that-responds-to-webhook-events.md.

What's being changed:

  • Updated the import in content/rest/guides/scripting-with-the-rest-api-and-javascript.md to import Octokit alongside App on ghes versions.

Check off the following:

  • A subject matter expert (SME) has reviewed the technical accuracy of the content in this PR. In most cases, the author can be the SME. Open source contributions may require an SME review from GitHub staff.
  • The changes in this PR meet the docs fundamentals that are required for all content.
  • All CI checks are passing and the changes look good in the review environment.

Copilot AI lite review requested due to automatic review settings November 28, 2026 11:51
@github-actions github-actions Bot added the triage Do not begin working on this issue until triaged by the team label Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

How to review these changes 👓

Thank you for your contribution. To review these changes, choose one of the following options:

A Hubber will need to deploy your changes internally to review.

Table of review links

Note: Please update the URL for your staging server or codespace.

The table shows the files in the content directory that were changed in this pull request. This helps you review your changes on a staging server. Changes to the data directory are not included in this table.

Source Review Production What Changed
rest/guides/scripting-with-the-rest-api-and-javascript.md fpt
ghec
ghes@ 3.23 3.22 3.21 3.20 3.19
fpt
ghec
ghes@ 3.23 3.22 3.21 3.20 3.19

Key: fpt: Free, Pro, Team; ghec: GitHub Enterprise Cloud; ghes: GitHub Enterprise Server

🤖 This comment is automatically generated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change addresses the GHES-specific ReferenceError by conditionally importing Octokit where Octokit.defaults is used, with no active review issues reported.

No open issues 🎉

What changed in this PR

This PR fixes a GHES-specific ReferenceError in the REST API JavaScript scripting guide by conditionally importing Octokit where the example uses Octokit.defaults.

Changes:

  • Conditionally imports Octokit alongside App for GHES documentation builds.
  • Preserves the existing App-only import for other supported versions.
File Description
content/​rest/​guides/​scripting-with-the-rest-api-and-javascript.md Updates the GitHub App authentication example to conditionally import Octokit for GHES.

Review effort: Lite

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage Do not begin working on this issue until triaged by the team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants