mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
fix bug with octokit url for github cloud
This commit is contained in:
parent
2d3b03bf12
commit
0bd545359e
2 changed files with 6 additions and 4 deletions
|
|
@ -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..
|
||||||
|
|
|
||||||
|
|
@ -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`
|
||||||
} : {}),
|
} : {}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue