Skip to content

Commit 50b94b2

Browse files
Connections UX pass + query optimizations (#212)
1 parent b77f55f commit 50b94b2

File tree

30 files changed

+1430
-948
lines changed

30 files changed

+1430
-948
lines changed

packages/backend/src/connectionManager.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Connection, ConnectionSyncStatus, PrismaClient, Prisma, Repo } from "@sourcebot/db";
1+
import { Connection, ConnectionSyncStatus, PrismaClient, Prisma } from "@sourcebot/db";
22
import { Job, Queue, Worker } from 'bullmq';
3-
import { Settings, WithRequired } from "./types.js";
3+
import { Settings } from "./types.js";
44
import { ConnectionConfig } from "@sourcebot/schemas/v3/connection.type";
55
import { createLogger } from "./logger.js";
66
import os from 'os';
@@ -24,7 +24,7 @@ type JobPayload = {
2424
};
2525

2626
type JobResult = {
27-
repoCount: number
27+
repoCount: number,
2828
}
2929

3030
export class ConnectionManager implements IConnectionManager {
@@ -82,7 +82,7 @@ export class ConnectionManager implements IConnectionManager {
8282
}, this.settings.resyncConnectionPollingIntervalMs);
8383
}
8484

85-
private async runSyncJob(job: Job<JobPayload>) {
85+
private async runSyncJob(job: Job<JobPayload>): Promise<JobResult> {
8686
const { config, orgId } = job.data;
8787
// @note: We aren't actually doing anything with this atm.
8888
const abortController = new AbortController();
@@ -105,6 +105,7 @@ export class ConnectionManager implements IConnectionManager {
105105
id: job.data.connectionId,
106106
},
107107
data: {
108+
syncStatus: ConnectionSyncStatus.SYNCING,
108109
syncStatusMetadata: {}
109110
}
110111
})
@@ -233,12 +234,25 @@ export class ConnectionManager implements IConnectionManager {
233234
this.logger.info(`Connection sync job ${job.id} completed`);
234235
const { connectionId } = job.data;
235236

237+
let syncStatusMetadata: Record<string, unknown> = (await this.db.connection.findUnique({
238+
where: { id: connectionId },
239+
select: { syncStatusMetadata: true }
240+
}))?.syncStatusMetadata as Record<string, unknown> ?? {};
241+
const { notFound } = syncStatusMetadata as { notFound: {
242+
users: string[],
243+
orgs: string[],
244+
repos: string[],
245+
}};
246+
236247
await this.db.connection.update({
237248
where: {
238249
id: connectionId,
239250
},
240251
data: {
241-
syncStatus: ConnectionSyncStatus.SYNCED,
252+
syncStatus:
253+
notFound.users.length > 0 ||
254+
notFound.orgs.length > 0 ||
255+
notFound.repos.length > 0 ? ConnectionSyncStatus.SYNCED_WITH_WARNINGS : ConnectionSyncStatus.SYNCED,
242256
syncedAt: new Date()
243257
}
244258
})

packages/backend/src/gitea.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const getGiteaReposFromConfig = async (config: GiteaConnectionConfig, org
8282
const tagGlobs = config.revisions.tags;
8383
allRepos = await Promise.all(
8484
allRepos.map(async (allRepos) => {
85-
const [owner, name] = allRepos.name!.split('/');
85+
const [owner, name] = allRepos.full_name!.split('/');
8686
let tags = (await fetchWithRetry(
8787
() => getTagsForRepo(owner, name, api),
8888
`tags for ${owner}/${name}`,

packages/backend/src/gitlab.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const GITLAB_CLOUD_HOSTNAME = "gitlab.com";
1212
export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig, orgId: number, db: PrismaClient) => {
1313
const tokenResult = config.token ? await getTokenFromConfig(config.token, orgId, db) : undefined;
1414
const token = tokenResult?.token ?? FALLBACK_GITLAB_TOKEN;
15-
const secretKey = tokenResult?.secretKey;
1615

1716
const api = new Gitlab({
1817
...(token ? {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "ConnectionSyncStatus" ADD VALUE 'SYNCED_WITH_WARNINGS';

packages/db/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum ConnectionSyncStatus {
2626
IN_SYNC_QUEUE
2727
SYNCING
2828
SYNCED
29+
SYNCED_WITH_WARNINGS
2930
FAILED
3031
}
3132

packages/web/next.config.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ const nextConfig = {
2626
remotePatterns: [
2727
{
2828
protocol: 'https',
29-
hostname: 'avatars.githubusercontent.com',
30-
},
31-
{
32-
protocol: 'https',
33-
hostname: 'gitlab.com',
29+
hostname: '**',
3430
},
3531
]
3632
}

0 commit comments

Comments
 (0)