UNPKG

@morodomi/ait3

Version:

AIT³ Development Platform - AI + Ticket + Test + Tool driven development methodology

58 lines (57 loc) 2.33 kB
import { ValidationError, TicketNotFoundError, TicketNotStartedError, TicketAlreadyCompletedError } from '../../common/errors.js'; import { STYLES } from '../../common/styles.js'; import { IDUtils } from '../../common/utils.js'; import { formatTicketLocation } from '../../common/utils/location-utils.js'; /** * Complete a ticket by moving it from 'doing' to 'done' status * Pure function that delegates to TicketService */ export async function completeTicket(args, services) { const { id } = args; const { ticketService } = services; // Validate ID format if (!id || !IDUtils.isValidTicketId(id)) { throw new ValidationError('Invalid ticket ID format. Use local format (0001) or GitHub format (#70, 70)'); } try { // Attempt to complete the ticket await ticketService.completeTicket(id); // Get ticket details for success message const ticket = await ticketService.getTicket(id); const ticketTitle = ticket?.title || 'Unknown'; // Generate formatted success output const messageParts = [ STYLES.success(`SUCCESS: Completed ticket #${id}`) + (ticket ? `: ${ticketTitle}` : ''), '', STYLES.muted(' Status updated: ') + STYLES.warning('doing') + STYLES.muted(' → ') + STYLES.success('done'), STYLES.muted(' Moved from doing → done') ]; // Add location information if (ticket) { const locationDisplay = formatTicketLocation(ticket, services.ticketService); messageParts.push(` Location: ${STYLES.info(locationDisplay)}`); } messageParts.push(''); return { success: true, message: messageParts.join('\n') }; } catch (error) { // Handle specific error types if (error instanceof TicketNotFoundError) { throw error; } if (error instanceof TicketNotStartedError) { throw error; } if (error instanceof TicketAlreadyCompletedError) { throw error; } if (error instanceof ValidationError) { throw error; } // Wrap other errors throw new Error(`Failed to complete ticket: ${error instanceof Error ? error.message : String(error)}`); } }