@@ -9,28 +9,36 @@ import type { ForgeConfig, ForgeType } from './types';
99 * - forgeHint overrides auto-detection
1010 */
1111export function detectForge ( repoUrl : string , forgeHint ?: string ) : ForgeConfig | null {
12- let url : URL ;
12+ let url : URL | null = null ;
1313 try {
1414 url = new URL ( repoUrl ) ;
1515 } catch {
16- return null ;
16+ // Not a full URL — try owner/repo shorthand
1717 }
1818
19- // Strip .git suffix and trailing slash from pathname
20- const path = url . pathname . replace ( / \. g i t $ / , '' ) . replace ( / \/ $ / , '' ) ;
21- const segments = path . split ( '/' ) . filter ( Boolean ) ;
19+ let owner : string ;
20+ let repo : string ;
2221
23- if ( segments . length < 2 ) return null ;
24-
25- const owner = segments [ 0 ] ;
26- const repo = segments [ 1 ] ;
22+ if ( url ) {
23+ const path = url . pathname . replace ( / \. g i t $ / , '' ) . replace ( / \/ $ / , '' ) ;
24+ const segments = path . split ( '/' ) . filter ( Boolean ) ;
25+ if ( segments . length < 2 ) return null ;
26+ owner = segments [ 0 ] ;
27+ repo = segments [ 1 ] ;
28+ } else {
29+ // Handle "owner/repo" shorthand
30+ const parts = repoUrl . split ( '/' ) . filter ( Boolean ) ;
31+ if ( parts . length < 2 ) return null ;
32+ owner = parts [ 0 ] ;
33+ repo = parts [ 1 ] ;
34+ }
2735
2836 let type : ForgeType ;
2937 let baseUrl : string ;
3038
3139 if ( forgeHint ) {
3240 type = forgeHint as ForgeType ;
33- } else {
41+ } else if ( url ) {
3442 const host = url . hostname . toLowerCase ( ) ;
3543 if ( host === 'github.com' ) {
3644 type = 'github' ;
@@ -39,16 +47,20 @@ export function detectForge(repoUrl: string, forgeHint?: string): ForgeConfig |
3947 } else {
4048 type = 'gitea' ;
4149 }
50+ } else {
51+ // Shorthand without forge hint — assume GitHub
52+ type = 'github' ;
4253 }
4354
4455 switch ( type ) {
4556 case 'github' :
4657 baseUrl = 'https://api.github.com' ;
4758 break ;
4859 case 'gitlab' :
49- baseUrl = `${ url . protocol } //${ url . host } ` ;
60+ baseUrl = url ? `${ url . protocol } //${ url . host } ` : 'https://gitlab.com' ;
5061 break ;
5162 case 'gitea' :
63+ if ( ! url ) return null ; // Gitea requires full URL for self-hosted
5264 baseUrl = `${ url . protocol } //${ url . host } ` ;
5365 break ;
5466 default :
0 commit comments