Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 48 additions & 36 deletions src/commands/issue/issue-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -27,44 +28,55 @@ export const pullRequestCommand = new Command()
"--head <branch:string>",
"The branch that contains commits for your pull request",
)
.option(
"-T, --template <template:string>",
"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")
}
})
},
)
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading