Skip to content

Commit ef78963

Browse files
committed
Try to fix compile errors
1 parent a90933a commit ef78963

File tree

1 file changed

+38
-48
lines changed

1 file changed

+38
-48
lines changed

src/utils/releases.ts

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve } from "node:path/posix";
2+
import { handlers } from "svelte/legacy";
23

34
interface Release {
45
name: string;
@@ -49,54 +50,18 @@ export async function fetchRelease(repo: string): Promise<Release[]> {
4950
})
5051
// Post-processing
5152
.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(/https\:\/\/github\.com\/\w+\/\w+\/pull\/\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(/https\:\/\/github\.com\/\w+\/\w+\/compare\/[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, /https\:\/\/github\.com\/\w+\/\w+\/pull\/\d+/g, (match) => {
55+
const split: string[] = match.split("/");
56+
return `[#${split[split.length - 1]}](${match})`;
57+
});
58+
handleRegex(obj, /https\:\/\/github\.com\/\w+\/\w+\/compare\/[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) => {
10065
Object.entries({
10166
bug: "🐛",
10267
older_adult: "🧓",
@@ -114,3 +79,28 @@ export async function fetchRelease(repo: string): Promise<Release[]> {
11479
cache.set(repo, out);
11580
return out;
11681
}
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

Comments
 (0)