This commit is contained in:
Tiara Rodney 2026-03-15 03:02:41 +01:00
commit 932d4ad420
No known key found for this signature in database
GPG key ID: 5CD8EC1D46106723
46 changed files with 5800 additions and 0 deletions

View file

@ -0,0 +1,60 @@
import type { Argv, ArgumentsCamelCase } from "yargs"
import { CLICommand } from "../cli/CLICommand"
import { parseTodoFile, writeTodoFile } from "../file"
import { getCurrentBranch, branchExists, commitFileWithBody } from "../git"
import { validateStatusTransition } from "../issue"
export class StartCommand extends CLICommand {
readonly name = "start <id>"
readonly help = "Start work on an issue"
readonly description = "Set issue to in-progress (must be on develop)"
addArguments(yargs: Argv): Argv {
return yargs
.positional("id", { type: "number", demandOption: true })
.option("plan", {
type: "string",
demandOption: true,
description: "High-level description of planned approach",
})
}
async execute(args: ArgumentsCamelCase): Promise<number> {
const branch = getCurrentBranch()
if (branch !== "develop") {
console.error(`Must be on develop to start an issue (currently on ${branch})`)
return 1
}
const todo = await parseTodoFile()
const issue = todo.issues.find(i => i.id === args.id)
if (!issue) {
console.error(`Issue #${args.id} not found`)
return 1
}
const err = validateStatusTransition(issue.status, "in-progress")
if (err) {
console.error(err)
return 1
}
// Check that the issue branch doesn't already exist
const issueBranch = `${issue.type}/${issue.id}`
if (branchExists(issueBranch)) {
console.error(`Branch ${issueBranch} already exists`)
return 1
}
issue.status = "in-progress"
writeTodoFile(todo)
commitFileWithBody(
"TODO",
`todo(${issue.id}): in-progress`,
args.plan as string
)
console.log(`Issue #${issue.id} is now in-progress`)
console.log(`Create the issue branch: git checkout -b ${issueBranch}`)
return 0
}
}