@@ -8,6 +8,7 @@ import { WithRequired } from "./types.js"
8
8
import { marshalBool } from "./utils.js" ;
9
9
import { GerritConnectionConfig , GiteaConnectionConfig , GitlabConnectionConfig } from '@sourcebot/schemas/v3/connection.type' ;
10
10
import { RepoMetadata } from './types.js' ;
11
+ import path from 'path' ;
11
12
12
13
export type RepoData = WithRequired < Prisma . RepoCreateInput , 'connections' > ;
13
14
@@ -29,10 +30,13 @@ export const compileGithubConfig = async (
29
30
const notFound = gitHubReposResult . notFound ;
30
31
31
32
const hostUrl = config . url ?? 'https://github.com' ;
32
- const hostname = new URL ( hostUrl ) . hostname ;
33
+ const repoNameRoot = new URL ( hostUrl )
34
+ . toString ( )
35
+ . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
33
36
34
37
const repos = gitHubRepos . map ( ( repo ) => {
35
- const repoName = `${ hostname } /${ repo . full_name } ` ;
38
+ const repoDisplayName = repo . full_name ;
39
+ const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
36
40
const cloneUrl = new URL ( repo . clone_url ! ) ;
37
41
38
42
const record : RepoData = {
@@ -42,6 +46,7 @@ export const compileGithubConfig = async (
42
46
cloneUrl : cloneUrl . toString ( ) ,
43
47
webUrl : repo . html_url ,
44
48
name : repoName ,
49
+ displayName : repoDisplayName ,
45
50
imageUrl : repo . owner . avatar_url ,
46
51
isFork : repo . fork ,
47
52
isArchived : ! ! repo . archived ,
@@ -67,6 +72,7 @@ export const compileGithubConfig = async (
67
72
'zoekt.archived' : marshalBool ( repo . archived ) ,
68
73
'zoekt.fork' : marshalBool ( repo . fork ) ,
69
74
'zoekt.public' : marshalBool ( repo . private === false ) ,
75
+ 'zoekt.display-name' : repoDisplayName ,
70
76
} ,
71
77
branches : config . revisions ?. branches ?? undefined ,
72
78
tags : config . revisions ?. tags ?? undefined ,
@@ -93,13 +99,16 @@ export const compileGitlabConfig = async (
93
99
const notFound = gitlabReposResult . notFound ;
94
100
95
101
const hostUrl = config . url ?? 'https://gitlab.com' ;
96
- const hostname = new URL ( hostUrl ) . hostname ;
97
-
102
+ const repoNameRoot = new URL ( hostUrl )
103
+ . toString ( )
104
+ . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
105
+
98
106
const repos = gitlabRepos . map ( ( project ) => {
99
107
const projectUrl = `${ hostUrl } /${ project . path_with_namespace } ` ;
100
108
const cloneUrl = new URL ( project . http_url_to_repo ) ;
101
109
const isFork = project . forked_from_project !== undefined ;
102
- const repoName = `${ hostname } /${ project . path_with_namespace } ` ;
110
+ const repoDisplayName = project . path_with_namespace ;
111
+ const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
103
112
104
113
const record : RepoData = {
105
114
external_id : project . id . toString ( ) ,
@@ -108,6 +117,7 @@ export const compileGitlabConfig = async (
108
117
cloneUrl : cloneUrl . toString ( ) ,
109
118
webUrl : projectUrl ,
110
119
name : repoName ,
120
+ displayName : repoDisplayName ,
111
121
imageUrl : project . avatar_url ,
112
122
isFork : isFork ,
113
123
isArchived : ! ! project . archived ,
@@ -130,7 +140,8 @@ export const compileGitlabConfig = async (
130
140
'zoekt.gitlab-forks' : ( project . forks_count ?? 0 ) . toString ( ) ,
131
141
'zoekt.archived' : marshalBool ( project . archived ) ,
132
142
'zoekt.fork' : marshalBool ( isFork ) ,
133
- 'zoekt.public' : marshalBool ( project . private === false )
143
+ 'zoekt.public' : marshalBool ( project . private === false ) ,
144
+ 'zoekt.display-name' : repoDisplayName ,
134
145
} ,
135
146
branches : config . revisions ?. branches ?? undefined ,
136
147
tags : config . revisions ?. tags ?? undefined ,
@@ -157,11 +168,14 @@ export const compileGiteaConfig = async (
157
168
const notFound = giteaReposResult . notFound ;
158
169
159
170
const hostUrl = config . url ?? 'https://gitea.com' ;
160
- const hostname = new URL ( hostUrl ) . hostname ;
171
+ const repoNameRoot = new URL ( hostUrl )
172
+ . toString ( )
173
+ . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
161
174
162
175
const repos = giteaRepos . map ( ( repo ) => {
163
176
const cloneUrl = new URL ( repo . clone_url ! ) ;
164
- const repoName = `${ hostname } /${ repo . full_name ! } ` ;
177
+ const repoDisplayName = repo . full_name ! ;
178
+ const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
165
179
166
180
const record : RepoData = {
167
181
external_id : repo . id ! . toString ( ) ,
@@ -170,6 +184,7 @@ export const compileGiteaConfig = async (
170
184
cloneUrl : cloneUrl . toString ( ) ,
171
185
webUrl : repo . html_url ,
172
186
name : repoName ,
187
+ displayName : repoDisplayName ,
173
188
imageUrl : repo . owner ?. avatar_url ,
174
189
isFork : repo . fork ! ,
175
190
isArchived : ! ! repo . archived ,
@@ -191,6 +206,7 @@ export const compileGiteaConfig = async (
191
206
'zoekt.archived' : marshalBool ( repo . archived ) ,
192
207
'zoekt.fork' : marshalBool ( repo . fork ! ) ,
193
208
'zoekt.public' : marshalBool ( repo . internal === false && repo . private === false ) ,
209
+ 'zoekt.display-name' : repoDisplayName ,
194
210
} ,
195
211
branches : config . revisions ?. branches ?? undefined ,
196
212
tags : config . revisions ?. tags ?? undefined ,
@@ -212,35 +228,41 @@ export const compileGerritConfig = async (
212
228
orgId : number ) => {
213
229
214
230
const gerritRepos = await getGerritReposFromConfig ( config ) ;
215
- const hostUrl = ( config . url ?? 'https://gerritcodereview.com' ) . replace ( / \/ $ / , '' ) ; // Remove trailing slash
216
- const hostname = new URL ( hostUrl ) . hostname ;
231
+ const hostUrl = config . url ;
232
+ const repoNameRoot = new URL ( hostUrl )
233
+ . toString ( )
234
+ . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
217
235
218
236
const repos = gerritRepos . map ( ( project ) => {
219
- const repoId = `${ hostname } /${ project . name } ` ;
220
- const cloneUrl = new URL ( `${ config . url } /${ encodeURIComponent ( project . name ) } ` ) ;
237
+ const cloneUrl = new URL ( path . join ( hostUrl , encodeURIComponent ( project . name ) ) ) ;
238
+ const repoDisplayName = project . name ;
239
+ const repoName = path . join ( repoNameRoot , repoDisplayName ) ;
221
240
222
- let webUrl = "https://www.gerritcodereview.com/" ;
223
- // Gerrit projects can have multiple web links; use the first one
224
- if ( project . web_links ) {
225
- const webLink = project . web_links [ 0 ] ;
226
- if ( webLink ) {
227
- webUrl = webLink . url ;
241
+ const webUrl = ( ( ) => {
242
+ if ( ! project . web_links || project . web_links . length === 0 ) {
243
+ return null ;
228
244
}
229
- }
230
245
231
- // Handle case where webUrl is just a gitiles path
232
- // https://github.com/GerritCodeReview/plugins_gitiles/blob/5ee7f57/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java#L50
233
- if ( webUrl . startsWith ( '/plugins/gitiles/' ) ) {
234
- webUrl = `${ hostUrl } ${ webUrl } ` ;
235
- }
246
+ const webLink = project . web_links [ 0 ] ;
247
+ const webUrl = webLink . url ;
248
+
249
+ // Handle case where webUrl is just a gitiles path
250
+ // https://github.com/GerritCodeReview/plugins_gitiles/blob/5ee7f57/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java#L50
251
+ if ( webUrl . startsWith ( '/plugins/gitiles/' ) ) {
252
+ return path . join ( hostUrl , webUrl ) ;
253
+ } else {
254
+ return webUrl ;
255
+ }
256
+ } ) ( ) ;
236
257
237
258
const record : RepoData = {
238
259
external_id : project . id . toString ( ) ,
239
260
external_codeHostType : 'gerrit' ,
240
261
external_codeHostUrl : hostUrl ,
241
262
cloneUrl : cloneUrl . toString ( ) ,
242
263
webUrl : webUrl ,
243
- name : project . name ,
264
+ name : repoName ,
265
+ displayName : repoDisplayName ,
244
266
isFork : false ,
245
267
isArchived : false ,
246
268
org : {
@@ -256,11 +278,12 @@ export const compileGerritConfig = async (
256
278
metadata : {
257
279
gitConfig : {
258
280
'zoekt.web-url-type' : 'gitiles' ,
259
- 'zoekt.web-url' : webUrl ,
260
- 'zoekt.name' : repoId ,
281
+ 'zoekt.web-url' : webUrl ?? '' ,
282
+ 'zoekt.name' : repoName ,
261
283
'zoekt.archived' : marshalBool ( false ) ,
262
284
'zoekt.fork' : marshalBool ( false ) ,
263
285
'zoekt.public' : marshalBool ( true ) ,
286
+ 'zoekt.display-name' : repoDisplayName ,
264
287
} ,
265
288
} satisfies RepoMetadata ,
266
289
} ;
0 commit comments