diff --git a/packages/backend/src/connectionManager.ts b/packages/backend/src/connectionManager.ts index eaba0638..e3be9941 100644 --- a/packages/backend/src/connectionManager.ts +++ b/packages/backend/src/connectionManager.ts @@ -1,14 +1,13 @@ -import { Connection, PrismaClient, ConnectionSyncJobStatus } from "@sourcebot/db"; -import { Job, Queue, ReservedJob, Worker } from "groupmq"; -import { Settings } from "./types.js"; -import { createLogger } from "@sourcebot/logger"; -import { Redis } from 'ioredis'; -import { RepoData, compileGithubConfig, compileGitlabConfig, compileGiteaConfig, compileGerritConfig, compileBitbucketConfig, compileAzureDevOpsConfig, compileGenericGitHostConfig } from "./repoCompileUtils.js"; -import { BackendError, BackendException } from "@sourcebot/error"; -import { env } from "./env.js"; import * as Sentry from "@sentry/node"; -import { loadConfig, syncSearchContexts } from "@sourcebot/shared"; +import { Connection, ConnectionSyncJobStatus, PrismaClient } from "@sourcebot/db"; +import { createLogger } from "@sourcebot/logger"; import { ConnectionConfig } from "@sourcebot/schemas/v3/connection.type"; +import { loadConfig, syncSearchContexts } from "@sourcebot/shared"; +import { Job, Queue, ReservedJob, Worker } from "groupmq"; +import { Redis } from 'ioredis'; +import { env } from "./env.js"; +import { compileAzureDevOpsConfig, compileBitbucketConfig, compileGenericGitHostConfig, compileGerritConfig, compileGiteaConfig, compileGithubConfig, compileGitlabConfig } from "./repoCompileUtils.js"; +import { Settings } from "./types.js"; import { groupmqLifecycleExceptionWrapper } from "./utils.js"; const LOG_TAG = 'connection-manager'; @@ -166,53 +165,32 @@ export class ConnectionManager { const config = rawConnectionConfig as unknown as ConnectionConfig; - let result: { - repoData: RepoData[], - warnings: string[], - } = { - repoData: [], - warnings: [], - }; - - try { - result = await (async () => { - switch (config.type) { - case 'github': { - return await compileGithubConfig(config, job.data.connectionId, orgId, this.db, abortController); - } - case 'gitlab': { - return await compileGitlabConfig(config, job.data.connectionId, orgId, this.db); - } - case 'gitea': { - return await compileGiteaConfig(config, job.data.connectionId, orgId, this.db); - } - case 'gerrit': { - return await compileGerritConfig(config, job.data.connectionId, orgId); - } - case 'bitbucket': { - return await compileBitbucketConfig(config, job.data.connectionId, orgId, this.db); - } - case 'azuredevops': { - return await compileAzureDevOpsConfig(config, job.data.connectionId, orgId, this.db); - } - case 'git': { - return await compileGenericGitHostConfig(config, job.data.connectionId, orgId); - } + const result = await (async () => { + switch (config.type) { + case 'github': { + return await compileGithubConfig(config, job.data.connectionId, orgId, this.db, abortController); + } + case 'gitlab': { + return await compileGitlabConfig(config, job.data.connectionId, orgId, this.db); + } + case 'gitea': { + return await compileGiteaConfig(config, job.data.connectionId, orgId, this.db); + } + case 'gerrit': { + return await compileGerritConfig(config, job.data.connectionId, orgId); + } + case 'bitbucket': { + return await compileBitbucketConfig(config, job.data.connectionId, orgId, this.db); + } + case 'azuredevops': { + return await compileAzureDevOpsConfig(config, job.data.connectionId, orgId, this.db); + } + case 'git': { + return await compileGenericGitHostConfig(config, job.data.connectionId, orgId); } - })(); - } catch (err) { - logger.error(`Failed to compile repo data for connection ${job.data.connectionId} (${connectionName}): ${err}`); - Sentry.captureException(err); - - if (err instanceof BackendException) { - throw err; - } else { - throw new BackendException(BackendError.CONNECTION_SYNC_SYSTEM_ERROR, { - message: `Failed to compile repo data for connection ${job.data.connectionId}`, - }); } - } - + })(); + let { repoData, warnings } = result; await this.db.connectionSyncJob.update({ diff --git a/packages/backend/src/gerrit.ts b/packages/backend/src/gerrit.ts index 25e3cfa7..ef149648 100644 --- a/packages/backend/src/gerrit.ts +++ b/packages/backend/src/gerrit.ts @@ -37,7 +37,6 @@ const logger = createLogger('gerrit'); export const getGerritReposFromConfig = async (config: GerritConnectionConfig): Promise => { const url = config.url.endsWith('/') ? config.url : `${config.url}/`; - const hostname = new URL(config.url).hostname; let { durationMs, data: projects } = await measure(async () => { try { diff --git a/packages/backend/src/git.ts b/packages/backend/src/git.ts index 80d34cef..dbb602e1 100644 --- a/packages/backend/src/git.ts +++ b/packages/backend/src/git.ts @@ -35,6 +35,11 @@ const createGitClientForPath = (path: string, onProgress?: onProgressFn, signal? * parent directory. */ GIT_CEILING_DIRECTORIES: parentPath, + /** + * Disable git credential prompts. This ensures that git operations will fail + * immediately if credentials are not available, rather than prompting for input. + */ + GIT_TERMINAL_PROMPT: '0', }) .cwd({ path, diff --git a/packages/backend/src/github.ts b/packages/backend/src/github.ts index 0b64eca8..ca4253c0 100644 --- a/packages/backend/src/github.ts +++ b/packages/backend/src/github.ts @@ -1,15 +1,14 @@ import { Octokit } from "@octokit/rest"; -import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type"; -import { createLogger } from "@sourcebot/logger"; -import { getTokenFromConfig, measure, fetchWithRetry } from "./utils.js"; -import micromatch from "micromatch"; -import { PrismaClient } from "@sourcebot/db"; -import { BackendException, BackendError } from "@sourcebot/error"; -import { processPromiseResults, throwIfAnyFailed } from "./connectionUtils.js"; import * as Sentry from "@sentry/node"; -import { env } from "./env.js"; -import { GithubAppManager } from "./ee/githubAppManager.js"; +import { PrismaClient } from "@sourcebot/db"; +import { createLogger } from "@sourcebot/logger"; +import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type"; import { hasEntitlement } from "@sourcebot/shared"; +import micromatch from "micromatch"; +import { processPromiseResults, throwIfAnyFailed } from "./connectionUtils.js"; +import { GithubAppManager } from "./ee/githubAppManager.js"; +import { env } from "./env.js"; +import { fetchWithRetry, getTokenFromConfig, measure } from "./utils.js"; export const GITHUB_CLOUD_HOSTNAME = "github.com"; const logger = createLogger('github'); @@ -114,22 +113,8 @@ export const getGitHubReposFromConfig = async (config: GithubConnectionConfig, o await octokit.rest.users.getAuthenticated(); } catch (error) { Sentry.captureException(error); - - if (isHttpError(error, 401)) { - const e = new BackendException(BackendError.CONNECTION_SYNC_INVALID_TOKEN, { - ...(config.token && 'secret' in config.token ? { - secretKey: config.token.secret, - } : {}), - }); - Sentry.captureException(e); - throw e; - } - - const e = new BackendException(BackendError.CONNECTION_SYNC_SYSTEM_ERROR, { - message: `Failed to authenticate with GitHub`, - }); - Sentry.captureException(e); - throw e; + logger.error(`Failed to authenticate with GitHub`, error); + throw error; } }