`pr review <n>` gains `--comments-file <path>`, a JSON array of inline
comments submitted with the review. Each entry is one of two exclusive
shapes: a new comment `{ path, line, body }` (mapped to `new_position`,
always the new side) or a reply `{ reply_to, body }`. A reply carries no
line or side — gitea-axi finds the target via the reviews-plus-comments
fan-out (there is no get-comment-by-id endpoint), reconstructs its anchor
from the target's own `diff_hunk`, and infers old/new side from it, so a
same-line post threads with the existing conversation. All entries map
onto the review-submission payload's `comments[]`; no new HTTP layer is
added. An unknown `reply_to` is a VALIDATION_ERROR raised before the POST,
and the submitted inline-comment count rides the action block.
The shared path-resolve-and-read behind --body-file and --comments-file is
extracted into src/flag-file.ts.
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import type { CliDeps } from "./deps.js";
|
|
import { axiError } from "./errors.js";
|
|
import { readFlagFile } from "./flag-file.js";
|
|
import { flagValue } from "./flags.js";
|
|
|
|
/**
|
|
* Resolve the body text a mutation should send from its `--body`/`--body-file`
|
|
* flags. Shared by every command that accepts a body (issue create, issue
|
|
* comment, and the edit/close commands that follow).
|
|
*
|
|
* The two flags are mutually exclusive: accepting both and picking a winner
|
|
* would silently discard text the caller meant to send.
|
|
*/
|
|
export function resolveBodySource(
|
|
deps: CliDeps,
|
|
flags: Record<string, string | true>,
|
|
command: string,
|
|
): string | undefined {
|
|
const body = flagValue(flags, "--body");
|
|
const path = flagValue(flags, "--body-file");
|
|
|
|
if (body !== undefined && path !== undefined) {
|
|
throw axiError(
|
|
"Flags --body and --body-file are mutually exclusive",
|
|
"VALIDATION_ERROR",
|
|
bodyFlagSuggestion(command),
|
|
);
|
|
}
|
|
if (body !== undefined) {
|
|
return body;
|
|
}
|
|
if (path !== undefined) {
|
|
return readBodyFile(deps, path, command);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
/** As {@link resolveBodySource}, for the commands where a body is mandatory. */
|
|
export function requireBodySource(
|
|
deps: CliDeps,
|
|
flags: Record<string, string | true>,
|
|
command: string,
|
|
): string {
|
|
const body = resolveBodySource(deps, flags, command);
|
|
if (body === undefined) {
|
|
throw axiError(
|
|
`${command} requires --body <text> or --body-file <path>`,
|
|
"VALIDATION_ERROR",
|
|
bodyFlagSuggestion(command),
|
|
);
|
|
}
|
|
return body;
|
|
}
|
|
|
|
function bodyFlagSuggestion(command: string): string[] {
|
|
return [
|
|
`Run \`gitea-axi ${command} --body <text>\` or \`gitea-axi ${command} --body-file <path>\``,
|
|
];
|
|
}
|
|
|
|
function readBodyFile(deps: CliDeps, path: string, command: string): string {
|
|
return readFlagFile(deps, path, "--body-file", bodyFlagSuggestion(command));
|
|
}
|