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 version bump patterns in commit messages #93

Closed guibranco closed 1 week ago

guibranco commented 3 weeks ago

Description:

The code should detect and preserve existing version bump patterns in the commit message. Currently, these commands may be stripped out, but they should remain intact in the final commit message.

For example, in the following commit message:

add something to some feature +semver: minor

The +semver: minor should be detected and kept at the end of the final commit message.

Accepted Patterns:

The following patterns should be detected and preserved in the commit message:

  1. Major Version Bump:

    +semver: breaking
    +semver: major
  2. Minor Version Bump:

    +semver: feature
    +semver: minor
  3. Patch Version Bump:

    +semver: fix
    +semver: patch
  4. No Version Bump:

    +semver: none
    +semver: skip

Expected Behavior:

The tool should detect the version bump command (if present) and ensure it is preserved at the end of the final commit message.


Example Code for Pattern Detection and Preservation:

using System;
using System.Text.RegularExpressions;

public class CommitMessageProcessor
{
    private static readonly string semverPattern = @"\+semver:\s?(breaking|major|feature|minor|fix|patch|none|skip)";

    public static string ProcessCommitMessage(string originalMessage)
    {
        // Detect and extract semver command
        var semverMatch = Regex.Match(originalMessage, semverPattern, RegexOptions.IgnoreCase);

        // If a semver command is found, remove it from the original message
        string cleanedMessage = Regex.Replace(originalMessage, semverPattern, "").Trim();

        // Append the semver command back to the cleaned message (if found)
        if (semverMatch.Success)
        {
            cleanedMessage += " " + semverMatch.Value;
        }

        return cleanedMessage;
    }

    public static void Main()
    {
        // Example commit message
        string commitMessage = "add something to some feature +semver: minor";

        // Process commit message
        string finalMessage = ProcessCommitMessage(commitMessage);

        // Output the final commit message
        Console.WriteLine(finalMessage);
    }
}

How It Works:

  1. The semverPattern matches any of the accepted version bump commands (+semver: breaking, +semver: feature, etc.).
  2. The regular expression extracts the command from the original commit message.
  3. The extracted command is appended back to the cleaned commit message to ensure it is preserved.

Notes:

This feature will ensure that valid version bump commands are always preserved in the final commit message, allowing seamless versioning integration.

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.