5567f49846
* Fix settigns page delete project width issue * Apply a couple of touch-ups to the project settings page * Add UI flow to connect gh repos * Enabling adding another gh account in the ui * Enable connecting a repo to a project * Enable updating git settings * Enable disconnecting gh repos from a project * Remove prisma migration drifts * Hide git settings when github app is disabled * Fix migration order * Avoid using `location` to avoid SSR issues * Make branch tracking optional * Disable save buttons when there are no field changes * Disable delete project button unless the input matches the project slug * Show connected repo connectedAt date * Check that tracking branch exists when updating git settings * Show tracking branch hint in the deployments page * Fix positioning issue of the pagination pane in the deployments page * Use mono font for branch names * Add link to git settings * Show tracking branch hint for the preview env too * Add a confirmation prompt on repo disconnect * Add link to configure repo access in gh * Add rel prop to github links * Automatically open repo connection modal after app installation * Apply some fixes suggested by mr rabbit * Fix flash cookie issue * Extract project settings actions into a service * Extract project settings loader into a presenter service * Introduce neverthrow for error handling * Try out neverthrow for error handling in the project setting flows * Move env gh branch resolution to the presenter service
36 lines
949 B
TypeScript
36 lines
949 B
TypeScript
import { z } from "zod";
|
|
|
|
export const BranchTrackingConfigSchema = z.object({
|
|
prod: z.object({
|
|
branch: z.string().optional(),
|
|
}),
|
|
staging: z.object({
|
|
branch: z.string().optional(),
|
|
}),
|
|
});
|
|
|
|
export type BranchTrackingConfig = z.infer<typeof BranchTrackingConfigSchema>;
|
|
|
|
export function getTrackedBranchForEnvironment(
|
|
branchTracking: BranchTrackingConfig | undefined,
|
|
previewDeploymentsEnabled: boolean,
|
|
environment: {
|
|
type: "PRODUCTION" | "STAGING" | "DEVELOPMENT" | "PREVIEW";
|
|
branchName?: string;
|
|
}
|
|
): string | undefined {
|
|
switch (environment.type) {
|
|
case "PRODUCTION":
|
|
return branchTracking?.prod?.branch;
|
|
case "STAGING":
|
|
return branchTracking?.staging?.branch;
|
|
case "PREVIEW":
|
|
return previewDeploymentsEnabled ? environment.branchName : undefined;
|
|
case "DEVELOPMENT":
|
|
return undefined;
|
|
default:
|
|
environment.type satisfies never;
|
|
return undefined;
|
|
}
|
|
}
|