Skip to content

Commit

Permalink
aider: feat: Add optional issue ID argument to issue commands
Browse files Browse the repository at this point in the history
  • Loading branch information
schpet committed Feb 4, 2025
1 parent 21dda02 commit 0770a69
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ async function getRepoDir(): Promise<string> {
return basename(fullPath);
}

async function getIssueId(): Promise<string | null> {
async function getIssueId(providedId?: string): Promise<string | null> {
if (providedId) {
return providedId.toUpperCase();
}
const branch = await getCurrentBranch();
const match = branch.match(/[a-zA-Z]{2,5}-[1-9][0-9]*/i);
return match ? match[0].toUpperCase() : null;
Expand Down Expand Up @@ -99,8 +102,8 @@ async function openTeamPage() {
await open(url, { app: { name: "Linear" } });
}

async function openIssuePage() {
const issueId = await getIssueId();
async function openIssuePage(providedId?: string) {
const issueId = await getIssueId(providedId);
if (!issueId) {
console.error(
"The current branch does not contain a valid linear issue id.",
Expand Down Expand Up @@ -175,16 +178,19 @@ const teamCommand = new Command()

const issueCommand = new Command()
.description("Manage Linear issues")
.action(openIssuePage)
.arguments("[issueId:string]")
.action((_, issueId) => openIssuePage(issueId))
.command("open", "Open the issue in Linear.app")
.alias("o")
.action(openIssuePage)
.arguments("[issueId:string]")
.action((_, issueId) => openIssuePage(issueId))
.command("print", "Print the issue details")
.alias("p")
.arguments("[issueId:string]")
.option("--no-color", "Disable colored output")
.action(async ({ color }) => {
const issueId = await getIssueId();
if (!issueId) {
.action(async ({ color }, issueId) => {
const resolvedId = await getIssueId(issueId);
if (!resolvedId) {
console.error(
"The current branch does not contain a valid linear issue id.",
);
Expand All @@ -193,7 +199,7 @@ const issueCommand = new Command()

const showSpinner = color && Deno.stdout.isTerminal();
const { title, description } = await fetchIssueDetails(
issueId,
resolvedId,
showSpinner,
);
const markdown = `# ${title}${description ? "\n\n" + description : ""}`;
Expand All @@ -204,10 +210,11 @@ const issueCommand = new Command()
}
})
.command("id", "Print the issue id in the current git branch")
.action(async () => {
const issueId = await getIssueId();
if (issueId) {
console.log(issueId);
.arguments("[issueId:string]")
.action(async (_, issueId) => {
const resolvedId = await getIssueId(issueId);
if (resolvedId) {
console.log(resolvedId);
} else {
console.error(
"The current branch does not contain a valid linear issue id.",
Expand All @@ -216,27 +223,29 @@ const issueCommand = new Command()
}
})
.command("title", "Print the issue title")
.action(async () => {
const issueId = await getIssueId();
if (!issueId) {
.arguments("[issueId:string]")
.action(async (_, issueId) => {
const resolvedId = await getIssueId(issueId);
if (!resolvedId) {
console.error(
"The current branch does not contain a valid linear issue id.",
);
Deno.exit(1);
}
const { title } = await fetchIssueDetails(issueId, false);
const { title } = await fetchIssueDetails(resolvedId, false);
console.log(title);
})
.command("url", "Print the issue URL")
.action(async () => {
const issueId = await getIssueId();
if (!issueId) {
.arguments("[issueId:string]")
.action(async (_, issueId) => {
const resolvedId = await getIssueId(issueId);
if (!resolvedId) {
console.error(
"The current branch does not contain a valid linear issue id.",
);
Deno.exit(1);
}
const { url } = await fetchIssueDetails(issueId, false);
const { url } = await fetchIssueDetails(resolvedId, false);
console.log(url);
})
.command("pull-request", "Create a GitHub pull request with issue details")
Expand All @@ -249,16 +258,17 @@ const issueCommand = new Command()
"--draft",
"Create the pull request as a draft",
)
.action(async ({ base, draft }) => {
const issueId = await getIssueId();
if (!issueId) {
.arguments("[issueId:string]")
.action(async ({ base, draft }, issueId) => {
const resolvedId = await getIssueId(issueId);
if (!resolvedId) {
console.error(
"The current branch does not contain a valid linear issue id.",
);
Deno.exit(1);
}
const { title, url } = await fetchIssueDetails(
issueId,
resolvedId,
Deno.stdout.isTerminal(),
);

Expand All @@ -267,7 +277,7 @@ const issueCommand = new Command()
"pr",
"create",
"--title",
`${issueId} ${title}`,
`${resolvedId} ${title}`,
"--body",
url,
...(base ? ["--base", base] : []),
Expand Down

0 comments on commit 0770a69

Please sign in to comment.