11import { GithubConnectionConfig } from '@sourcebot/schemas/v3/github.type' ;
2- import { getGitHubReposFromConfig } from "./github.js" ;
2+ import { getGitHubReposFromConfig , OctokitRepository } from "./github.js" ;
33import { getGitLabReposFromConfig } from "./gitlab.js" ;
44import { getGiteaReposFromConfig } from "./gitea.js" ;
55import { getGerritReposFromConfig } from "./gerrit.js" ;
@@ -62,60 +62,23 @@ export const compileGithubConfig = async (
6262 const warnings = gitHubReposResult . warnings ;
6363
6464 const hostUrl = config . url ?? 'https://github.com' ;
65- const repoNameRoot = new URL ( hostUrl )
66- . toString ( )
67- . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
6865
6966 const repos = gitHubRepos . map ( ( repo ) => {
70- const repoDisplayName = repo . full_name ;
71- const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
72- const cloneUrl = new URL ( repo . clone_url ! ) ;
73- const isPublic = repo . private === false ;
74-
75- logger . debug ( `Found github repo ${ repoDisplayName } with webUrl: ${ repo . html_url } ` ) ;
67+ const record = createGitHubRepoRecord ( {
68+ repo ,
69+ hostUrl ,
70+ branches : config . revisions ?. branches ?? undefined ,
71+ tags : config . revisions ?. tags ?? undefined ,
72+ } )
7673
77- const record : RepoData = {
78- external_id : repo . id . toString ( ) ,
79- external_codeHostType : 'github' ,
80- external_codeHostUrl : hostUrl ,
81- cloneUrl : cloneUrl . toString ( ) ,
82- webUrl : repo . html_url ,
83- name : repoName ,
84- displayName : repoDisplayName ,
85- imageUrl : repo . owner . avatar_url ,
86- isFork : repo . fork ,
87- isArchived : ! ! repo . archived ,
88- isPublic : isPublic ,
89- org : {
90- connect : {
91- id : SINGLE_TENANT_ORG_ID ,
92- } ,
93- } ,
74+ return {
75+ ...record ,
9476 connections : {
9577 create : {
9678 connectionId : connectionId ,
9779 }
9880 } ,
99- metadata : {
100- gitConfig : {
101- 'zoekt.web-url-type' : 'github' ,
102- 'zoekt.web-url' : repo . html_url ,
103- 'zoekt.name' : repoName ,
104- 'zoekt.github-stars' : ( repo . stargazers_count ?? 0 ) . toString ( ) ,
105- 'zoekt.github-watchers' : ( repo . watchers_count ?? 0 ) . toString ( ) ,
106- 'zoekt.github-subscribers' : ( repo . subscribers_count ?? 0 ) . toString ( ) ,
107- 'zoekt.github-forks' : ( repo . forks_count ?? 0 ) . toString ( ) ,
108- 'zoekt.archived' : marshalBool ( repo . archived ) ,
109- 'zoekt.fork' : marshalBool ( repo . fork ) ,
110- 'zoekt.public' : marshalBool ( isPublic ) ,
111- 'zoekt.display-name' : repoDisplayName ,
112- } ,
113- branches : config . revisions ?. branches ?? undefined ,
114- tags : config . revisions ?. tags ?? undefined ,
115- } satisfies RepoMetadata ,
11681 } ;
117-
118- return record ;
11982 } )
12083
12184 return {
@@ -124,6 +87,70 @@ export const compileGithubConfig = async (
12487 } ;
12588}
12689
90+ export const createGitHubRepoRecord = ( {
91+ repo,
92+ hostUrl,
93+ branches,
94+ tags,
95+ isAutoCleanupDisabled,
96+ } : {
97+ repo : OctokitRepository ,
98+ hostUrl : string ,
99+ branches ?: string [ ] ,
100+ tags ?: string [ ] ,
101+ isAutoCleanupDisabled ?: boolean ,
102+ } ) => {
103+ const repoNameRoot = new URL ( hostUrl )
104+ . toString ( )
105+ . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
106+
107+ const repoDisplayName = repo . full_name ;
108+ const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
109+ const cloneUrl = new URL ( repo . clone_url ! ) ;
110+ const isPublic = repo . private === false ;
111+
112+ logger . debug ( `Found github repo ${ repoDisplayName } with webUrl: ${ repo . html_url } ` ) ;
113+
114+ const record : Prisma . RepoCreateInput = {
115+ external_id : repo . id . toString ( ) ,
116+ external_codeHostType : 'github' ,
117+ external_codeHostUrl : hostUrl ,
118+ cloneUrl : cloneUrl . toString ( ) ,
119+ webUrl : repo . html_url ,
120+ name : repoName ,
121+ displayName : repoDisplayName ,
122+ imageUrl : repo . owner . avatar_url ,
123+ isFork : repo . fork ,
124+ isArchived : ! ! repo . archived ,
125+ isPublic : isPublic ,
126+ isAutoCleanupDisabled,
127+ org : {
128+ connect : {
129+ id : SINGLE_TENANT_ORG_ID ,
130+ } ,
131+ } ,
132+ metadata : {
133+ gitConfig : {
134+ 'zoekt.web-url-type' : 'github' ,
135+ 'zoekt.web-url' : repo . html_url ,
136+ 'zoekt.name' : repoName ,
137+ 'zoekt.github-stars' : ( repo . stargazers_count ?? 0 ) . toString ( ) ,
138+ 'zoekt.github-watchers' : ( repo . watchers_count ?? 0 ) . toString ( ) ,
139+ 'zoekt.github-subscribers' : ( repo . subscribers_count ?? 0 ) . toString ( ) ,
140+ 'zoekt.github-forks' : ( repo . forks_count ?? 0 ) . toString ( ) ,
141+ 'zoekt.archived' : marshalBool ( repo . archived ) ,
142+ 'zoekt.fork' : marshalBool ( repo . fork ) ,
143+ 'zoekt.public' : marshalBool ( isPublic ) ,
144+ 'zoekt.display-name' : repoDisplayName ,
145+ } ,
146+ branches,
147+ tags,
148+ } satisfies RepoMetadata ,
149+ } ;
150+
151+ return record ;
152+ }
153+
127154export const compileGitlabConfig = async (
128155 config : GitlabConnectionConfig ,
129156 connectionId : number ) : Promise < CompileResult > => {
0 commit comments