90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using MarketAlly.GitCommitEditor.Resources;
|
|
|
|
namespace MarketAlly.GitCommitEditor.Options;
|
|
|
|
public sealed class GitImproverOptions : IValidatableObject
|
|
{
|
|
/// <summary>
|
|
/// Root directory to scan for git repositories
|
|
/// </summary>
|
|
public string WorkspaceRoot { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Path to persist state between sessions
|
|
/// </summary>
|
|
public string StateFilePath { get; set; } = "git-improver-state.json";
|
|
|
|
/// <summary>
|
|
/// Rules for analyzing commit message quality
|
|
/// </summary>
|
|
public CommitMessageRules Rules { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// AI configuration for generating suggestions
|
|
/// </summary>
|
|
public AiOptions Ai { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Maximum number of commits to analyze per repo
|
|
/// </summary>
|
|
public int MaxCommitsPerRepo { get; set; } = 100;
|
|
|
|
/// <summary>
|
|
/// Only analyze commits newer than this date
|
|
/// </summary>
|
|
public DateTimeOffset? AnalyzeSince { get; set; }
|
|
|
|
/// <summary>
|
|
/// Skip commits by these authors (useful for excluding bots)
|
|
/// </summary>
|
|
public string[] ExcludedAuthors { get; set; } = [];
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(WorkspaceRoot))
|
|
{
|
|
yield return new ValidationResult(
|
|
Str.Validation_WorkspaceRequired,
|
|
[nameof(WorkspaceRoot)]);
|
|
}
|
|
else if (!Directory.Exists(WorkspaceRoot))
|
|
{
|
|
yield return new ValidationResult(
|
|
Str.Validation_WorkspaceNotFound(WorkspaceRoot),
|
|
[nameof(WorkspaceRoot)]);
|
|
}
|
|
|
|
if (MaxCommitsPerRepo <= 0)
|
|
{
|
|
yield return new ValidationResult(
|
|
Str.Validation_MaxCommitsPositive,
|
|
[nameof(MaxCommitsPerRepo)]);
|
|
}
|
|
|
|
if (Rules == null)
|
|
{
|
|
yield return new ValidationResult(
|
|
Str.Validation_RulesNull,
|
|
[nameof(Rules)]);
|
|
}
|
|
|
|
if (Ai == null)
|
|
{
|
|
yield return new ValidationResult(
|
|
Str.Validation_AiOptionsNull,
|
|
[nameof(Ai)]);
|
|
}
|
|
}
|
|
|
|
public void ValidateAndThrow()
|
|
{
|
|
var results = Validate(new ValidationContext(this)).ToList();
|
|
if (results.Count > 0)
|
|
{
|
|
var messages = string.Join("; ", results.Select(r => r.ErrorMessage));
|
|
throw new ValidationException(Str.Validation_InvalidOptions(messages));
|
|
}
|
|
}
|
|
}
|