Skip to content

Commit d0e8e75

Browse files
committed
Type fix
1 parent c95a501 commit d0e8e75

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/components/organizations/Organization.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,9 @@ export function Organization() {
653653
loadingOrgIds={loadingOrgIds}
654654
onMirror={handleMirrorOrg}
655655
onAddOrganization={() => setIsDialogOpen(true)}
656-
onRefresh={() => fetchOrganizations(false)}
656+
onRefresh={async () => {
657+
await fetchOrganizations(false);
658+
}}
657659
/>
658660

659661
<AddOrganizationDialog

src/lib/gitea.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type RepositoryVisibility,
44
type RepoStatus,
55
} from "@/types/Repository";
6+
import { membershipRoleEnum } from "@/types/organizations";
67
import { Octokit } from "@octokit/rest";
78
import type { Config } from "@/types/config";
89
import type { Organization, Repository } from "./db/schema";
@@ -22,13 +23,26 @@ export const getOrganizationConfig = async ({
2223
userId: string;
2324
}): Promise<Organization | null> => {
2425
try {
25-
const [orgConfig] = await db
26+
const result = await db
2627
.select()
2728
.from(organizations)
2829
.where(and(eq(organizations.name, orgName), eq(organizations.userId, userId)))
2930
.limit(1);
3031

31-
return orgConfig || null;
32+
if (!result[0]) {
33+
return null;
34+
}
35+
36+
// Validate and cast the membershipRole to ensure type safety
37+
const rawOrg = result[0];
38+
const membershipRole = membershipRoleEnum.parse(rawOrg.membershipRole);
39+
const status = repoStatusEnum.parse(rawOrg.status);
40+
41+
return {
42+
...rawOrg,
43+
membershipRole,
44+
status,
45+
} as Organization;
3246
} catch (error) {
3347
console.error(`Error fetching organization config for ${orgName}:`, error);
3448
return null;
@@ -113,7 +127,7 @@ export const getGiteaRepoOwner = ({
113127

114128
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
115129
const mirrorStrategy = config.giteaConfig.mirrorStrategy ||
116-
(config.githubConfig.preserveOrgStructure ? "preserve" : "flat-user");
130+
(config.giteaConfig.preserveOrgStructure ? "preserve" : "flat-user");
117131

118132
switch (mirrorStrategy) {
119133
case "preserve":
@@ -870,8 +884,8 @@ export async function mirrorGitHubOrgToGitea({
870884
});
871885

872886
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
873-
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
874-
(config.githubConfig?.preserveOrgStructure ? "preserve" : "flat-user");
887+
const mirrorStrategy = config.giteaConfig?.mirrorStrategy ||
888+
(config.giteaConfig?.preserveOrgStructure ? "preserve" : "flat-user");
875889

876890
let giteaOrgId: number;
877891
let targetOrgName: string;

0 commit comments

Comments
 (0)