cloudflare/kumo

Public

mirrored fromhttps://github.com/cloudflare/kumoAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6dc9a73c0bb7ae2731f474f987d92742b4e3b764

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

ci/utils/pr-reporter.ts

59lines · modecode

1/**
2 * PR Reporter Utilities
3 *
4 * Handles building and posting consolidated PR comments from multiple reporters.
5 */
6
7import type { CIContext, ReportItem } from "../reporters/types";
8import { postPRComment as postGitHubPRComment, GITHUB_REPO_OWNER, GITHUB_REPO_NAME } from "./github-api";
9
10/**
11 * Build a consolidated markdown comment from report items
12 */
13export function buildMarkdownComment(
14 items: ReportItem[],
15 failures: string[] = [],
16): string {
17 // Sort by priority (lower = higher in comment)
18 const sorted = [...items].sort((a, b) => a.priority - b.priority);
19
20 const sections = sorted.map((item) => {
21 return `### ${item.title}\n\n${item.content}`;
22 });
23
24 // Add warning section if there were failures
25 if (failures.length > 0) {
26 sections.push(
27 `### Warning\n\nFailed to load ${failures.length} report artifact(s): ${failures.join(", ")}`,
28 );
29 }
30
31 const header = "## PR Release Summary\n";
32 const footer =
33 `\n---\n*Auto-generated by [Kumo CI](https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME})*`;
34
35 return `${header}\n${sections.join("\n\n")}\n${footer}`;
36}
37
38/**
39 * Post a new comment to the PR
40 */
41export async function postPRComment(
42 context: CIContext,
43 body: string,
44): Promise<void> {
45 const { prNumber, apiToken } = context;
46
47 const missing: string[] = [];
48 if (!prNumber) missing.push("prNumber (GITHUB_PR_NUMBER)");
49 if (!apiToken) missing.push("apiToken (GITHUB_TOKEN)");
50
51 if (missing.length > 0) {
52 console.log(` Missing required variables: ${missing.join(", ")}`);
53 return;
54 }
55
56 await postGitHubPRComment(apiToken, Number(prNumber), body);
57
58 console.log(` Posted PR comment to #${prNumber}`);
59}
60