Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/api/src/handlers/environments/createEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type TaskPayload,
environmentConfigSchema,
getMissingEnvironmentRepositoryError,
getEnvironmentRepositoryInstallationError,
getEnvironmentRepositoryConnectionError,
} from '@roomote/types';
import { captureActivationEnvironmentSaved } from '@roomote/telemetry/server';

Expand Down Expand Up @@ -66,10 +66,12 @@ export function isEnvironmentNameUniqueViolation(error: unknown): boolean {
export function getEnvironmentRepositoryConfigError(
repositoryRows: Array<{
fullName: string;
sourceControlProvider: string | null | undefined;
host: string | null | undefined;
installationId: string | number | null | undefined;
}>,
): string | null {
return getEnvironmentRepositoryInstallationError(repositoryRows);
return getEnvironmentRepositoryConnectionError(repositoryRows);
}

function extractRunId(auth: McpAuth): number | null {
Expand Down Expand Up @@ -273,7 +275,13 @@ export async function createEnvironment(
eq(repositories.isActive, true),
inArray(repositories.fullName, repositoryNames),
),
columns: { id: true, fullName: true, installationId: true },
columns: {
id: true,
fullName: true,
sourceControlProvider: true,
host: true,
installationId: true,
},
})
: [];

Expand Down
8 changes: 7 additions & 1 deletion apps/api/src/handlers/environments/updateEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ export async function updateEnvironment(
eq(repositories.isActive, true),
inArray(repositories.fullName, repositoryNames),
),
columns: { id: true, fullName: true, installationId: true },
columns: {
id: true,
fullName: true,
sourceControlProvider: true,
host: true,
installationId: true,
},
})
: [];

Expand Down
23 changes: 14 additions & 9 deletions apps/api/src/handlers/tasks/launchTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ADMIN_REQUIRED_LAUNCH_TYPES,
ALL_REPOSITORIES,
buildTaskTypePromptAndWorkspacePayload,
getEnvironmentRepositoryInstallationError,
getEnvironmentRepositoryConnectionError,
type StandardTask,
type SuggestedTasksTask,
TaskPayloadKind,
Expand Down Expand Up @@ -48,7 +48,7 @@ function normalizeRepositoryFullNames(body: TaskLaunchRequest): string[] {

async function validateSelectedRepositories(
repositoryFullNames: string[],
options: { requireSingleInstallation?: boolean } = {},
options: { requireSingleConnection?: boolean } = {},
): Promise<{ error: string; status: 400 | 404 } | null> {
if (repositoryFullNames.length === 0) {
return null;
Expand All @@ -59,7 +59,12 @@ async function validateSelectedRepositories(
eq(repositories.isActive, true),
inArray(repositories.fullName, repositoryFullNames),
),
columns: { fullName: true, installationId: true },
columns: {
fullName: true,
sourceControlProvider: true,
host: true,
installationId: true,
},
});

const foundRepositories = new Set(
Expand All @@ -76,12 +81,12 @@ async function validateSelectedRepositories(
};
}

if (options.requireSingleInstallation) {
const installationError =
getEnvironmentRepositoryInstallationError(orgRepositories);
if (options.requireSingleConnection) {
const connectionError =
getEnvironmentRepositoryConnectionError(orgRepositories);

if (installationError) {
return { error: installationError, status: 400 };
if (connectionError) {
return { error: connectionError, status: 400 };
}
}

Expand Down Expand Up @@ -223,7 +228,7 @@ export async function launchTask(

const repositoryValidationError = shouldValidateRepositorySelection
? await validateSelectedRepositories(repositoryFullNames, {
requireSingleInstallation: requestedType === 'environment-definition',
requireSingleConnection: requestedType === 'environment-definition',
})
: null;

Expand Down
89 changes: 88 additions & 1 deletion apps/web/src/trpc/commands/environments/index.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions apps/web/src/trpc/commands/environments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
type ComputeProvider,
type EnvironmentConfig,
environmentConfigSchema,
getEnvironmentRepositoryInstallationError,
getEnvironmentRepositoryConnectionError,
getMissingEnvironmentRepositoryError,
isExitedRunStatus,
normalizeRepositorySelection,
Expand Down Expand Up @@ -131,21 +131,27 @@ function assertAdmin(auth: UserAuthSuccess) {
type SelectedRepositorySummary = {
id: string;
fullName: string;
sourceControlProvider: string;
host: string | null;
installationId: string | null;
};

type EnvironmentRepositoryRow = {
id: string;
fullName: string;
sourceControlProvider: string;
host: string | null;
installationId: string | null;
};

function getEnvironmentRepositoryConfigError(
repositoriesToValidate: EnvironmentRepositoryRow[],
): string | null {
return getEnvironmentRepositoryInstallationError(
return getEnvironmentRepositoryConnectionError(
repositoriesToValidate.map((repository) => ({
fullName: repository.fullName,
sourceControlProvider: repository.sourceControlProvider,
host: repository.host,
installationId: repository.installationId,
})),
);
Expand All @@ -168,6 +174,8 @@ async function getEnvironmentRepositoryRows(
.select({
id: repositories.id,
fullName: repositories.fullName,
sourceControlProvider: repositories.sourceControlProvider,
host: repositories.host,
installationId: repositories.installationId,
})
.from(repositories)
Expand Down Expand Up @@ -203,6 +211,8 @@ async function resolveSelectedRepositories(
return {
id: repository.id,
fullName: repository.fullName,
sourceControlProvider: repository.sourceControlProvider,
host: repository.host,
installationId: repository.installationId,
};
});
Expand Down Expand Up @@ -1203,6 +1213,7 @@ export async function validateConfigCommand(
fullName: repositories.fullName,
installationId: repositories.installationId,
sourceControlProvider: repositories.sourceControlProvider,
host: repositories.host,
})
.from(repositories)
.where(
Expand Down
12 changes: 9 additions & 3 deletions packages/db/src/lib/declarative-environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';
import type { EnvironmentConfig } from '@roomote/types';
import {
environmentConfigSchema,
getEnvironmentRepositoryInstallationError,
getEnvironmentRepositoryConnectionError,
getMissingEnvironmentRepositoryError,
} from '@roomote/types';
import { and, eq, inArray, isNotNull, notInArray } from 'drizzle-orm';
Expand Down Expand Up @@ -364,7 +364,13 @@ async function resolveConfiguredRepositories(config: EnvironmentConfig) {
eq(repositories.isActive, true),
inArray(repositories.fullName, repositoryNames),
),
columns: { id: true, fullName: true, installationId: true },
columns: {
id: true,
fullName: true,
sourceControlProvider: true,
host: true,
installationId: true,
},
})
: [];

Expand Down Expand Up @@ -473,7 +479,7 @@ async function applyDefinition(
await resolveConfiguredRepositories(config);

const repositoryConfigError =
getEnvironmentRepositoryInstallationError(repositoryRows);
getEnvironmentRepositoryConnectionError(repositoryRows);

if (repositoryConfigError) {
return { skip: { source, reason: repositoryConfigError } };
Expand Down
Loading
Loading