feat: add pr create and comment (task 0010)
`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:
19
src/git.ts
19
src/git.ts
@@ -43,6 +43,25 @@ export function parseRemoteUrl(url: string): RemoteRepo | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The branch currently checked out, or null when git cannot name one — it is
|
||||
* absent, this is not a repository, or HEAD is detached. Every null case is
|
||||
* repaired the same way, by the caller naming the branch explicitly, so they
|
||||
* are not distinguished here.
|
||||
*/
|
||||
export async function currentBranch(deps: CliDeps): Promise<string | null> {
|
||||
const result = await runSubprocess("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
||||
cwd: deps.cwd,
|
||||
env: deps.env,
|
||||
});
|
||||
if (result.enoent || result.code !== 0) {
|
||||
return null;
|
||||
}
|
||||
const branch = result.stdout.trim();
|
||||
// A detached HEAD abbreviates to the literal "HEAD", which is no branch.
|
||||
return branch && branch !== "HEAD" ? branch : null;
|
||||
}
|
||||
|
||||
export async function detectRemote(deps: CliDeps): Promise<RemoteRepo | null> {
|
||||
const result = await runSubprocess("git", ["remote", "get-url", "origin"], {
|
||||
cwd: deps.cwd,
|
||||
|
||||
Reference in New Issue
Block a user