File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,18 @@ describe('test getRepositoryInfo', () => {
252
252
url : 'git+https://bitbucket.org/2klicdev/2klic-sdk.git' ,
253
253
} ;
254
254
255
+ const githubRepoWithDirectory = {
256
+ type : 'git' ,
257
+ url : 'https://github.com/facebook/react.git' ,
258
+ directory : './packages/react-dom' ,
259
+ } ;
260
+
261
+ const githubRepoWithPathUrlAndDirectory = {
262
+ type : 'git' ,
263
+ url : 'https://github.com/facebook/react/tree/master/packages/wrong' ,
264
+ directory : './packages/react-dom' ,
265
+ } ;
266
+
255
267
expect ( getRepositoryInfo ( githubRepo ) ) . toEqual ( {
256
268
host : 'github.com' ,
257
269
user : 'webpack' ,
@@ -272,6 +284,20 @@ describe('test getRepositoryInfo', () => {
272
284
project : '2klic-sdk' ,
273
285
path : '' ,
274
286
} ) ;
287
+
288
+ expect ( getRepositoryInfo ( githubRepoWithDirectory ) ) . toEqual ( {
289
+ host : 'github.com' ,
290
+ user : 'facebook' ,
291
+ project : 'react' ,
292
+ path : 'packages/react-dom' ,
293
+ } ) ;
294
+
295
+ expect ( getRepositoryInfo ( githubRepoWithPathUrlAndDirectory ) ) . toEqual ( {
296
+ host : 'github.com' ,
297
+ user : 'facebook' ,
298
+ project : 'react' ,
299
+ path : 'packages/react-dom' ,
300
+ } ) ;
275
301
} ) ;
276
302
277
303
it ( 'should return null if it cannot get information' , ( ) => {
Original file line number Diff line number Diff line change @@ -338,6 +338,7 @@ function getRepositoryInfo(repository) {
338
338
}
339
339
340
340
const url = typeof repository === 'string' ? repository : repository . url ;
341
+ const path = typeof repository === 'string' ? '' : repository . directory || '' ;
341
342
342
343
if ( ! url ) {
343
344
return null ;
@@ -354,7 +355,7 @@ function getRepositoryInfo(repository) {
354
355
project,
355
356
user,
356
357
host : domain ,
357
- path : '' ,
358
+ path : path . replace ( / ^ [ . / ] + / , '' ) ,
358
359
} ;
359
360
}
360
361
@@ -363,7 +364,14 @@ function getRepositoryInfo(repository) {
363
364
* https://github.com/babel/babel/tree/master/packages/babel-core
364
365
* so we need to do it
365
366
*/
366
- return getRepositoryInfoFromHttpUrl ( url ) ;
367
+ const repositoryInfoFromUrl = getRepositoryInfoFromHttpUrl ( url ) ;
368
+ if ( ! repositoryInfoFromUrl ) {
369
+ return null ;
370
+ }
371
+ return {
372
+ ...repositoryInfoFromUrl ,
373
+ path : path . replace ( / ^ [ . / ] + / , '' ) || repositoryInfoFromUrl . path ,
374
+ } ;
367
375
}
368
376
369
377
function formatUser ( user ) {
You can’t perform that action at this time.
0 commit comments