diff --git a/src/commands/issue/issue-pull-request.ts b/src/commands/issue/issue-pull-request.ts index ff83ff35..abeddcae 100644 --- a/src/commands/issue/issue-pull-request.ts +++ b/src/commands/issue/issue-pull-request.ts @@ -2,6 +2,7 @@ import { Command } from "@cliffy/command" import { fetchIssueDetails, getIssueIdentifier } from "../../utils/linear.ts" import { shouldShowSpinner } from "../../utils/hyperlink.ts" import { CliError, handleError, ValidationError } from "../../utils/errors.ts" +import { getOption } from "../../config.ts" export const pullRequestCommand = new Command() .name("pull-request") @@ -27,44 +28,55 @@ export const pullRequestCommand = new Command() "--head ", "The branch that contains commits for your pull request", ) + .option( + "-T, --template ", + "Optional template filename for the pull request body", + ) .arguments("[issueId:string]") - .action(async ({ base, draft, title: customTitle, web, head }, issueId) => { - try { - const resolvedId = await getIssueIdentifier(issueId) - if (!resolvedId) { - throw new ValidationError( - "Could not determine issue ID", - { suggestion: "Please provide an issue ID like 'ENG-123'." }, + .action( + async ( + { base, draft, title: customTitle, web, head, template }, + issueId, + ) => { + template = template ?? getOption("pr_template") + try { + const resolvedId = await getIssueIdentifier(issueId) + if (!resolvedId) { + throw new ValidationError( + "Could not determine issue ID", + { suggestion: "Please provide an issue ID like 'ENG-123'." }, + ) + } + const { title, url } = await fetchIssueDetails( + resolvedId, + shouldShowSpinner(), ) - } - const { title, url } = await fetchIssueDetails( - resolvedId, - shouldShowSpinner(), - ) - const process = new Deno.Command("gh", { - args: [ - "pr", - "create", - "--title", - `${resolvedId} ${customTitle ?? title}`, - "--body", - url, - ...(base ? ["--base", base] : []), - ...(head ? ["--head", head] : []), - ...(draft ? ["--draft"] : []), - ...(web ? ["--web"] : []), - ], - stdin: "inherit", - stdout: "inherit", - stderr: "inherit", - }) + const process = new Deno.Command("gh", { + args: [ + "pr", + "create", + "--title", + `${resolvedId} ${customTitle ?? title}`, + "--body", + url, + ...(base ? ["--base", base] : []), + ...(head ? ["--head", head] : []), + ...(draft ? ["--draft"] : []), + ...(web ? ["--web"] : []), + ...(template && template.length ? ["--template", template] : []), + ], + stdin: "inherit", + stdout: "inherit", + stderr: "inherit", + }) - const status = await process.spawn().status - if (!status.success) { - throw new CliError("Failed to create pull request") + const status = await process.spawn().status + if (!status.success) { + throw new CliError("Failed to create pull request") + } + } catch (error) { + handleError(error, "Failed to create pull request") } - } catch (error) { - handleError(error, "Failed to create pull request") - } - }) + }, + ) diff --git a/src/config.ts b/src/config.ts index 1abfaa1d..1afe3f42 100644 --- a/src/config.ts +++ b/src/config.ts @@ -156,6 +156,7 @@ const OptionSchemas = { hyperlink_format: v.optional(v.string()), attachment_dir: v.optional(v.string()), auto_download_attachments: v.optional(BooleanLike), + pr_template: v.optional(v.string()), } export type OptionName = keyof typeof OptionSchemas