@@ -13,6 +13,25 @@ const dependentsRegex = /^network[/]dependents[/]?$/;
1313const dependenciesRegex = / ^ n e t w o r k [ / ] d e p e n d e n c i e s [ / ] ? $ / ;
1414const wikiRegex = / ^ w i k i [ / ] ( .+ ) $ / ;
1515
16+ function pullQueryOut ( searchParameters , pathname ) {
17+ let query = searchParameters . get ( 'q' ) ;
18+
19+ if ( ! query ) {
20+ return '' ;
21+ }
22+
23+ searchParameters . delete ( 'q' ) ;
24+ if ( pathname . endsWith ( '/issues' ) ) {
25+ query = query . replace ( 'is:issue' , '' ) ;
26+ }
27+
28+ if ( pathname . endsWith ( '/pulls' ) ) {
29+ query = query . replace ( 'is:pr' , '' ) ;
30+ }
31+
32+ return ` (${ query . replaceAll ( / \s + / g, ' ' ) . trim ( ) } )` ;
33+ }
34+
1635function styleRevision ( revision ) {
1736 if ( ! revision ) {
1837 return ;
@@ -127,12 +146,24 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
127146 /**
128147 * Shorten URL
129148 */
130-
131149 if ( isReserved || pathname === '/' || ( ! isLocal && ! isRaw && ! isRedirection ) ) {
132- return href
133- . replace ( / ^ h t t p s : [ / ] [ / ] / , '' )
134- . replace ( / ^ w w w [ . ] / , '' )
135- . replace ( / [ / ] $ / , '' ) ;
150+ const parsedUrl = new URL ( href ) ;
151+ const cleanHref = [
152+ parsedUrl . origin
153+ . replace ( / ^ h t t p s : [ / ] [ / ] / , '' )
154+ . replace ( / ^ w w w [ . ] / , '' ) ,
155+ parsedUrl . pathname
156+ . replace ( / [ / ] $ / , '' ) ,
157+ ] ;
158+
159+ if ( [ 'issues' , 'pulls' ] . includes ( user ) && ! repo ) {
160+ const query = pullQueryOut ( parsedUrl . searchParams , parsedUrl . pathname ) ;
161+ cleanHref . push ( parsedUrl . search , query ) ;
162+ } else {
163+ cleanHref . push ( parsedUrl . search ) ;
164+ }
165+
166+ return cleanHref . join ( '' ) ;
136167 }
137168
138169 if ( user && ! repo ) {
@@ -224,17 +255,7 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
224255 }
225256 }
226257
227- let query = searchParams . get ( 'q' ) ?? '' ;
228- if ( query ) {
229- searchParams . delete ( 'q' ) ;
230- if ( pathname . endsWith ( '/issues' ) ) {
231- query = query . replace ( 'is:issue' , '' ) ;
232- } else if ( pathname . endsWith ( '/pulls' ) ) {
233- query = query . replace ( 'is:pr' , '' ) ;
234- }
235-
236- query = ` (${ query . replaceAll ( / \s + / g, ' ' ) . trim ( ) } )` ;
237- }
258+ const query = pullQueryOut ( searchParams , pathname ) ;
238259
239260 if ( searchParams . get ( 'tab' ) === 'readme-ov-file' ) {
240261 searchParams . delete ( 'tab' ) ;
0 commit comments