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.
This commit is contained in:
parent
6b0b3729f3
commit
d56e509649
2 changed files with 12 additions and 3 deletions
|
|
@ -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}`);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue