Skip to content

Commit 395c4fb

Browse files
committed
add metadata to run summary
1 parent e3fc44a commit 395c4fb

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

.github/workflows/custom.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,5 @@ jobs:
4545
uses: ./
4646
env:
4747
GITHUB_TOKEN: ${{ github.token }}
48-
with:
49-
github_token: ${{ secrets.GITHUB_TOKEN }}
50-
postgres_url: http://query_doctor@localhost:5432/testing
51-
log_path: /var/log/postgresql/postgres.log
48+
POSTGRES_URL: http://query_doctor@localhost:5432/testing
49+
# LOG_PATH: /var/log/postgresql/postgres.log

main.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ function formatQuery(query: string) {
2323
}
2424

2525
async function main() {
26-
const logPath = process.env.LOG_PATH || core.getInput("log_path");
27-
const postgresUrl = process.env.POSTGRES_URL || core.getInput("postgres_url");
28-
console.log(logPath);
29-
console.log(postgresUrl);
26+
const logPath = process.env.LOG_PATH || "/var/log/postgresql/postgres.log";
27+
const postgresUrl = process.env.POSTGRES_URL;
28+
if (!postgresUrl) {
29+
core.setFailed("POSTGRES_URL environment variable is not set");
30+
Deno.exit(1);
31+
}
32+
const startDate = new Date();
33+
const fileSize = Deno.statSync(logPath).size;
3034
// core.setOutput("time", new Date().toLocaleTimeString());
3135
const command = new Deno.Command("pgbadger", {
3236
stdout: "piped",
@@ -183,7 +187,13 @@ async function main() {
183187
}
184188
}
185189
const reporter = new GithubReporter(process.env.GITHUB_TOKEN);
186-
await reporter.report({ recommendations });
190+
await reporter.report({
191+
recommendations,
192+
metadata: {
193+
logSize: fileSize,
194+
timeElapsed: Date.now() - startTime,
195+
},
196+
});
187197
console.timeEnd("total");
188198
await output.status;
189199
console.log(`Ran ${matching} queries`);

reporters/github.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class GithubReporter {
2828
(r) =>
2929
r.user &&
3030
r.body_html &&
31-
r.user.type === "Bot" &&
3231
r.body_html.includes(GithubReporter.REVIEW_COMMENT_SUFFIX)
3332
);
3433
const recommendations = ctx.recommendations.map(
@@ -64,15 +63,28 @@ export class GithubReporter {
6463
`
6564
);
6665
let review: string;
66+
const metadata = dedent`
67+
<details>
68+
<summary>Metadata</summary>
69+
<dl>
70+
<dt>Log size</dt>
71+
<dd>${ctx.metadata.logSize}</dd>
72+
<dt>Time elapsed</dt>
73+
<dd>${ctx.metadata.timeElapsed}</dd>
74+
</dl>
75+
</details>
76+
`;
6777
if (recommendations.length > 0) {
6878
review = dedent`
6979
# Found ${recommendations.length} queries that could be optimized
7080
${recommendations.join("\n")}
81+
${metadata}
7182
${GithubReporter.REVIEW_COMMENT_SUFFIX}
7283
`;
7384
} else {
7485
review = dedent`
7586
# Your queries are optimized!
87+
${metadata}
7688
${GithubReporter.REVIEW_COMMENT_SUFFIX}
7789
`;
7890
}
@@ -97,8 +109,14 @@ export class GithubReporter {
97109
}
98110
}
99111

112+
type ReportMetadata = {
113+
logSize: number;
114+
timeElapsed: number;
115+
};
116+
100117
export type ReportContext = {
101118
recommendations: ReportIndexRecommendation[];
119+
metadata: ReportMetadata;
102120
};
103121

104122
export type ReportIndexRecommendation = {

0 commit comments

Comments
 (0)