Skip to content

Commit 81ca16c

Browse files
committed
Show tracking branch hint in the deployments page
1 parent e6f8f65 commit 81ca16c

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Prisma,
2+
type Prisma,
33
type WorkerDeploymentStatus,
44
type WorkerInstanceGroupType,
55
} from "@trigger.dev/database";
@@ -56,6 +56,17 @@ export class DeploymentListPresenter {
5656
},
5757
},
5858
},
59+
connectedGithubRepository: {
60+
select: {
61+
branchTracking: true,
62+
repository: {
63+
select: {
64+
htmlUrl: true,
65+
fullName: true,
66+
},
67+
},
68+
},
69+
},
5970
},
6071
where: {
6172
slug: projectSlug,
@@ -143,6 +154,7 @@ LIMIT ${pageSize} OFFSET ${pageSize * (page - 1)};`;
143154
return {
144155
currentPage: page,
145156
totalPages: Math.ceil(totalCount / pageSize),
157+
connectedGithubRepository: project.connectedGithubRepository ?? undefined,
146158
deployments: deployments.map((deployment, index) => {
147159
const label = labeledDeployments.find(
148160
(labeledDeployment) => labeledDeployment.deploymentId === deployment.id

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { ArrowUturnLeftIcon, BookOpenIcon } from "@heroicons/react/20/solid";
22
import { type MetaFunction, Outlet, useLocation, useNavigate, useParams } from "@remix-run/react";
33
import { type LoaderFunctionArgs } from "@remix-run/server-runtime";
4+
import { GitBranchIcon } from "lucide-react";
45
import { useEffect } from "react";
56
import { typedjson, useTypedLoaderData } from "remix-typedjson";
67
import { z } from "zod";
78
import { PromoteIcon } from "~/assets/icons/PromoteIcon";
89
import { DeploymentsNone, DeploymentsNoneDev } from "~/components/BlankStatePanels";
10+
import { OctoKitty } from "~/components/GitHubLoginButton";
911
import { GitMetadata } from "~/components/GitMetadata";
1012
import { RuntimeIcon } from "~/components/RuntimeIcon";
1113
import { UserAvatar } from "~/components/UserProfilePhoto";
@@ -52,6 +54,7 @@ import { requireUserId } from "~/services/session.server";
5254
import { titleCase } from "~/utils";
5355
import { EnvironmentParamSchema, docsPath, v3DeploymentPath } from "~/utils/pathBuilder";
5456
import { createSearchParams } from "~/utils/searchParams";
57+
import { BranchTrackingConfigSchema, getTrackedBranchForEnvironment } from "~/v3/github";
5558
import { compareDeploymentVersions } from "~/v3/utils/deploymentVersions";
5659

5760
export const meta: MetaFunction = () => {
@@ -122,8 +125,15 @@ export default function Page() {
122125
const organization = useOrganization();
123126
const project = useProject();
124127
const environment = useEnvironment();
125-
const { deployments, currentPage, totalPages, selectedDeployment } =
128+
const { deployments, currentPage, totalPages, selectedDeployment, connectedGithubRepository } =
126129
useTypedLoaderData<typeof loader>();
130+
const branchTrackingOrError =
131+
connectedGithubRepository &&
132+
BranchTrackingConfigSchema.safeParse(connectedGithubRepository.branchTracking);
133+
const environmentGitHubBranch =
134+
branchTrackingOrError && branchTrackingOrError.success
135+
? getTrackedBranchForEnvironment(branchTrackingOrError.data, environment.type)
136+
: undefined;
127137
const hasDeployments = totalPages > 0;
128138

129139
const { deploymentParam } = useParams();
@@ -286,11 +296,27 @@ export default function Page() {
286296
)}
287297
</TableBody>
288298
</Table>
289-
{totalPages > 1 && (
290-
<div className="-mt-px flex justify-end border-t border-grid-dimmed py-2 pr-2">
291-
<PaginationControls currentPage={currentPage} totalPages={totalPages} />
292-
</div>
293-
)}
299+
<div className="-mt-px flex justify-between gap-2 border-t border-grid-dimmed px-2 py-2">
300+
{connectedGithubRepository && environmentGitHubBranch && (
301+
<div className="flex flex-nowrap items-center gap-2 whitespace-nowrap text-sm">
302+
<OctoKitty className="size-4" />
303+
Automatically triggered by pushes to{" "}
304+
<div className="flex max-w-32 items-center gap-1 truncate rounded bg-grid-dimmed px-1 font-mono">
305+
<GitBranchIcon className="size-3 shrink-0" />
306+
<span className="max-w-28 truncate">{environmentGitHubBranch}</span>
307+
</div>{" "}
308+
in
309+
<a
310+
href={connectedGithubRepository.repository.htmlUrl}
311+
target="_blank"
312+
className="max-w-52 truncate text-sm text-text-dimmed underline transition-colors hover:text-text-bright"
313+
>
314+
{connectedGithubRepository.repository.fullName}
315+
</a>
316+
</div>
317+
)}
318+
<PaginationControls currentPage={currentPage} totalPages={20} />
319+
</div>
294320
</div>
295321
) : environment.type === "DEVELOPMENT" ? (
296322
<MainCenteredContainer className="max-w-md">

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export const action: ActionFunction = async ({ request, params }) => {
357357

358358
const [error, branchValidationsOrFail] = await tryCatch(
359359
Promise.all([
360-
productionBranch && existingBranchTracking.data?.production?.branch !== productionBranch
360+
productionBranch && existingBranchTracking.data?.prod?.branch !== productionBranch
361361
? checkGitHubBranchExists(installationId, owner, repo, productionBranch)
362362
: Promise.resolve(true),
363363
stagingBranch && existingBranchTracking.data?.staging?.branch !== stagingBranch
@@ -392,7 +392,7 @@ export const action: ActionFunction = async ({ request, params }) => {
392392
},
393393
data: {
394394
branchTracking: {
395-
production: productionBranch ? { branch: productionBranch } : {},
395+
prod: productionBranch ? { branch: productionBranch } : {},
396396
staging: stagingBranch ? { branch: stagingBranch } : {},
397397
} satisfies BranchTrackingConfig,
398398
previewDeploymentsEnabled: previewDeploymentsEnabled,
@@ -441,7 +441,7 @@ export const action: ActionFunction = async ({ request, params }) => {
441441
projectId: project.id,
442442
repositoryId: repositoryId,
443443
branchTracking: {
444-
production: { branch: repository.defaultBranch },
444+
prod: { branch: repository.defaultBranch },
445445
staging: { branch: repository.defaultBranch },
446446
} satisfies BranchTrackingConfig,
447447
previewDeploymentsEnabled: true,
@@ -908,15 +908,15 @@ function ConnectedGitHubRepoForm({
908908

909909
const [hasGitSettingsChanges, setHasGitSettingsChanges] = useState(false);
910910
const [gitSettingsValues, setGitSettingsValues] = useState({
911-
productionBranch: connectedGitHubRepo.branchTracking?.production?.branch || "",
911+
productionBranch: connectedGitHubRepo.branchTracking?.prod?.branch || "",
912912
stagingBranch: connectedGitHubRepo.branchTracking?.staging?.branch || "",
913913
previewDeploymentsEnabled: connectedGitHubRepo.previewDeploymentsEnabled,
914914
});
915915

916916
useEffect(() => {
917917
const hasChanges =
918918
gitSettingsValues.productionBranch !==
919-
(connectedGitHubRepo.branchTracking?.production?.branch || "") ||
919+
(connectedGitHubRepo.branchTracking?.prod?.branch || "") ||
920920
gitSettingsValues.stagingBranch !==
921921
(connectedGitHubRepo.branchTracking?.staging?.branch || "") ||
922922
gitSettingsValues.previewDeploymentsEnabled !== connectedGitHubRepo.previewDeploymentsEnabled;
@@ -986,7 +986,7 @@ function ConnectedGitHubRepoForm({
986986
</div>
987987
<Input
988988
{...conform.input(fields.productionBranch, { type: "text" })}
989-
defaultValue={connectedGitHubRepo.branchTracking?.production?.branch}
989+
defaultValue={connectedGitHubRepo.branchTracking?.prod?.branch}
990990
placeholder="none"
991991
variant="tertiary"
992992
icon={GitBranchIcon}

apps/webapp/app/v3/github.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22

33
export const BranchTrackingConfigSchema = z.object({
4-
production: z.object({
4+
prod: z.object({
55
branch: z.string().optional(),
66
}),
77
staging: z.object({
@@ -10,3 +10,18 @@ export const BranchTrackingConfigSchema = z.object({
1010
});
1111

1212
export type BranchTrackingConfig = z.infer<typeof BranchTrackingConfigSchema>;
13+
14+
export function getTrackedBranchForEnvironment(
15+
branchTracking: BranchTrackingConfig | undefined,
16+
environmentType: "PRODUCTION" | "STAGING" | "DEVELOPMENT" | "PREVIEW"
17+
): string | undefined {
18+
if (!branchTracking) return undefined;
19+
switch (environmentType) {
20+
case "PRODUCTION":
21+
return branchTracking.prod?.branch;
22+
case "STAGING":
23+
return branchTracking.staging?.branch;
24+
default:
25+
return undefined;
26+
}
27+
}

internal-packages/database/prisma/schema.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ model Project {
393393
taskRunCheckpoints TaskRunCheckpoint[]
394394
executionSnapshots TaskRunExecutionSnapshot[]
395395
waitpointTags WaitpointTag[]
396-
ConnectedGithubRepository ConnectedGithubRepository?
396+
connectedGithubRepository ConnectedGithubRepository?
397397
}
398398

399399
enum ProjectVersion {
@@ -2300,9 +2300,9 @@ model ConnectedGithubRepository {
23002300
repository GithubRepository @relation(fields: [repositoryId], references: [id], onDelete: Cascade, onUpdate: Cascade)
23012301
repositoryId String
23022302
2303-
// Branch configuration by environment, stored as JSON
2303+
// Branch configuration by environment slug, stored as JSON
23042304
// Example: {
2305-
// "production": { "branch": "main" },
2305+
// "prod": { "branch": "main" },
23062306
// "staging": { "branch": "staging" },
23072307
// }
23082308
// We could alternatively store tracking branch configurations in a separate table and reference the runtime environments properly.

0 commit comments

Comments
 (0)