Skip to content

Commit bc16809

Browse files
committed
traverse
1 parent 4078574 commit bc16809

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

src/index.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import { Octokit } from "@octokit/action";
2-
import { readFileSync } from "fs";
2+
import { readdirSync, readFileSync } from "fs";
33

4-
const compilation_output = readFileSync("compilation.log").toString();
5-
6-
const regex = /warning( .\d+)?:/;
7-
8-
const match_result = compilation_output.match(regex);
9-
10-
if (match_result && match_result.length > 0) {
11-
console.log("compilation output contains warnings.");
12-
}
13-
14-
// if the action is triggered by not a pull request, exit
154
if (!process.env.GITHUB_REF?.startsWith("refs/pull/")) {
165
console.log("not a pull request, exiting.");
176
process.exit(0);
@@ -22,9 +11,28 @@ const octokit = new Octokit();
2211
const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/")!;
2312
const pull_request_number = parseInt(process.env.GITHUB_REF?.split("/")[2]!);
2413

14+
let body = "";
15+
16+
for (const file of readdirSync(".")) {
17+
if (!file.startsWith("compilation") || !file.endsWith(".log")) {
18+
console.log(`skipping ${file}`);
19+
continue;
20+
}
21+
22+
const compilation_output = readFileSync(file).toString();
23+
24+
const regex = /warning( .\d+)?:/;
25+
26+
const match_result = compilation_output.match(regex);
27+
28+
if (match_result && match_result.length > 0) {
29+
body += `detected warnings in the compilation output: <details><summary>compilation output</summary>\n\n\`\`\`\n${compilation_output}\n\`\`\`\n</details>\n`;
30+
}
31+
}
32+
2533
octokit.rest.issues.createComment({
2634
owner,
2735
repo,
2836
issue_number: pull_request_number,
29-
body: `detected warnings in the compilation output: <details><summary>compilation output</summary>\n\n\`\`\`\n${compilation_output}\n\`\`\`\n</details>`,
37+
body,
3038
});

0 commit comments

Comments
 (0)