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 3 forks source link

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

Open guibranco opened 3 weeks ago

guibranco commented 3 weeks 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 3 weeks 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.

gitauto-ai[bot] commented 3 weeks ago

Hey, I'm a bit lost here! Not sure which file I should be fixing. Could you give me a bit more to go on? Maybe add some details to the issue or drop a comment with some extra hints? Thanks!

Have feedback or need help? Feel free to email info@gitauto.ai.