fix: handle repository id null case consistently

This commit is contained in:
Jason Parks 2025-03-23 14:04:30 -06:00
parent 048c8ffc11
commit d5137d5d3a

View File

@ -67,8 +67,8 @@ const GiteaProviderSchema = z.object({
.object({ .object({
repo: z.string().min(1, "Repo is required"), repo: z.string().min(1, "Repo is required"),
owner: z.string().min(1, "Owner is required"), owner: z.string().min(1, "Owner is required"),
giteaPathNamespace: z.string(), giteaPathNamespace: z.string().min(1),
id: z.number().nullable(), id: z.number().nullable().optional(),
}) })
.required(), .required(),
branch: z.string().min(1, "Branch is required"), branch: z.string().min(1, "Branch is required"),
@ -129,7 +129,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
{ {
owner: repository?.owner, owner: repository?.owner,
repositoryName: repository?.repo, repositoryName: repository?.repo,
id: repository?.id || 0, id: repository?.id ?? 0, // Use nullish coalescing to provide 0 as a fallback
giteaId: giteaId, giteaId: giteaId,
}, },
{ {
@ -145,7 +145,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
repo: data.giteaRepository || "", repo: data.giteaRepository || "",
owner: data.giteaOwner || "", owner: data.giteaOwner || "",
giteaPathNamespace: data.giteaPathNamespace || "", giteaPathNamespace: data.giteaPathNamespace || "",
id: data.giteaProjectId, id: data.giteaProjectId || null, // Handle null case explicitly
}, },
buildPath: data.giteaBuildPath || "/", buildPath: data.giteaBuildPath || "/",
giteaId: data.giteaId || "", giteaId: data.giteaId || "",
@ -162,7 +162,7 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
giteaBuildPath: data.buildPath, giteaBuildPath: data.buildPath,
giteaId: data.giteaId, giteaId: data.giteaId,
applicationId, applicationId,
giteaProjectId: data.repository.id, giteaProjectId: data.repository.id || null, // Handle null case explicitly
giteaPathNamespace: data.repository.giteaPathNamespace, giteaPathNamespace: data.repository.giteaPathNamespace,
watchPaths: data.watchPaths, watchPaths: data.watchPaths,
}) })
@ -502,4 +502,4 @@ export const SaveGiteaProvider = ({ applicationId }: Props) => {
</Form> </Form>
</div> </div>
); );
}; };