diff --git a/AGENTS.md b/AGENTS.md index faa07b2..2db91b1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,6 +12,9 @@ which the store pushes itself. Convex codegen writes `src/store/convex/_generated/` and `src/store/component/_generated/`. The store and its readers (Samebase) are released and upgraded together; a renamed function is a version bump on both sides. See `docs/design/convex-state.md`. +- `alchemy-convex stack-comment` reads the store and writes a pull request comment. It reads Worker + and R2 rows of the store, and it depends on no Cloudflare package. GitHub removes most HTML, so + `src/StackComment.ts` names the reason for each choice of its markup. - The Convex CLI owns typecheck, codegen, bundling, and the code push. `Convex.Deployment` only runs the installed `convex deploy`. Do not move work of the Convex CLI into this package. - No backwards compatibility with earlier versions of this package, its store, or its data: diff --git a/CHANGELOG.md b/CHANGELOG.md index d91654d..44a82a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 0.18.0 (unreleased) + +The command `alchemy-convex stack-comment` keeps one comment on a pull request with a card for each +stack of the repository at the stage of the pull request. + +- Run it as a step of a pull request workflow after every deploy. It needs `CONVEX_ACCESS_TOKEN`, + `GITHUB_TOKEN`, and the permission `pull-requests: write`. The run record gives it the repository + and the pull request. +- A card shows the folder of the stack, its address, its last run, and its Convex deployments, + Workers, and R2 buckets. A stack without the stage of the pull request has no card. +- Remove a `GitHub.Comment` from the stack. A comment that a stack declares can show only that stack. + ## 0.17.0 (unreleased) The hub is the project `identity-hub`, a name that says what the project holds. diff --git a/NOTICE b/NOTICE index d5bf30b..1f5e0ff 100644 --- a/NOTICE +++ b/NOTICE @@ -8,6 +8,9 @@ packages/alchemy, under the ISC license: - the Convex CLI runner in src/Push.ts (internal/CommandRunner.ts), - the deployment lookup rules in src/Deployment.ts and the project listing in src/Project.ts. +The Workers and R2 icons in assets/stack-comment are by Cloudflare, under CC BY 4.0 +(https://creativecommons.org/licenses/by/4.0/), with Cloudflare orange fill. + ISC License Copyright 2024 RJ Dellecese diff --git a/README.md b/README.md index 44e80ec..0e3f8ef 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,33 @@ of the app, before the first push: it registers the deployment of that directory npx alchemy-convex hub-client --team my-team --app scout --callback-path /auth/hub/callback ``` +## Pull request comment + +`alchemy-convex stack-comment` keeps one comment on a pull request. The comment has a card for each +stack of the repository at the stage `pr-`: the folder, the address, the last run, and the +Convex deployments, Workers, and R2 buckets. A stack sees only itself, so a comment that a stack +declares cannot show this. + +Run it after every deploy of the workflow. The run record gives the repository and the pull request, +so the command needs no argument with a team access token: + +```yaml +permissions: + pull-requests: write + +steps: + # The deploy steps of each stack. + - name: Update the stack comment + if: github.event_name == 'pull_request' + run: pnpm exec alchemy-convex stack-comment + env: + CONVEX_ACCESS_TOKEN: ${{ secrets.CONVEX_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ github.token }} +``` + +A stack named `owner/name`, or `owner/name/` for a stack in a folder, belongs to the +repository `owner/name`. A stack without the stage of the pull request has no card. + ## Data safety - `Convex.Project` and `Convex.Deployment` have the removal policy `retain`. `alchemy destroy` diff --git a/assets/stack-comment/convex.svg b/assets/stack-comment/convex.svg new file mode 100644 index 0000000..fced7ad --- /dev/null +++ b/assets/stack-comment/convex.svg @@ -0,0 +1 @@ + diff --git a/assets/stack-comment/r2.svg b/assets/stack-comment/r2.svg new file mode 100644 index 0000000..f467787 --- /dev/null +++ b/assets/stack-comment/r2.svg @@ -0,0 +1,2 @@ + + diff --git a/assets/stack-comment/spacer.svg b/assets/stack-comment/spacer.svg new file mode 100644 index 0000000..d497aa6 --- /dev/null +++ b/assets/stack-comment/spacer.svg @@ -0,0 +1 @@ + diff --git a/assets/stack-comment/worker.svg b/assets/stack-comment/worker.svg new file mode 100644 index 0000000..785b1ed --- /dev/null +++ b/assets/stack-comment/worker.svg @@ -0,0 +1,2 @@ + + diff --git a/package.json b/package.json index 96c31e8..fe02434 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@samebase/alchemy-convex", - "version": "0.17.0", + "version": "0.18.0", "description": "The Convex plane for Alchemy v2: projects, deployments, environment variables, and the push of the functions", "keywords": [ "alchemy", diff --git a/src/StackComment.ts b/src/StackComment.ts new file mode 100644 index 0000000..004b4ae --- /dev/null +++ b/src/StackComment.ts @@ -0,0 +1,307 @@ +// The command `alchemy-convex stack-comment`: one comment on a pull request with the stacks of the +// repository, read from the state store after the deploys. +// +// A stack sees only itself, so a comment that a stack declares cannot show the other stacks of the +// repository. This command runs as a step after them and reads each stack named `owner/name` or +// `owner/name/` that has the stage `pr-`. A stack without that stage has no card. A +// run replaces the whole body, so the last run shows the newest state. +// +// It reads only the fields of the rows below, because Alchemy state holds secrets in clear text. +// +// GitHub keeps a fixed set of HTML in a comment and removes `style` and `class`, so every choice of +// the markup is a fact about the sanitizer or the CSS of github.com: +// - A table has `display: block` and `width: max-content`, so a `width` on it does nothing. The +// spacer, a floated image one pixel high in a block of its own, gives every card one width, and +// it shrinks on a narrow page. +// - The CSS colors the even rows of a group, so each row has its own `tbody`. +// - An HTML block ends at a blank line, so a table has none and is not indented. +// - A bare image links to its raw file, and one link around an image and text underlines the space +// between them, so the icon and the name are two links to one place. +// - An image with `height` gets a gray background, so each icon is square and has only `width`. +// - `align="middle"` is `-webkit-baseline-middle` in Chrome, which is below the text. +// `align="absmiddle"` is the CSS value `middle`. +import { State } from "alchemy/State"; +import * as Effect from "effect/Effect"; +import * as Schema from "effect/Schema"; +import { RUN_RECORD_KEY, runRecord } from "./RunRecord.ts"; + +/** The first text of the comment, which finds it again. */ +const MARKER = ""; + +/** GitHub does not proxy this host, so a new icon needs no purge of its image cache. */ +const ICONS = "https://raw.githubusercontent.com/samebase/alchemy-convex/main/assets/stack-comment"; + +const GITHUB_API = "https://api.github.com"; + +/** The resources that a card shows. A row of any other type, or without `attr` from an interrupted deploy, is left out. */ +const Resource = Schema.Union([ + Schema.Struct({ + resourceType: Schema.Literal("Convex.Deployment"), + attr: Schema.Struct({ name: Schema.String, siteUrl: Schema.String }), + }), + Schema.Struct({ + resourceType: Schema.Literal("Cloudflare.Worker"), + attr: Schema.Struct({ workerName: Schema.String, url: Schema.optional(Schema.String) }), + }), + Schema.Struct({ + resourceType: Schema.Literal("Cloudflare.R2.Bucket"), + attr: Schema.Struct({ + bucketName: Schema.String, + accountId: Schema.String, + jurisdiction: Schema.String, + }), + }), +]); +type Resource = typeof Resource.Type; + +/** The fields of the run record that a card shows. */ +const StageOutput = Schema.Struct({ + [RUN_RECORD_KEY]: Schema.Struct({ + headCommit: Schema.String, + runUrl: Schema.NullOr(Schema.String), + recordedAt: Schema.String, + }), +}); + +export interface StackCard { + readonly name: string; + readonly stage: string; + readonly resources: readonly Resource[]; + readonly run: typeof StageOutput.Type | null; +} + +export class StackCommentError extends Schema.TaggedError()( + "StackCommentError", + { reason: Schema.String }, +) { + override get message() { + return `The stack comment cannot be updated: ${this.reason}`; + } +} + +/** The cards of the stacks of `repository` that have `stage`, in name order. */ +export const readStackCards = ({ repository, stage }: { repository: string; stage: string }) => + Effect.gen(function* () { + const state = yield* yield* State; + const names = (yield* state.listStacks()).filter( + (name) => name === repository || name.startsWith(`${repository}/`), + ); + const cards: StackCard[] = []; + for (const name of names) { + if (!(yield* state.listStages(name)).includes(stage)) { + continue; + } + const request = { stack: name, stage }; + const rows = yield* Effect.forEach(yield* state.list(request), (fqn) => + state.get({ ...request, fqn }), + ); + const output = yield* state.getOutput(request); + cards.push({ + name, + stage, + resources: rows.filter(Schema.is(Resource)), + run: Schema.is(StageOutput)(output) ? output : null, + }); + } + return cards; + }); + +/** A stack can create a deployment in one resource and push to it in another: a card shows it once. */ +const withoutRepeats = (resources: readonly Resource[]) => { + const deployments = new Set(); + return resources.filter((resource) => { + if (resource.resourceType !== "Convex.Deployment") { + return true; + } + const repeated = deployments.has(resource.attr.name); + deployments.add(resource.attr.name); + return !repeated; + }); +}; + +const escapeHtml = (text: string) => + text + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll('"', """); + +const link = (href: string, text: string) => `${text}`; + +const named = (href: string, icon: string, alt: string, name: string) => { + const image = `${alt}`; + return `${link(href, image)} ${link(href, escapeHtml(name))}`; +}; + +const hostOf = (url: string) => escapeHtml(new URL(url).host); + +/** Where a stack serves: its Convex deployment, else its first Worker with a URL. */ +const addressOf = (resources: readonly Resource[]) => { + for (const resource of resources) { + if (resource.resourceType === "Convex.Deployment") { + return resource.attr.siteUrl; + } + } + for (const resource of resources) { + if (resource.resourceType === "Cloudflare.Worker" && resource.attr.url !== undefined) { + return resource.attr.url; + } + } + return null; +}; + +const resourceRow = (resource: Resource, address: string | null) => { + switch (resource.resourceType) { + case "Convex.Deployment": { + const { name } = resource.attr; + return named( + `https://dashboard.convex.dev/d/${encodeURIComponent(name)}`, + "convex", + "Convex", + name, + ); + } + case "Cloudflare.Worker": { + const { url, workerName } = resource.attr; + const row = named( + `https://dash.cloudflare.com/?to=/:account/workers/services/view/${encodeURIComponent(workerName)}`, + "worker", + "Worker", + workerName, + ); + return url === undefined || url === address + ? row + : `${row}
${link(url, hostOf(url))}`; + } + case "Cloudflare.R2.Bucket": { + const { accountId, bucketName, jurisdiction } = resource.attr; + return named( + `https://dash.cloudflare.com/${encodeURIComponent(accountId)}/r2/${encodeURIComponent(jurisdiction)}/buckets/${encodeURIComponent(bucketName)}`, + "r2", + "R2 bucket", + bucketName, + ); + } + } +}; + +const runLine = ({ run }: StackCard) => { + if (run === null) { + return ""; + } + const { headCommit, recordedAt, runUrl } = run[RUN_RECORD_KEY]; + const commit = escapeHtml(headCommit.slice(0, 7)); + const time = `${recordedAt.slice(0, 16).replace("T", " ")} UTC`; + return `
${runUrl === null ? commit : link(runUrl, commit)} ${escapeHtml(time)}`; +}; + +const SPACER = `
`; + +/** `alone`: the one card of the repository. A card at the root then has no folder, as on the repository page. */ +const renderCard = (card: StackCard, repository: string, alone: boolean) => { + const folder = card.name.slice(repository.length + 1); + const heading = [ + folder === "" && alone ? "" : `${escapeHtml(folder || "/")} `, + `${escapeHtml(card.stage)}`, + ].join(""); + const resources = withoutRepeats(card.resources); + const address = addressOf(resources); + const addressLine = address === null ? "" : `
${link(address, hostOf(address))}`; + const rows = resources + .map((resource) => `${resourceRow(resource, address)}`) + .join("\n"); + return ` + +${rows} +
${SPACER}${heading}${addressLine}${runLine(card)}
`; +}; + +export const renderStackComment = (cards: readonly StackCard[], repository: string) => `${MARKER} +${cards.map((card) => renderCard(card, repository, cards.length === 1)).join("\n\n")} +`; + +const Comments = Schema.Array(Schema.Struct({ id: Schema.Number, body: Schema.String })); +const SavedComment = Schema.Struct({ html_url: Schema.String }); + +const github = (token: string, path: string, init: { method: string; body?: string }) => + Effect.tryPromise({ + try: async (): Promise => { + const response = await fetch(`${GITHUB_API}${path}`, { + ...init, + headers: { + Accept: "application/vnd.github+json", + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + "X-GitHub-Api-Version": "2022-11-28", + }, + }); + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + return await response.json(); + }, + catch: (error) => + new StackCommentError({ + reason: `GitHub ${init.method} ${path} failed (${error instanceof Error ? error.message : String(error)})`, + }), + }); + +const decode = + >(schema: S, what: string) => + (value: unknown) => + Schema.decodeUnknownEffect(schema)(value).pipe( + Effect.mapError(() => new StackCommentError({ reason: `GitHub gave a bad ${what}` })), + ); + +const findComment = (token: string, path: string) => + Effect.gen(function* () { + for (let page = 1; ; page += 1) { + const comments = yield* github(token, `${path}?per_page=100&page=${page}`, { + method: "GET", + }).pipe(Effect.flatMap(decode(Comments, "comment list"))); + const comment = comments.find(({ body }) => body.startsWith(MARKER)); + if (comment !== undefined || comments.length < 100) { + return comment; + } + } + }); + +/** Replaces the body of the comment of this command, or posts it on the first run, and gives its URL. */ +export const saveStackComment = (args: { + readonly token: string; + readonly repository: string; + readonly pullRequest: number; + readonly body: string; +}) => + Effect.gen(function* () { + const { body, pullRequest, repository, token } = args; + const comments = `/repos/${repository}/issues/${pullRequest}/comments`; + const comment = yield* findComment(token, comments); + const reply = yield* comment === undefined + ? github(token, comments, { method: "POST", body: JSON.stringify({ body }) }) + : github(token, `/repos/${repository}/issues/comments/${comment.id}`, { + method: "PATCH", + body: JSON.stringify({ body }), + }); + const saved = yield* decode(SavedComment, "comment")(reply); + return saved.html_url; + }); + +/** The step of a workflow: the run record names the repository and the pull request of the run. */ +export const updateStackComment = Effect.gen(function* () { + const { pullRequest, repository } = yield* runRecord({ cwd: process.cwd(), env: process.env }); + if (pullRequest === null) { + return yield* new StackCommentError({ reason: "this run has no pull request" }); + } + const token = process.env["GITHUB_TOKEN"]; + if (token === undefined || token === "") { + return yield* new StackCommentError({ reason: "GITHUB_TOKEN is not set" }); + } + const cards = yield* readStackCards({ repository, stage: `pr-${pullRequest}` }); + return yield* saveStackComment({ + token, + repository, + pullRequest, + body: renderStackComment(cards, repository), + }); +}); diff --git a/src/cli.ts b/src/cli.ts index 07f9815..2b8f873 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,19 +1,25 @@ #!/usr/bin/env node -// The command of the package: +// The commands of the package: // // alchemy-convex hub-client --team --app --callback-path +// alchemy-convex stack-comment [--team ] // -// It runs in the directory of a Convex app, and gives the development deployment of that directory -// a client of the identity hub of the team: see registerDevelopmentClient. It uses -// CONVEX_ACCESS_TOKEN or the Convex CLI login. +// hub-client runs in the directory of a Convex app, and gives the development deployment of that +// directory a client of the identity hub of the team: see registerDevelopmentClient. stack-comment +// runs as a step of a pull request workflow after the deploys, and keeps one comment with the stacks +// of the repository: see src/StackComment.ts. It needs GITHUB_TOKEN and, with a team access token, +// no --team. Both use CONVEX_ACCESS_TOKEN or the Convex CLI login. import { execFileSync } from "node:child_process"; import { parseArgs } from "node:util"; +import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import { fromConfig } from "./Credentials.ts"; import { registerDevelopmentClient } from "./HubClient.ts"; import { ManagementApiLive } from "./ManagementApi.ts"; import { installedCli } from "./Push.ts"; +import { updateStackComment } from "./StackComment.ts"; +import { state } from "./State.ts"; const { positionals, values } = parseArgs({ allowPositionals: true, @@ -24,38 +30,50 @@ const { positionals, values } = parseArgs({ }, }); const { team, app, "callback-path": callbackPath } = values; -if ( - positionals.join(" ") !== "hub-client" || - team === undefined || - app === undefined || - callbackPath === undefined -) { - console.error( - "Usage: alchemy-convex hub-client --team --app --callback-path ", +const USAGE = `Usage: + alchemy-convex hub-client --team --app --callback-path + alchemy-convex stack-comment [--team ]`; + +const hubClient = (hub: { team: string; app: string; callbackPath: string }) => + Effect.gen(function* () { + const [command, ...prefix] = yield* installedCli(process.cwd()); + const callbackUrl = yield* registerDevelopmentClient({ + ...hub, + convex: (args, input) => + execFileSync(command, [...prefix, ...args], { + encoding: "utf8", + input, + stdio: ["pipe", "pipe", "inherit"], + }).trim(), + }); + console.log( + callbackUrl === undefined + ? "Hub client already registered." + : `Hub client registered for ${callbackUrl}.`, + ); + }).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig())))); + +const stackComment = (options: { team?: string }) => + updateStackComment.pipe( + Effect.tap((url) => Effect.sync(() => console.log(url))), + Effect.provide(state(options).pipe(Layer.provide(NodeServices.layer))), ); + +const subcommand = positionals.join(" "); +const program: Effect.Effect | undefined = + subcommand === "stack-comment" + ? stackComment(team === undefined ? {} : { team }) + : subcommand === "hub-client" && + team !== undefined && + app !== undefined && + callbackPath !== undefined + ? hubClient({ team, app, callbackPath }) + : undefined; +if (program === undefined) { + console.error(USAGE); process.exit(1); } -const program = Effect.gen(function* () { - const [command, ...prefix] = yield* installedCli(process.cwd()); - const callbackUrl = yield* registerDevelopmentClient({ - team, - app, - callbackPath, - convex: (args, input) => - execFileSync(command, [...prefix, ...args], { - encoding: "utf8", - input, - stdio: ["pipe", "pipe", "inherit"], - }).trim(), - }); - console.log( - callbackUrl === undefined - ? "Hub client already registered." - : `Hub client registered for ${callbackUrl}.`, - ); -}).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig())))); - await Effect.runPromise(program).catch((error: unknown) => { console.error(error instanceof Error ? error.message : String(error)); process.exit(1); diff --git a/test/StackComment.test.ts b/test/StackComment.test.ts new file mode 100644 index 0000000..4786e2b --- /dev/null +++ b/test/StackComment.test.ts @@ -0,0 +1,226 @@ +// The comment from recorded stages: the app and the sidebars example of samebase/samebase at its +// pull request 1829, and a bucket of samebase/scout. Secret values and `props.env` are not recorded. +import { readFileSync } from "node:fs"; +import { inMemoryState } from "alchemy/State"; +import * as Effect from "effect/Effect"; +import * as Exit from "effect/Exit"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { + readStackCards, + renderStackComment, + saveStackComment, + type StackCard, +} from "../src/StackComment.ts"; + +interface RecordedStage { + readonly stack: string; + readonly stage: string; + readonly rows: readonly { readonly fqn: string }[]; + readonly output: unknown; +} + +const recorded = (path: string): unknown => + JSON.parse(readFileSync(new URL(path, import.meta.url), "utf8")); + +const stages = recorded("./fixtures/state/stack_comment_stages.json") as readonly RecordedStage[]; + +const repository = "samebase/samebase"; + +const stateOf = (recordedStages: readonly RecordedStage[]) => { + const rows: Record>> = {}; + const outputs: Record> = {}; + for (const { output, rows: stageRows, stack, stage } of recordedStages) { + rows[stack] = { + ...rows[stack], + [stage]: Object.fromEntries(stageRows.map((row) => [row.fqn, row as never])), + }; + outputs[stack] = { ...outputs[stack], [stage]: output }; + } + return inMemoryState(rows, outputs); +}; + +const cardsAt = (stage: string, name = repository) => + Effect.runPromise( + readStackCards({ repository: name, stage }).pipe(Effect.provide(stateOf(stages))), + ); + +const worker = (cards: readonly StackCard[]) => cards[1]?.resources[0]; + +describe("readStackCards", () => { + it("gives a card for each stack of the repository with the stage", async () => { + const cards = await cardsAt("pr-1829"); + + expect(cards.map(({ name }) => name)).toEqual([ + "samebase/samebase/apps/samebase", + "samebase/samebase/apps/sidebars-example", + ]); + }); + + it("gives no card for a stack without the stage", async () => { + expect(await cardsAt("pr-1")).toEqual([]); + }); + + it("does not read a repository whose name starts with the same text", async () => { + expect(await cardsAt("pr-1829", "samebase/same")).toEqual([]); + }); + + it("leaves out a row of another type", async () => { + const [app] = await cardsAt("pr-1829"); + + expect(app?.resources.map(({ resourceType }) => resourceType)).toEqual([ + "Convex.Deployment", + "Convex.Deployment", + ]); + }); +}); + +describe("renderStackComment", () => { + it("starts with the marker that finds the comment again", async () => { + const body = renderStackComment(await cardsAt("pr-1829"), repository); + + expect(body.startsWith("\n")).toBe(true); + }); + + it("names each stack by its folder, with its address and its run", async () => { + const body = renderStackComment(await cardsAt("pr-1829"), repository); + + expect(body).toContain("apps/samebase pr-1829"); + expect(body).toContain("apps/sidebars-example pr-1829"); + expect(body).toContain('">adventurous-dog-484.convex.site'); + expect(body).toContain(">7b23daa 2026-10-31"); + }); + + it("shows the two rows of one deployment once", async () => { + const [app] = await cardsAt("pr-1829"); + + const body = renderStackComment(app ? [app] : [], repository); + + expect(body.match(/convex\.svg/g)).toHaveLength(1); + }); + + it("does not repeat the address of a Worker in its row", async () => { + const body = renderStackComment(await cardsAt("pr-1829"), repository); + + expect(body.match(/
{ + const cards = await cardsAt("pr-1829"); + const row = worker(cards); + const [app] = cards; + + const body = renderStackComment( + app && row ? [{ ...app, resources: [...app.resources, row] }] : [], + repository, + ); + + expect(body).toContain( + '
', + ); + }); + + it("links a bucket to the dashboard page of its jurisdiction", async () => { + const cards = await cardsAt("prod", "samebase/scout"); + + const body = renderStackComment(cards, "samebase/scout"); + + expect(body).toMatch( + /href="https:\/\/dash\.cloudflare\.com\/[0-9a-f]+\/r2\/default\/buckets\/[^"]+"/, + ); + }); + + it("names the root only when the repository has several cards", async () => { + const [app] = await cardsAt("pr-1829"); + const root = app ? [{ ...app, name: repository }] : []; + + expect(renderStackComment(root, repository)).not.toContain("/"); + expect(renderStackComment([...root, ...root], repository)).toContain("/"); + }); + + it("has a blank line between tables and none inside a table", async () => { + const body = renderStackComment(await cardsAt("pr-1829"), repository); + + expect(body.split("\n\n")).toHaveLength(2); + }); + + it("escapes the values of the state", async () => { + const [bucket] = await cardsAt("prod", "samebase/scout"); + const [row] = bucket?.resources ?? []; + + const body = renderStackComment( + bucket && row?.resourceType === "Cloudflare.R2.Bucket" + ? [ + { + ...bucket, + resources: [{ ...row, attr: { ...row.attr, bucketName: "