Files
gitcommiteditor/Services/ICleanupExecutor.cs

125 lines
3.9 KiB
C#

using MarketAlly.GitCommitEditor.Models;
using MarketAlly.GitCommitEditor.Models.HistoryHealth;
namespace MarketAlly.GitCommitEditor.Services;
/// <summary>
/// Executes cleanup operations on git repositories.
/// </summary>
public interface ICleanupExecutor
{
/// <summary>
/// Executes a single cleanup operation.
/// </summary>
Task<CleanupExecutionResult> ExecuteAsync(
ManagedRepo repo,
CleanupOperation operation,
CleanupExecutionOptions? options = null,
IProgress<CleanupProgress>? progress = null,
CancellationToken ct = default);
/// <summary>
/// Executes multiple cleanup operations in sequence.
/// </summary>
Task<BatchCleanupResult> ExecuteBatchAsync(
ManagedRepo repo,
IEnumerable<CleanupOperation> operations,
CleanupExecutionOptions? options = null,
IProgress<CleanupProgress>? progress = null,
CancellationToken ct = default);
/// <summary>
/// Previews what a cleanup operation will do without executing it.
/// </summary>
Task<CleanupPreview> PreviewAsync(
ManagedRepo repo,
CleanupOperation operation,
CancellationToken ct = default);
/// <summary>
/// Creates a backup branch before cleanup operations.
/// </summary>
Task<string> CreateBackupBranchAsync(
ManagedRepo repo,
string? branchName = null,
CancellationToken ct = default);
}
/// <summary>
/// Options for cleanup execution.
/// </summary>
public sealed record CleanupExecutionOptions
{
/// <summary>
/// Create a backup branch before making changes.
/// </summary>
public bool CreateBackup { get; init; } = true;
/// <summary>
/// Custom backup branch name. Auto-generated if null.
/// </summary>
public string? BackupBranchName { get; init; }
/// <summary>
/// Allow operations on pushed commits (requires force push).
/// </summary>
public bool AllowPushedCommits { get; init; } = false;
/// <summary>
/// Automatically force push after rewriting history.
/// </summary>
public bool AutoForcePush { get; init; } = false;
/// <summary>
/// Use AI to generate improved commit messages.
/// </summary>
public bool UseAiForMessages { get; init; } = true;
}
/// <summary>
/// Result of executing a single cleanup operation.
/// </summary>
public sealed record CleanupExecutionResult
{
public required string OperationId { get; init; }
public required CleanupType Type { get; init; }
public bool Success { get; init; }
public string? ErrorMessage { get; init; }
public int CommitsModified { get; init; }
public int CommitsRemoved { get; init; }
public string? BackupBranch { get; init; }
public bool RequiresForcePush { get; init; }
public IReadOnlyList<string> ModifiedCommitHashes { get; init; } = [];
public IReadOnlyList<string> NewCommitHashes { get; init; } = [];
public TimeSpan Duration { get; init; }
}
/// <summary>
/// Result of executing multiple cleanup operations.
/// </summary>
public sealed class BatchCleanupResult
{
public int TotalOperations { get; init; }
public int Successful { get; init; }
public int Failed { get; init; }
public int Skipped { get; init; }
public string? BackupBranch { get; init; }
public bool RequiresForcePush { get; init; }
public IReadOnlyList<CleanupExecutionResult> Results { get; init; } = [];
public TimeSpan TotalDuration { get; init; }
public bool AllSucceeded => Failed == 0 && Skipped == 0;
}
/// <summary>
/// Progress information for cleanup operations.
/// </summary>
public sealed class CleanupProgress
{
public required string CurrentOperation { get; init; }
public int CurrentIndex { get; init; }
public int TotalOperations { get; init; }
public int PercentComplete { get; init; }
public string? CurrentCommit { get; init; }
}