1
1
import { resolve } from "node:path/posix" ;
2
+ import { handlers } from "svelte/legacy" ;
2
3
3
4
interface Release {
4
5
name : string ;
@@ -49,54 +50,18 @@ export async function fetchRelease(repo: string): Promise<Release[]> {
49
50
} )
50
51
// Post-processing
51
52
. map ( ( obj ) => {
52
- // Link contributors
53
- {
54
- const alreadyMatched : string [ ] = [ ] ;
55
- obj . body
56
- . matchAll ( / \@ ( \w | \d | \- ) + / g)
57
- . map ( ( match ) => match [ 0 ] )
58
- . forEach ( ( match ) => {
59
- if ( alreadyMatched . find ( ( e ) => e == match ) != null ) {
60
- return ;
61
- }
62
-
63
- obj . body = obj . body . replaceAll ( match , `[${ match } ](https://github.com/${ match . substring ( 1 ) } )` ) ;
64
- alreadyMatched . push ( match ) ;
65
- } ) ;
66
- }
67
- {
68
- const alreadyMatched : string [ ] = [ ] ;
69
- obj . body
70
- . matchAll ( / h t t p s \: \/ \/ g i t h u b \. c o m \/ \w + \/ \w + \/ p u l l \/ \d + / g)
71
- . map ( ( match ) => match [ 0 ] )
72
- . forEach ( ( match ) => {
73
- if ( alreadyMatched . find ( ( e ) => e == match ) != null ) {
74
- return ;
75
- }
76
-
77
- const split : string [ ] = match . split ( "/" ) ;
78
-
79
- obj . body = obj . body . replaceAll ( match , `[#${ split [ split . length - 1 ] } ](${ match } )` ) ;
80
- alreadyMatched . push ( match ) ;
81
- } ) ;
82
- }
83
- {
84
- const alreadyMatched : string [ ] = [ ] ;
85
- obj . body
86
- . matchAll ( / h t t p s \: \/ \/ g i t h u b \. c o m \/ \w + \/ \w + \/ c o m p a r e \/ [ v \. \d ] + / g)
87
- . map ( ( match ) => match [ 0 ] )
88
- . forEach ( ( match ) => {
89
- if ( alreadyMatched . find ( ( e ) => e == match ) != null ) {
90
- return ;
91
- }
92
-
93
- const split : string [ ] = match . split ( "/" ) ;
94
-
95
- obj . body = obj . body . replaceAll ( match , `[${ split [ split . length - 1 ] } ](${ match } )` ) ;
96
- alreadyMatched . push ( match ) ;
97
- } ) ;
98
- }
99
-
53
+ handleRegex ( obj , / \@ ( \w | \d | \- ) + / g, ( match ) => `[${ match } ](https://github.com/${ match . substring ( 1 ) } )` ) ;
54
+ handleRegex ( obj , / h t t p s \: \/ \/ g i t h u b \. c o m \/ \w + \/ \w + \/ p u l l \/ \d + / g, ( match ) => {
55
+ const split : string [ ] = match . split ( "/" ) ;
56
+ return `[#${ split [ split . length - 1 ] } ](${ match } )` ;
57
+ } ) ;
58
+ handleRegex ( obj , / h t t p s \: \/ \/ g i t h u b \. c o m \/ \w + \/ \w + \/ c o m p a r e \/ [ v \. \d ] + / g, ( match ) => {
59
+ const split : string [ ] = match . split ( "/" ) ;
60
+ return `[${ split [ split . length - 1 ] } ](${ match } )` ;
61
+ } ) ;
62
+ return obj ;
63
+ } )
64
+ . map ( ( obj ) => {
100
65
Object . entries ( {
101
66
bug : "🐛" ,
102
67
older_adult : "🧓" ,
@@ -114,3 +79,28 @@ export async function fetchRelease(repo: string): Promise<Release[]> {
114
79
cache . set ( repo , out ) ;
115
80
return out ;
116
81
}
82
+
83
+ function handleRegex ( obj : Release , regex : RegExp , onMatch : ( match : string ) => string ) {
84
+ if ( obj . body == null || obj . body . matchAll == null ) {
85
+ console . warn ( "obj.body is null. Not resolving any further." ) ;
86
+ return ;
87
+ }
88
+
89
+ const alreadyMatched : string [ ] = [ ] ;
90
+ let result = obj . body . matchAll ( regex ) ;
91
+ if ( result == null || result . map == null ) {
92
+ console . warn ( "Result of match was null." ) ;
93
+ return ;
94
+ }
95
+
96
+ result
97
+ . map ( ( match ) => match [ 0 ] )
98
+ . forEach ( ( match ) => {
99
+ if ( alreadyMatched . find ( ( e ) => e == match ) != null ) {
100
+ return ;
101
+ }
102
+
103
+ obj . body = obj . body . replaceAll ( match , onMatch ( match ) ) ;
104
+ alreadyMatched . push ( match ) ;
105
+ } ) ;
106
+ }
0 commit comments