From d56e509649a0b98a81db6c326c1abe5c236ab1f4 Mon Sep 17 00:00:00 2001 From: kimi-reviewer-andresmgsl Date: Wed, 22 Jul 2026 21:37:56 +0000 Subject: [PATCH] Preserve raw review body while validating emptiness Validate non-APPROVED reviews using trim().length, but send the original unmodified body to the API so Markdown whitespace is preserved. --- src/cli.js | 6 +++--- test/api.test.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cli.js b/src/cli.js index 350db6a..36497e6 100755 --- a/src/cli.js +++ b/src/cli.js @@ -756,12 +756,12 @@ pr console.error(`Invalid review event: ${options.event}. Must be approve, request-changes, or comment.`); process.exit(1); } - const body = (readBodyOption(options) || '').trim(); - if (event !== 'APPROVED' && body.length === 0) { + const rawBody = readBodyOption(options) || ''; + if (event !== 'APPROVED' && rawBody.trim().length === 0) { console.error(`Review event ${options.event} requires a non-empty body. Use -b/--body or --body-file.`); process.exit(1); } - await client.createPullRequestReview(options.owner, options.repo, options.number, event, body); + await client.createPullRequestReview(options.owner, options.repo, options.number, event, rawBody); console.log(`Review submitted on !${options.number}: ${event}.`); } catch (err) { console.error(`Failed to submit review: ${err.message}`); diff --git a/test/api.test.js b/test/api.test.js index 317ac3e..4fede09 100644 --- a/test/api.test.js +++ b/test/api.test.js @@ -170,3 +170,12 @@ test('createPullRequestReview posts the review event and body', async () => { assert.equal(body.event, 'APPROVED'); assert.equal(body.body, 'Ship it.'); }); + +test('createPullRequestReview preserves leading and trailing whitespace in the body', async () => { + const calls = mockFetch(() => jsonResponse({ id: 89 })); + const client = new ForgejoClient('https://forge.test', 'tok'); + const rawBody = ' code block prefix\n'; + await client.createPullRequestReview('owner', 'repo', 8, 'REQUEST_CHANGES', rawBody); + const body = JSON.parse(calls[0].opts.body); + assert.equal(body.body, rawBody); +});