Skip to content

Commit 0bd5453

Browse files
committed
fix bug with octokit url for github cloud
1 parent 2d3b03b commit 0bd5453

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/backend/src/ee/repoPermissionSyncer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Job, Queue, Worker } from 'bullmq';
66
import { Redis } from 'ioredis';
77
import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js";
88
import { env } from "../env.js";
9-
import { createOctokitFromToken, getRepoCollaborators } from "../github.js";
9+
import { createOctokitFromToken, getRepoCollaborators, GITHUB_CLOUD_HOSTNAME } from "../github.js";
1010
import { Settings } from "../types.js";
1111
import { getAuthCredentialsForRepo } from "../utils.js";
1212

@@ -164,9 +164,10 @@ export class RepoPermissionSyncer {
164164

165165
const userIds = await (async () => {
166166
if (repo.external_codeHostType === 'github') {
167+
const isGitHubCloud = credentials.hostUrl ? new URL(credentials.hostUrl).hostname === GITHUB_CLOUD_HOSTNAME : false;
167168
const { octokit } = await createOctokitFromToken({
168169
token: credentials.token,
169-
url: credentials.hostUrl,
170+
url: isGitHubCloud ? undefined : credentials.hostUrl,
170171
});
171172

172173
// @note: this is a bit of a hack since the displayName _might_ not be set..

packages/backend/src/github.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { env } from "./env.js";
1111
import { GithubAppManager } from "./ee/githubAppManager.js";
1212
import { hasEntitlement } from "@sourcebot/shared";
1313

14+
export const GITHUB_CLOUD_HOSTNAME = "github.com";
1415
const logger = createLogger('github');
15-
const GITHUB_CLOUD_HOSTNAME = "github.com";
1616

1717
export type OctokitRepository = {
1818
name: string,
@@ -44,9 +44,10 @@ const isHttpError = (error: unknown, status: number): boolean => {
4444
}
4545

4646
export const createOctokitFromToken = async ({ token, url }: { token?: string, url?: string }): Promise<{ octokit: Octokit, isAuthenticated: boolean }> => {
47+
const isGitHubCloud = url ? new URL(url).hostname === GITHUB_CLOUD_HOSTNAME : false;
4748
const octokit = new Octokit({
4849
auth: token,
49-
...(url ? {
50+
...(url && !isGitHubCloud ? {
5051
baseUrl: `${url}/api/v3`
5152
} : {}),
5253
});

0 commit comments

Comments
 (0)