UNPKG

@fromsvenwithlove/devops-issues-cli

Version:

AI-powered CLI tool and library for Azure DevOps work item management with Claude agents

78 lines (63 loc) 2.83 kB
import chalk from 'chalk'; import { getConfig } from '../config/index.js'; import { AzureDevOpsClient } from '../api/azure-client.js'; import { getChildWorkItemType, canHaveChildren } from '../utils/work-item-types.js'; import { runCreateWizard } from '../interactive/create-wizard.js'; export default async function createCommand(parentId, title, options = {}) { try { // If no arguments provided, launch interactive wizard if (!parentId && !title) { return await runCreateWizard(options); } // Validate inputs for direct mode if (!parentId) { console.error(chalk.red('Error: Parent ID is required')); console.log(chalk.dim('Usage: devops-issues create <parentId> <title>')); console.log(chalk.dim(' or: devops-issues create (for interactive mode)')); process.exit(1); } if (!title) { console.error(chalk.red('Error: Title is required')); console.log(chalk.dim('Usage: devops-issues create <parentId> <title>')); console.log(chalk.dim(' or: devops-issues create (for interactive mode)')); process.exit(1); } // Get configuration const config = getConfig(); // Create and connect client const client = new AzureDevOpsClient(config); await client.connect(); console.log(chalk.blue(`Fetching parent work item #${parentId}...`)); // Get parent work item to determine child type const parent = await client.getWorkItem(parentId); console.log(chalk.dim(`Parent: ${parent.type} #${parent.id} - ${parent.title}`)); // Validate that parent can have children if (!canHaveChildren(parent.type)) { console.error(chalk.red(`Error: Work item type "${parent.type}" cannot have child items`)); console.log(chalk.dim('Supported parent types: Epic, Feature, User Story, Task, Bug')); process.exit(1); } // Determine child work item type const childType = getChildWorkItemType(parent.type); console.log(chalk.dim(`Creating ${childType} under ${parent.type} #${parentId}`)); // Create the work item const newWorkItem = await client.createWorkItem(parentId, title, childType); // Display success message console.log(''); console.log(chalk.green('✅ Work item created successfully!')); console.log(''); console.log(chalk.bold('Details:')); console.log(` ID: ${chalk.cyan('#' + newWorkItem.id)}`); console.log(` Title: ${newWorkItem.title}`); console.log(` Type: ${newWorkItem.type}`); console.log(` State: ${newWorkItem.state}`); console.log(` Parent: #${parentId} (${parent.title})`); if (newWorkItem.url) { console.log(` URL: ${chalk.dim(newWorkItem.url)}`); } console.log(''); } catch (error) { console.error(chalk.red('Error:'), error.message); process.exit(1); } }