/** * @nahisaho/musubix-codegraph - PR Creator * * Main orchestrator for creating PRs from refactoring suggestions * * @packageDocumentation * @module @nahisaho/musubix-codegraph/pr * * @see REQ-CG-PR-001 - GitHub Authentication * @see REQ-CG-PR-002 - Auto Apply Refactoring * @see REQ-CG-PR-003 - Git Branch Creation * @see REQ-CG-PR-004 - Auto Commit * @see REQ-CG-PR-005 - GitHub PR Creation * @see DES-CG-PR-001 - Component Design * @see DES-CG-PR-005 - Sequence Diagram */ import { EventEmitter } from 'node:events'; import type { RefactoringSuggestion, PRCreateOptions, PRCreateResult, PRPreview, PRCreatorEvents } from './types.js'; /** * PRCreator state * @see DES-CG-v234-003 */ export type PRCreatorState = 'uninitialized' | 'offline' | 'full'; /** * PR Creator configuration */ export interface PRCreatorConfig { /** Repository root path */ repoPath: string; /** GitHub token (optional, will try env or gh CLI) */ githubToken?: string; /** Remote name (default: origin) */ remote?: string; /** Create backups before modifications */ createBackups?: boolean; } /** * PR Creator * * Orchestrates the entire PR creation workflow: * 1. Authenticate with GitHub * 2. Create a new branch * 3. Apply refactoring changes * 4. Commit changes * 5. Push to remote * 6. Create PR on GitHub * * @see DES-CG-PR-001 * @see DES-CG-PR-005 * @example * ```typescript * const creator = new PRCreator({ repoPath: '/path/to/repo' }); * await creator.initialize(); * * const result = await creator.create({ * suggestion: refactoringSuggestion, * baseBranch: 'main', * labels: ['refactoring', 'auto-generated'], * }); * * console.log(`PR created: ${result.pr?.url}`); * ``` */ export declare class PRCreator extends EventEmitter { private readonly config; private git; private github; private applier; private templateGenerator; private initialized; private originalBranch; private state; /** * Create a new PRCreator * @param config - Configuration options */ constructor(config: PRCreatorConfig); /** * Initialize for offline operations (preview only) * Does not require GitHub authentication * * @see REQ-CG-v234-001 * @see DES-CG-v234-001 */ initializeOffline(): Promise<{ success: boolean; error?: string; }>; /** * Initialize the PR creator with full GitHub authentication * Sets up Git operations and authenticates with GitHub */ initialize(): Promise<{ success: boolean; error?: string; }>; /** * Check if initialized */ isInitialized(): boolean; /** * Get current state * @see DES-CG-v234-003 */ getState(): PRCreatorState; /** * Generate PR preview without creating * Works in both offline and full modes * * @see REQ-CG-v234-001 * @see DES-CG-v234-001 */ previewSuggestion(suggestion: RefactoringSuggestion): PRPreview; /** * Create a PR from a refactoring suggestion * Requires full initialization (GitHub authentication) * * @see REQ-CG-PR-002, REQ-CG-PR-003, REQ-CG-PR-004, REQ-CG-PR-005 */ create(options: PRCreateOptions): Promise; /** * Preview PR creation without actually creating * @see REQ-CG-PR-007 */ preview(options: PRCreateOptions): Promise; /** * Validate a suggestion can be applied */ validate(suggestion: RefactoringSuggestion): { valid: boolean; reason?: string; }; /** * Dry run implementation */ private dryRun; /** * Ensure initialized before operations (legacy) * @deprecated Use ensureState() instead */ private ensureInitialized; /** * Ensure PRCreator is in one of the allowed states * @see DES-CG-v234-003 */ private ensureState; /** * Typed event emitter methods */ emit(event: K, data: PRCreatorEvents[K]): boolean; on(event: K, listener: (data: PRCreatorEvents[K]) => void): this; once(event: K, listener: (data: PRCreatorEvents[K]) => void): this; } /** * Create a PRCreator instance */ export declare function createPRCreator(repoPath: string, options?: Partial): PRCreator; /** * Quick PR creation helper * * One-shot function to create a PR from a suggestion. * * @example * ```typescript * const result = await createRefactoringPR( * '/path/to/repo', * suggestion, * { labels: ['refactoring'] } * ); * ``` */ export declare function createRefactoringPR(repoPath: string, suggestion: RefactoringSuggestion, options?: Partial): Promise; //# sourceMappingURL=pr-creator.d.ts.map