fix bug with octokit url for github cloud
Some checks are pending
Publish to ghcr / build (linux/amd64, blacksmith-4vcpu-ubuntu-2404) (push) Waiting to run
Publish to ghcr / build (linux/arm64, blacksmith-8vcpu-ubuntu-2204-arm) (push) Waiting to run
Publish to ghcr / merge (push) Blocked by required conditions

This commit is contained in:
msukkari 2025-10-25 21:57:13 -07:00
parent 2d3b03bf12
commit 0bd545359e
2 changed files with 6 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import { Job, Queue, Worker } from 'bullmq';
import { Redis } from 'ioredis'; import { Redis } from 'ioredis';
import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js"; import { PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES } from "../constants.js";
import { env } from "../env.js"; import { env } from "../env.js";
import { createOctokitFromToken, getRepoCollaborators } from "../github.js"; import { createOctokitFromToken, getRepoCollaborators, GITHUB_CLOUD_HOSTNAME } from "../github.js";
import { Settings } from "../types.js"; import { Settings } from "../types.js";
import { getAuthCredentialsForRepo } from "../utils.js"; import { getAuthCredentialsForRepo } from "../utils.js";
@ -164,9 +164,10 @@ export class RepoPermissionSyncer {
const userIds = await (async () => { const userIds = await (async () => {
if (repo.external_codeHostType === 'github') { if (repo.external_codeHostType === 'github') {
const isGitHubCloud = credentials.hostUrl ? new URL(credentials.hostUrl).hostname === GITHUB_CLOUD_HOSTNAME : false;
const { octokit } = await createOctokitFromToken({ const { octokit } = await createOctokitFromToken({
token: credentials.token, token: credentials.token,
url: credentials.hostUrl, url: isGitHubCloud ? undefined : credentials.hostUrl,
}); });
// @note: this is a bit of a hack since the displayName _might_ not be set.. // @note: this is a bit of a hack since the displayName _might_ not be set..

View file

@ -11,8 +11,8 @@ import { env } from "./env.js";
import { GithubAppManager } from "./ee/githubAppManager.js"; import { GithubAppManager } from "./ee/githubAppManager.js";
import { hasEntitlement } from "@sourcebot/shared"; import { hasEntitlement } from "@sourcebot/shared";
export const GITHUB_CLOUD_HOSTNAME = "github.com";
const logger = createLogger('github'); const logger = createLogger('github');
const GITHUB_CLOUD_HOSTNAME = "github.com";
export type OctokitRepository = { export type OctokitRepository = {
name: string, name: string,
@ -44,9 +44,10 @@ const isHttpError = (error: unknown, status: number): boolean => {
} }
export const createOctokitFromToken = async ({ token, url }: { token?: string, url?: string }): Promise<{ octokit: Octokit, isAuthenticated: boolean }> => { export const createOctokitFromToken = async ({ token, url }: { token?: string, url?: string }): Promise<{ octokit: Octokit, isAuthenticated: boolean }> => {
const isGitHubCloud = url ? new URL(url).hostname === GITHUB_CLOUD_HOSTNAME : false;
const octokit = new Octokit({ const octokit = new Octokit({
auth: token, auth: token,
...(url ? { ...(url && !isGitHubCloud ? {
baseUrl: `${url}/api/v3` baseUrl: `${url}/api/v3`
} : {}), } : {}),
}); });