Skip to content

Commit b9c9b34

Browse files
authored
Merge pull request #28 from diggerhq/feat/branch-project
Add branch field to project create form
2 parents 6565091 + 49fd44f commit b9c9b34

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/components/CreateProjectForm.tsx

+26-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const createProjectFormSchema = z.object({
2727
name: z.string().min(1, "Project name is required"),
2828
repository: z.number().int().positive("Please select a repository"),
2929
terraformDir: z.string().min(1, "Terraform working directory is required"),
30+
branch: z.string().optional(),
3031
labels: z.array(z.string()),
3132
managedState: z.boolean().default(true),
3233
teamId: z.number().int().positive().nullable(),
@@ -83,6 +84,7 @@ export default function CreateProjectForm({ organizationId, repositories, teams,
8384
repoId: data.repository,
8485
managedState: data.managedState,
8586
terraformWorkingDir: data.terraformDir,
87+
branch: data.branch || '',
8688
labels: data.labels,
8789
is_drift_detection_enabled: data.is_drift_detection_enabled,
8890
drift_crontab: data.drift_crontab || '',
@@ -308,8 +310,8 @@ export default function CreateProjectForm({ organizationId, repositories, teams,
308310
>
309311
<CardHeader>
310312
<div className="flex flex-col">
311-
<CardTitle className="text-lg ">Terraform Configuration</CardTitle>
312-
<CardDescription className="text-sm text-muted-foreground">Specify the working directory for Terraform</CardDescription>
313+
<CardTitle className="text-lg ">Configuration</CardTitle>
314+
<CardDescription className="text-sm text-muted-foreground">Specify branch and working directory for Terraform</CardDescription>
313315
</div>
314316
</CardHeader>
315317
<CardContent>
@@ -322,7 +324,7 @@ export default function CreateProjectForm({ organizationId, repositories, teams,
322324
<div className="relative">
323325
<Input
324326
id="terraformDir"
325-
placeholder="Enter directory path"
327+
placeholder="e.g. ./"
326328
className={`mt-1 ${errors.terraformDir ? 'border-destructive' : ''}`}
327329
{...field}
328330
/>
@@ -335,6 +337,27 @@ export default function CreateProjectForm({ organizationId, repositories, teams,
335337
</div>
336338
)}
337339
/>
340+
<Label htmlFor="branch">Branch</Label>
341+
<Controller
342+
name="branch"
343+
control={control}
344+
render={({ field }) => (
345+
<div className="relative">
346+
<Input
347+
id="branch"
348+
placeholder="if not specified, main branch will be used"
349+
className={`mt-1 ${errors.branch ? 'border-destructive' : ''}`}
350+
{...field}
351+
/>
352+
{errors.branch && (
353+
<div className="flex items-center mt-1 text-destructive">
354+
<AlertCircle className="h-4 w-4 mr-1" />
355+
<span className="text-sm">{errors.branch.message}</span>
356+
</div>
357+
)}
358+
</div>
359+
)}
360+
/>
338361
</div>
339362
</CardContent>
340363
</MotionCard>

src/data/user/projects.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const createProjectAction = async ({
7070
slug,
7171
repoId,
7272
terraformWorkingDir,
73+
branch,
7374
managedState,
7475
labels,
7576
teamId,
@@ -81,6 +82,7 @@ export const createProjectAction = async ({
8182
slug: string;
8283
repoId: number;
8384
terraformWorkingDir: string;
85+
branch: string;
8486
managedState: boolean;
8587
labels: string[];
8688
teamId: number | null;
@@ -98,6 +100,7 @@ export const createProjectAction = async ({
98100
team_id: teamId,
99101
repo_id: repoId,
100102
terraform_working_dir: terraformWorkingDir,
103+
branch: branch,
101104
is_managing_state: managedState,
102105
is_in_main_branch: true,
103106
is_generated: true,
@@ -106,7 +109,6 @@ export const createProjectAction = async ({
106109
labels,
107110
is_drift_detection_enabled,
108111
drift_crontab,
109-
110112
})
111113
.select("*")
112114
.single();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE public.projects
2+
ADD COLUMN IF NOT EXISTS branch TEXT;

0 commit comments

Comments
 (0)