@@ -61,6 +61,22 @@ function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink |
6161 : null ;
6262}
6363
64+ function remoteWebOrigin ( host : string , remoteUrl : string | undefined ) : string {
65+ try {
66+ const remote = new URL ( remoteUrl ?? "" ) ;
67+ if (
68+ ( remote . protocol === "http:" || remote . protocol === "https:" ) &&
69+ ( remote . hostname . toLowerCase ( ) === host . toLowerCase ( ) ||
70+ remote . host . toLowerCase ( ) === host . toLowerCase ( ) )
71+ ) {
72+ return remote . origin ;
73+ }
74+ } catch {
75+ // SSH remotes do not specify the server's web origin.
76+ }
77+ return `https://${ host } ` ;
78+ }
79+
6480export function changeRequestUrlFor (
6581 kind : string | null | undefined ,
6682 host : string ,
@@ -73,27 +89,18 @@ export function changeRequestUrlFor(
7389 return `https://${ host } /${ repository } /pull/${ number } ` ;
7490 case "gitcafe" :
7591 return `https://${ host } /${ repository } /pulls/${ number } ` ;
76- case "forgejo" : {
77- try {
78- const remote = new URL ( remoteUrl ?? "" ) ;
79- if (
80- ( remote . protocol === "http:" || remote . protocol === "https:" ) &&
81- ( remote . hostname . toLowerCase ( ) === host . toLowerCase ( ) ||
82- remote . host . toLowerCase ( ) === host . toLowerCase ( ) )
83- ) {
84- return `${ remote . origin } /${ repository } /pulls/${ number } ` ;
85- }
86- } catch {
87- // SSH remotes do not specify the server's web origin.
88- }
89- return `https://${ host } /${ repository } /pulls/${ number } ` ;
90- }
92+ case "forgejo" :
93+ return `${ remoteWebOrigin ( host , remoteUrl ) } /${ repository } /pulls/${ number } ` ;
9194 case "gitlab" :
9295 return `https://${ host } /${ repository } /-/merge_requests/${ number } ` ;
9396 case "bitbucket" :
9497 return `https://${ host } /${ repository } /pull-requests/${ number } ` ;
95- case "azure-devops" :
96- return `https://${ canonicalRepositoryKey ( `${ host } /${ repository } ` . toLowerCase ( ) ) } /pullrequest/${ number } ` ;
98+ case "azure-devops" : {
99+ const [ canonicalHost = host , ...path ] = canonicalRepositoryKey (
100+ `${ host } /${ repository } ` . toLowerCase ( ) ,
101+ ) . split ( "/" ) ;
102+ return `${ remoteWebOrigin ( canonicalHost , remoteUrl ) } /${ path . join ( "/" ) } /pullrequest/${ number } ` ;
103+ }
97104 default :
98105 return null ;
99106 }
0 commit comments