3
3
type RepositoryVisibility ,
4
4
type RepoStatus ,
5
5
} from "@/types/Repository" ;
6
+ import { membershipRoleEnum } from "@/types/organizations" ;
6
7
import { Octokit } from "@octokit/rest" ;
7
8
import type { Config } from "@/types/config" ;
8
9
import type { Organization , Repository } from "./db/schema" ;
@@ -22,13 +23,26 @@ export const getOrganizationConfig = async ({
22
23
userId : string ;
23
24
} ) : Promise < Organization | null > => {
24
25
try {
25
- const [ orgConfig ] = await db
26
+ const result = await db
26
27
. select ( )
27
28
. from ( organizations )
28
29
. where ( and ( eq ( organizations . name , orgName ) , eq ( organizations . userId , userId ) ) )
29
30
. limit ( 1 ) ;
30
31
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 ;
32
46
} catch ( error ) {
33
47
console . error ( `Error fetching organization config for ${ orgName } :` , error ) ;
34
48
return null ;
@@ -113,7 +127,7 @@ export const getGiteaRepoOwner = ({
113
127
114
128
// Get the mirror strategy - use preserveOrgStructure for backward compatibility
115
129
const mirrorStrategy = config . giteaConfig . mirrorStrategy ||
116
- ( config . githubConfig . preserveOrgStructure ? "preserve" : "flat-user" ) ;
130
+ ( config . giteaConfig . preserveOrgStructure ? "preserve" : "flat-user" ) ;
117
131
118
132
switch ( mirrorStrategy ) {
119
133
case "preserve" :
@@ -870,8 +884,8 @@ export async function mirrorGitHubOrgToGitea({
870
884
} ) ;
871
885
872
886
// 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" ) ;
875
889
876
890
let giteaOrgId : number ;
877
891
let targetOrgName : string ;
0 commit comments