feat: add pr create and comment (task 0010)
All checks were successful
CI / test (pull_request) Successful in 30s
CI / test (push) Successful in 29s

`pr create` takes --title (required), --body/--body-file, --base, --head,
--assignee, --reviewer, repeatable name-resolved --label, and --milestone.
An omitted --head defaults to the current local branch; an omitted --base to
the repository's default branch. Before creating, an existing open PR for the
same base/head pair short-circuits to `pull_request: { number, url, already:
true }` rather than opening a duplicate; only an open PR does, since a closed
one's branches are free to be proposed again.

`pr comment <n>` posts through the shared issue-comment endpoint and returns
the created comment as `comment: { number, author, created, body }` (ADR 0008),
reporting a 404 as PR_NOT_FOUND since the caller asked about a pull request.

That comment block is now built in one place (src/comment.ts) for both issue
and pr comment, as ADR 0008 requires them to stay identical.
This commit was merged in pull request #4.
This commit is contained in:
2026-07-11 21:03:40 -04:00
parent f82414a933
commit 590691fc96
13 changed files with 1151 additions and 69 deletions

40
src/comment.ts Normal file
View File

@@ -0,0 +1,40 @@
import type { Comment } from "gitea-js";
import { COMMENT_TRUNCATE_LIMIT, truncateBody } from "./body.js";
import type { FlagSpec } from "./flags.js";
import { relativeTime } from "./time.js";
/**
* The one comment-posting shape `issue comment` and `pr comment` share. ADR 0008
* requires both to emit the same `comment` block with the same schema, so the
* block is built in exactly one place; what the two commands genuinely differ on
* — how a missing target is reported, and what to suggest next — stays with them.
*/
export const COMMENT_FLAGS: FlagSpec = {
"--body": { takesValue: true },
"--body-file": { takesValue: true },
"--full": { takesValue: false },
};
export interface CommentItemOptions {
/** The issue or pull request commented on — not the comment's own id. */
number: number;
/** Echo the body untruncated, as `--full` asks. */
full: boolean;
host: string;
now: Date;
}
/** The `comment: { number, author, created, body }` block, body truncated at 800 chars. */
export function commentItem(
comment: Comment,
options: CommentItemOptions,
): Record<string, unknown> {
const body = comment.body ?? "";
return {
number: options.number,
author: comment.user?.login ?? "",
created: relativeTime(comment.created_at, options.now),
body: options.full ? body : truncateBody(body, COMMENT_TRUNCATE_LIMIT, options.host),
};
}