guibranco / dotnet-aicommitmessage

🧠 🧰 This tool generates AI-powered commit messages via Git hooks, automating meaningful message suggestions from OpenAI and others to improve commit quality and efficiency.
https://guibranco.github.io/dotnet-aicommitmessage/
MIT License
1 stars 2 forks source link

[FEATURE] Preserve original message for merge conflict resolutions #113

Open guibranco opened 6 hours ago

guibranco commented 6 hours ago

Description
In the dotnet-aicommitmessage tool, which generates commit messages using the ChatGPT API (LLM models), implement a business rule to retain the original commit message when it follows the auto-generated format used during a merge conflict resolution. Currently, the tool replaces all commit messages, which can modify the intended context of merge conflict resolutions. Preserving these original messages will help maintain a clear version history.

Message Pattern
The pattern for auto-generated messages following a merge conflict resolution is as follows:

Merge branch '<source branch>' into <destination branch>
# Conflicts
# file1
# file2
# file3 
# fileN

Requirements

Acceptance Criteria

Sample pattern extraction

using System.Text.RegularExpressions;

public class CommitMessageValidator
{
    // Regular expression pattern for merge conflict resolution messages
    private static readonly Regex MergeConflictPattern = new Regex(
        @"^Merge branch '(.+)' into (.+)\n(# Conflicts\n# .+\n?)+$",
        RegexOptions.Multiline | RegexOptions.Compiled
    );

    /// <summary>
    /// Checks if the commit message is an auto-generated merge conflict resolution message.
    /// </summary>
    /// <param name="commitMessage">The commit message to check.</param>
    /// <returns>True if the message matches the merge conflict resolution pattern; otherwise, false.</returns>
    public static bool IsMergeConflictResolutionMessage(string commitMessage)
    {
        return MergeConflictPattern.IsMatch(commitMessage);
    }
}

Additional Context
This feature will help retain the context of conflict resolutions in commit history by preserving the original message format.

gitauto-ai[bot] commented 6 hours ago

Click the checkbox below to generate a PR!

@guibranco, You have 3 requests left in this cycle which refreshes on 2024-11-21 10:07:38+00:00. If you have any questions or concerns, please contact us at info@gitauto.ai.