@@ -50,6 +50,7 @@ export const compileGithubConfig = async (
5050 const repoDisplayName = repo . full_name ;
5151 const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
5252 const cloneUrl = new URL ( repo . clone_url ! ) ;
53+ const isPublic = repo . private === false ;
5354
5455 logger . debug ( `Found github repo ${ repoDisplayName } with webUrl: ${ repo . html_url } ` ) ;
5556
@@ -64,6 +65,7 @@ export const compileGithubConfig = async (
6465 imageUrl : repo . owner . avatar_url ,
6566 isFork : repo . fork ,
6667 isArchived : ! ! repo . archived ,
68+ isPublic : isPublic ,
6769 org : {
6870 connect : {
6971 id : orgId ,
@@ -85,7 +87,7 @@ export const compileGithubConfig = async (
8587 'zoekt.github-forks' : ( repo . forks_count ?? 0 ) . toString ( ) ,
8688 'zoekt.archived' : marshalBool ( repo . archived ) ,
8789 'zoekt.fork' : marshalBool ( repo . fork ) ,
88- 'zoekt.public' : marshalBool ( repo . private === false ) ,
90+ 'zoekt.public' : marshalBool ( isPublic ) ,
8991 'zoekt.display-name' : repoDisplayName ,
9092 } ,
9193 branches : config . revisions ?. branches ?? undefined ,
@@ -121,6 +123,8 @@ export const compileGitlabConfig = async (
121123 const projectUrl = `${ hostUrl } /${ project . path_with_namespace } ` ;
122124 const cloneUrl = new URL ( project . http_url_to_repo ) ;
123125 const isFork = project . forked_from_project !== undefined ;
126+ // @todo : we will need to double check whether 'internal' should also be considered public or not.
127+ const isPublic = project . visibility === 'public' ;
124128 const repoDisplayName = project . path_with_namespace ;
125129 const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
126130 // project.avatar_url is not directly accessible with tokens; use the avatar API endpoint if available
@@ -139,6 +143,7 @@ export const compileGitlabConfig = async (
139143 displayName : repoDisplayName ,
140144 imageUrl : avatarUrl ,
141145 isFork : isFork ,
146+ isPublic : isPublic ,
142147 isArchived : ! ! project . archived ,
143148 org : {
144149 connect : {
@@ -159,7 +164,7 @@ export const compileGitlabConfig = async (
159164 'zoekt.gitlab-forks' : ( project . forks_count ?? 0 ) . toString ( ) ,
160165 'zoekt.archived' : marshalBool ( project . archived ) ,
161166 'zoekt.fork' : marshalBool ( isFork ) ,
162- 'zoekt.public' : marshalBool ( project . private === false ) ,
167+ 'zoekt.public' : marshalBool ( isPublic ) ,
163168 'zoekt.display-name' : repoDisplayName ,
164169 } ,
165170 branches : config . revisions ?. branches ?? undefined ,
@@ -197,6 +202,7 @@ export const compileGiteaConfig = async (
197202 cloneUrl . host = configUrl . host
198203 const repoDisplayName = repo . full_name ! ;
199204 const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
205+ const isPublic = repo . internal === false && repo . private === false ;
200206
201207 logger . debug ( `Found gitea repo ${ repoDisplayName } with webUrl: ${ repo . html_url } ` ) ;
202208
@@ -210,6 +216,7 @@ export const compileGiteaConfig = async (
210216 displayName : repoDisplayName ,
211217 imageUrl : repo . owner ?. avatar_url ,
212218 isFork : repo . fork ! ,
219+ isPublic : isPublic ,
213220 isArchived : ! ! repo . archived ,
214221 org : {
215222 connect : {
@@ -228,7 +235,7 @@ export const compileGiteaConfig = async (
228235 'zoekt.name' : repoName ,
229236 'zoekt.archived' : marshalBool ( repo . archived ) ,
230237 'zoekt.fork' : marshalBool ( repo . fork ! ) ,
231- 'zoekt.public' : marshalBool ( repo . internal === false && repo . private === false ) ,
238+ 'zoekt.public' : marshalBool ( isPublic ) ,
232239 'zoekt.display-name' : repoDisplayName ,
233240 } ,
234241 branches : config . revisions ?. branches ?? undefined ,
@@ -411,6 +418,7 @@ export const compileBitbucketConfig = async (
411418 name : repoName ,
412419 displayName : displayName ,
413420 isFork : isFork ,
421+ isPublic : isPublic ,
414422 isArchived : isArchived ,
415423 org : {
416424 connect : {
@@ -546,6 +554,70 @@ export const compileGenericGitHostConfig_file = async (
546554 }
547555}
548556
557+
558+ export const compileGenericGitHostConfig_url = async (
559+ config : GenericGitHostConnectionConfig ,
560+ orgId : number ,
561+ connectionId : number ,
562+ ) => {
563+ const remoteUrl = new URL ( config . url ) ;
564+ assert ( remoteUrl . protocol === 'http:' || remoteUrl . protocol === 'https:' , 'config.url must be a http:// or https:// URL' ) ;
565+
566+ const notFound : {
567+ users : string [ ] ,
568+ orgs : string [ ] ,
569+ repos : string [ ] ,
570+ } = {
571+ users : [ ] ,
572+ orgs : [ ] ,
573+ repos : [ ] ,
574+ } ;
575+
576+ // Validate that we are dealing with a valid git repo.
577+ const isGitRepo = await isUrlAValidGitRepo ( remoteUrl . toString ( ) ) ;
578+ if ( ! isGitRepo ) {
579+ notFound . repos . push ( remoteUrl . toString ( ) ) ;
580+ return {
581+ repoData : [ ] ,
582+ notFound,
583+ }
584+ }
585+
586+ // @note : matches the naming here:
587+ // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293
588+ const repoName = path . join ( remoteUrl . host , remoteUrl . pathname . replace ( / \. g i t $ / , '' ) ) ;
589+
590+ const repo : RepoData = {
591+ external_codeHostType : 'generic-git-host' ,
592+ external_codeHostUrl : remoteUrl . origin ,
593+ external_id : remoteUrl . toString ( ) ,
594+ cloneUrl : remoteUrl . toString ( ) ,
595+ name : repoName ,
596+ displayName : repoName ,
597+ isFork : false ,
598+ isArchived : false ,
599+ org : {
600+ connect : {
601+ id : orgId ,
602+ } ,
603+ } ,
604+ connections : {
605+ create : {
606+ connectionId : connectionId ,
607+ }
608+ } ,
609+ metadata : {
610+ branches : config . revisions ?. branches ?? undefined ,
611+ tags : config . revisions ?. tags ?? undefined ,
612+ }
613+ } ;
614+
615+ return {
616+ repoData : [ repo ] ,
617+ notFound,
618+ }
619+ }
620+
549621export const compileAzureDevOpsConfig = async (
550622 config : AzureDevOpsConnectionConfig ,
551623 connectionId : number ,
@@ -569,6 +641,7 @@ export const compileAzureDevOpsConfig = async (
569641
570642 const repoDisplayName = `${ repo . project . name } /${ repo . name } ` ;
571643 const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
644+ const isPublic = repo . project . visibility === ProjectVisibility . Public ;
572645
573646 if ( ! repo . remoteUrl ) {
574647 throw new Error ( `No remoteUrl found for repository ${ repoDisplayName } ` ) ;
@@ -593,6 +666,7 @@ export const compileAzureDevOpsConfig = async (
593666 imageUrl : null ,
594667 isFork : ! ! repo . isFork ,
595668 isArchived : false ,
669+ isPublic : isPublic ,
596670 org : {
597671 connect : {
598672 id : orgId ,
@@ -610,7 +684,7 @@ export const compileAzureDevOpsConfig = async (
610684 'zoekt.name' : repoName ,
611685 'zoekt.archived' : marshalBool ( false ) ,
612686 'zoekt.fork' : marshalBool ( ! ! repo . isFork ) ,
613- 'zoekt.public' : marshalBool ( repo . project . visibility === ProjectVisibility . Public ) ,
687+ 'zoekt.public' : marshalBool ( isPublic ) ,
614688 'zoekt.display-name' : repoDisplayName ,
615689 } ,
616690 branches : config . revisions ?. branches ?? undefined ,
@@ -626,66 +700,3 @@ export const compileAzureDevOpsConfig = async (
626700 notFound,
627701 } ;
628702}
629-
630- export const compileGenericGitHostConfig_url = async (
631- config : GenericGitHostConnectionConfig ,
632- orgId : number ,
633- connectionId : number ,
634- ) => {
635- const remoteUrl = new URL ( config . url ) ;
636- assert ( remoteUrl . protocol === 'http:' || remoteUrl . protocol === 'https:' , 'config.url must be a http:// or https:// URL' ) ;
637-
638- const notFound : {
639- users : string [ ] ,
640- orgs : string [ ] ,
641- repos : string [ ] ,
642- } = {
643- users : [ ] ,
644- orgs : [ ] ,
645- repos : [ ] ,
646- } ;
647-
648- // Validate that we are dealing with a valid git repo.
649- const isGitRepo = await isUrlAValidGitRepo ( remoteUrl . toString ( ) ) ;
650- if ( ! isGitRepo ) {
651- notFound . repos . push ( remoteUrl . toString ( ) ) ;
652- return {
653- repoData : [ ] ,
654- notFound,
655- }
656- }
657-
658- // @note : matches the naming here:
659- // https://github.com/sourcebot-dev/zoekt/blob/main/gitindex/index.go#L293
660- const repoName = path . join ( remoteUrl . host , remoteUrl . pathname . replace ( / \. g i t $ / , '' ) ) ;
661-
662- const repo : RepoData = {
663- external_codeHostType : 'generic-git-host' ,
664- external_codeHostUrl : remoteUrl . origin ,
665- external_id : remoteUrl . toString ( ) ,
666- cloneUrl : remoteUrl . toString ( ) ,
667- name : repoName ,
668- displayName : repoName ,
669- isFork : false ,
670- isArchived : false ,
671- org : {
672- connect : {
673- id : orgId ,
674- } ,
675- } ,
676- connections : {
677- create : {
678- connectionId : connectionId ,
679- }
680- } ,
681- metadata : {
682- branches : config . revisions ?. branches ?? undefined ,
683- tags : config . revisions ?. tags ?? undefined ,
684- }
685- } ;
686-
687- return {
688- repoData : [ repo ] ,
689- notFound,
690- }
691- }
0 commit comments