@entro314labs/ai-changelog-generator
Version:
AI-powered changelog generator with MCP server support - works with most providers, online and local models
398 lines (397 loc) • 12.5 kB
TypeScript
/**
* Consolidated Utility Functions
*
* Provides comprehensive utility functions for AI changelog generation:
* - Data manipulation and conversion utilities
* - Format and presentation utilities
* - File analysis and categorization
* - Text processing and analysis
* - Commit analysis and changelog generation
*
* For advanced JSON operations with error detection, use JsonUtils from './json-utils.js'
* For specialized error handling, use error classes from './error-classes.js'
*/
import type { TemplateData } from '../../../types/index.js';
import { AbstractMethodError, AIChangelogError, ProviderError } from './error-classes.js';
export { AbstractMethodError, AIChangelogError, ProviderError };
/**
* Convert Sets to Arrays for JSON serialization
*/
export declare function convertSetsToArrays(obj: any): any;
/**
* Enhanced conventional commit parsing
* Based on git-conventional-commits patterns with breaking change detection
*/
export declare function extractCommitScope(message: any): {
type: any;
scope: any;
description: any;
breaking: boolean;
isConventional: boolean;
};
/**
* Parse conventional commit message with full body analysis
*/
export declare function parseConventionalCommit(subject: any, body?: string): {
type: any;
scope: any;
description: any;
breaking: boolean;
isConventional: boolean;
breakingChanges: any[];
issueReferences: any[];
closesReferences: any[];
body: string;
revert: any;
};
/**
* Generate markdown link for commit hash
*/
export declare function markdownCommitLink(commitHash: any, commitUrl: any, shortHash?: boolean): any;
/**
* Generate markdown link for commit range
*/
export declare function markdownCommitRangeLink(fromCommit: any, toCommit: any, commitRangeUrl: any): string;
/**
* Generate markdown link for issue reference
*/
export declare function markdownIssueLink(issueId: any, issueUrl: any): any;
/**
* Process issue references in text and convert to markdown links
*/
export declare function processIssueReferences(text: any, issueUrl: any, issueRegex: any): any;
/**
* Deep merge objects
*/
export declare function deepMerge(target: any, source: any): any;
/**
* Format duration in human-readable format
*/
export declare function formatDuration(ms: any): string;
/**
* Interactive configuration prompt (simplified)
*/
export declare function promptForConfig(message?: string, defaultValue?: string): Promise<string>;
/**
* Get health status color
*/
export declare function getHealthColor(status: any): any;
/**
* Format file size
*/
export declare function formatFileSize(bytes: any): string;
/**
* Format percentage
*/
export declare function formatPercentage(value: any, total: any): string;
/**
* Categorize file by path and extension
*/
export declare function categorizeFile(filePath: any): "assets" | "build" | "configuration" | "documentation" | "frontend" | "other" | "source" | "tests";
/**
* Detect programming language from file extension
*/
export declare function detectLanguage(filePath: any): string;
/**
* Assess file importance based on path and type
*/
export declare function assessFileImportance(filePath: any, status: any): "critical" | "high" | "low" | "medium";
/**
* Assess overall complexity of changes
*/
export declare function assessOverallComplexity(diffContent: any, fileCount: any): string;
/**
* Assess risk level of changes
*/
export declare function assessRisk(diffContent: any, fileCount: any, commitMessage: any): string;
/**
* Check if changes are breaking
*/
export declare function isBreakingChange(commitMessage: any, diffContent: any): boolean;
/**
* Assess business relevance of changes
*/
export declare function assessBusinessRelevance(commitMessage: any, filePaths: any): "high" | "low" | "medium";
/**
* Safe JSON parse with fallback
*/
export declare function safeJsonParse(jsonString: any, fallback?: any): any;
/**
* Safe JSON stringify with formatting
*/
export declare function safeJsonStringify(obj: any, indent?: number): string;
/**
* Sleep utility for rate limiting
*/
export declare function sleep(ms: any): Promise<unknown>;
/**
* Retry utility with exponential backoff
*/
export declare function retry(fn: any, maxRetries?: number, baseDelay?: number): Promise<any>;
/**
* Debounce utility
*/
export declare function debounce(func: any, wait: any): (...args: any[]) => void;
/**
* Throttle utility
*/
export declare function throttle(func: any, limit: any): (this: unknown, ...args: any[]) => void;
/**
* Analyze semantic changes in code diffs
*/
export declare function analyzeSemanticChanges(diff: any, filePath: any): any;
/**
* Analyze functional impact of code changes
*/
export declare function analyzeFunctionalImpact(diff: any, filePath: any, status: any): any;
/**
* Generate analysis summary from semantic and functional analysis
*/
export declare function generateAnalysisSummary(semanticAnalysis: any, functionalImpact: any): {
primaryChanges: string[];
impactLevel: string;
technicalScope: string;
businessRelevance: string;
frameworks: string[];
patterns: string[];
recommendations: string[];
riskFactors: string[];
};
/**
* Perform semantic analysis on files and commit message
*/
export declare function performSemanticAnalysis(files: any, subject: any, body: any): any;
/**
* Build enhanced prompt for AI analysis
*/
export declare function buildEnhancedPrompt(commitAnalysis: any, analysisMode?: string): string;
/**
* Validate and correct AI categorization and impact assessment based on commit characteristics
*/
export declare function validateCommitCategory(category: any, commitAnalysis: any): any;
/**
* Validate and correct impact assessment based on actual change magnitude
*/
export declare function validateImpactAssessment(impact: any, commitAnalysis: any): any;
/**
* Parse AI response content
*/
export declare function parseAIResponse(content: any, originalCommit?: Record<string, any>): {
summary: any;
impact: any;
category: any;
description: any;
technicalDetails: any;
businessValue: any;
riskFactors: any;
recommendations: any;
breakingChanges: boolean;
migrationRequired: boolean;
};
/**
* Process working directory changes for changelog generation
*/
/**
* Get raw working directory changes from git status
*
* Note: This is a lightweight utility function that shells out to git directly
* for simple status checks. For comprehensive git operations, services should
* use GitService/GitManager, but this utility is kept for:
* - Performance (avoids service initialization overhead)
* - Simplicity (standalone function for basic status checks)
*
* @returns {Array} Array of change objects with status and filePath
*/
export declare function getWorkingDirectoryChanges(cwd?: undefined): {
status: string;
filePath: string;
path: string;
diff: string;
additions: number;
deletions: number;
}[];
/**
* Get raw staged changes from git index.
*
* Uses the staged diff instead of the working tree so commit-message generation
* reflects the actual commit payload, including partially staged files.
*
* @returns {Array} Array of change objects with status and filePath
*/
export declare function getStagedChanges(cwd?: undefined): {
status: string;
rawStatus: string;
filePath: string;
path: string;
previousPath: string | undefined;
diff: string;
additions: number;
deletions: number;
}[];
export declare function processWorkingDirectoryChanges(workingDirChanges: any, _gitManager?: any): never[] | {
categorizedChanges: Record<"added" | "deleted" | "modified" | "renamed" | "unknown", {
filePath: any;
status: any;
category: string;
language: any;
importance: string;
diff: any;
additions: any;
deletions: any;
}[]>;
summary: string;
totalFiles: number;
complexity: string;
};
/**
* Summarize file changes for changelog
*/
export declare function summarizeFileChanges(changes: any): {
summary: string;
categories: {};
stats: {
added: number;
modified: number;
deleted: number;
renamed: number;
};
languages: {};
totalFiles?: undefined;
} | {
summary: string;
categories: Record<string, any>;
stats: {
added: number;
modified: number;
deleted: number;
renamed: number;
};
totalFiles: any;
languages: any[];
};
/**
* Build commit changelog from analyzed commits
*/
export declare function buildCommitChangelog(analyzedCommits: any, releaseInsights: any, version: any, options?: Record<string, any>): string;
/**
* Handle unified output for analysis commands
*/
export declare function handleUnifiedOutput(data: any, config: any): any;
/**
* Run interactive mode with full menu system
*/
export declare function runInteractiveMode(): Promise<{
action: string | symbol;
timestamp: string;
}>;
/**
* Analyze changes for commit message with detailed analysis
*/
export declare function analyzeChangesForCommitMessage(changes: any, includeScope?: boolean): {
summary: string;
scope: null;
changes: number;
recommendations: string[];
type: string;
primaryCategory?: undefined;
categories?: undefined;
details?: undefined;
} | {
summary: string;
scope: string | null;
changes: number;
type: any;
primaryCategory: string;
categories: string[];
recommendations: any[];
details: {
added: number;
modified: number;
deleted: number;
hasTests: boolean;
hasDocs: boolean;
hasConfig: boolean;
hasSource: boolean;
};
};
/**
* Select specific commits with interactive interface
*/
export declare function selectSpecificCommits(maxCommits?: number): Promise<string[]>;
/**
* Assess change complexity based on diff output
*/
export declare function assessChangeComplexity(diff: any): {
score: number;
additions?: undefined;
deletions?: undefined;
total?: undefined;
level?: undefined;
} | {
score: number;
additions: any;
deletions: any;
total: any;
level: string;
};
/**
* Get current git branch name
*/
export declare function getCurrentBranch(cwd?: string): string | null;
/**
* Extract branch context and intelligence from branch name
* Based on better-commits patterns: type/ticket-description, feat/ABC-123-add-feature
*/
export declare function analyzeBranchIntelligence(branchName?: any, cwd?: any): {
branch: null;
type: null;
ticket: null;
description: null;
confidence: number;
patterns: never[];
} | {
branch: string;
type: string | null;
ticket: string | null;
description: string | null;
confidence: number;
patterns: string[];
};
/**
* Generate enhanced commit message context from branch intelligence
*/
export declare function generateCommitContextFromBranch(branchAnalysis: any, _changes?: any[]): string;
/**
* Get suggested commit type based on branch analysis and file changes
*/
export declare function getSuggestedCommitType(branchAnalysis: any, changes?: any[]): {
type: any;
source: string;
confidence: any;
};
/**
* Format changelog content for a target output format.
*
* - `markdown` returns the content unchanged.
* - `json` returns a pretty-printed JSON document wrapping the markdown content
* together with version/timestamp metadata.
* - `html` returns a valid, self-contained HTML document.
*
* @param content Markdown changelog content.
* @param format Target format: "markdown" | "json" | "html".
* @param meta Optional metadata (version, generatedAt) used by the JSON format.
*/
export declare function formatChangelogOutput(content: string, format?: string, meta?: Record<string, any>): string;
/**
* Resolve a human-readable section heading for a commit category. Mirrors the
* category naming used across the changelog templates.
*/
export declare function getChangelogCategoryName(category: string): string;
/**
* Render a changelog from structured {@link TemplateData} using one of the
* built-in templates.
*
* @param templateType One of "standard" | "keep-a-changelog" | "simple" | "semantic" | "github".
* @param data Structured changelog data (title, version, grouped changes, ...).
*/
export declare function renderChangelogTemplate(templateType: string, data: TemplateData): string;