-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathcomment-parser.ts
58 lines (51 loc) · 1.52 KB
/
comment-parser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { octokit } from "../util/octokit";
import YAML from "yaml";
const owner = "swc-project";
const repo = "swc";
const maintainer = "kdy1";
export interface Action {
crate: string;
breaking: boolean;
}
export async function parsePrComments(prNumber: number): Promise<Action[]> {
const comments = await octokit.pulls.listReviews({
owner,
repo,
pull_number: prNumber,
});
return comments.data
.filter((c) => c.user && c.user.login === maintainer)
.map((c) => {
const idx = c.body.indexOf("swc-bump:");
if (idx === -1) {
return undefined;
}
return c.body.substring(idx);
})
.filter((text) => !!text)
.map((text) => text!)
.map((text) => YAML.parse(text))
.map((data) => data["swc-bump"])
.flatMap((data) => data)
.map((line) => {
if (typeof line !== "string") {
throw new Error(`Non-string data: ${line}`);
}
line = line.trim();
console.log(`Comment line: '${line}'`);
if (line.endsWith(" --breaking")) {
return {
crate: line.substring(
0,
line.length - " --breaking".length
),
breaking: true,
};
}
return {
crate: line,
breaking: false,
};
})
.filter((l) => !!l);
}