Skip to content

Commit 269cf9c

Browse files
committed
Move env gh branch resolution to the presenter service
1 parent 190830b commit 269cf9c

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

apps/webapp/app/presenters/v3/DeploymentListPresenter.server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type Project } from "~/models/project.server";
99
import { findEnvironmentBySlug } from "~/models/runtimeEnvironment.server";
1010
import { type User } from "~/models/user.server";
1111
import { processGitMetadata } from "./BranchesPresenter.server";
12+
import { BranchTrackingConfigSchema, getTrackedBranchForEnvironment } from "~/v3/github";
1213

1314
const pageSize = 20;
1415

@@ -152,10 +153,28 @@ ORDER BY
152153
string_to_array(wd."version", '.')::int[] DESC
153154
LIMIT ${pageSize} OFFSET ${pageSize * (page - 1)};`;
154155

156+
const { connectedGithubRepository } = project;
157+
158+
const branchTrackingOrError =
159+
connectedGithubRepository &&
160+
BranchTrackingConfigSchema.safeParse(connectedGithubRepository.branchTracking);
161+
const environmentGitHubBranch =
162+
branchTrackingOrError && branchTrackingOrError.success
163+
? getTrackedBranchForEnvironment(
164+
branchTrackingOrError.data,
165+
connectedGithubRepository.previewDeploymentsEnabled,
166+
{
167+
type: environment.type,
168+
branchName: environment.branchName ?? undefined,
169+
}
170+
)
171+
: undefined;
172+
155173
return {
156174
currentPage: page,
157175
totalPages: Math.ceil(totalCount / pageSize),
158176
connectedGithubRepository: project.connectedGithubRepository ?? undefined,
177+
environmentGitHubBranch,
159178
deployments: deployments.map((deployment, index) => {
160179
const label = labeledDeployments.find(
161180
(labeledDeployment) => labeledDeployment.deploymentId === deployment.id

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.deployments/route.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
v3ProjectSettingsPath,
6161
} from "~/utils/pathBuilder";
6262
import { createSearchParams } from "~/utils/searchParams";
63-
import { BranchTrackingConfigSchema, getTrackedBranchForEnvironment } from "~/v3/github";
6463
import { compareDeploymentVersions } from "~/v3/utils/deploymentVersions";
6564

6665
export const meta: MetaFunction = () => {
@@ -131,22 +130,14 @@ export default function Page() {
131130
const organization = useOrganization();
132131
const project = useProject();
133132
const environment = useEnvironment();
134-
const { deployments, currentPage, totalPages, selectedDeployment, connectedGithubRepository } =
135-
useTypedLoaderData<typeof loader>();
136-
const branchTrackingOrError =
137-
connectedGithubRepository &&
138-
BranchTrackingConfigSchema.safeParse(connectedGithubRepository.branchTracking);
139-
const environmentGitHubBranch =
140-
branchTrackingOrError && branchTrackingOrError.success
141-
? getTrackedBranchForEnvironment(
142-
branchTrackingOrError.data,
143-
connectedGithubRepository.previewDeploymentsEnabled,
144-
{
145-
type: environment.type,
146-
branchName: environment.branchName ?? undefined,
147-
}
148-
)
149-
: undefined;
133+
const {
134+
deployments,
135+
currentPage,
136+
totalPages,
137+
selectedDeployment,
138+
connectedGithubRepository,
139+
environmentGitHubBranch,
140+
} = useTypedLoaderData<typeof loader>();
150141
const hasDeployments = totalPages > 0;
151142

152143
const { deploymentParam } = useParams();

0 commit comments

Comments
 (0)