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

[FEATURE] Implement GitHub Issue Number Extraction from Branch Name #35

Open guibranco opened 1 day ago

guibranco commented 1 day ago

Description:

We need to implement a method that extracts the GitHub issue number from branch names. GitHub issue numbers are numerical and may or may not be prefixed with the word issue. The implementation should handle branch names that use different formats and consistently return the issue number, if present.

Acceptance Criteria:

  1. Prefix Handling: The extraction should work for branches that either:
    • Include the word issue before the issue number (e.g., feature/issue123-fix-bug).
    • Contain just the issue number without any prefix (e.g., bugfix/123-fix-crash).
  2. Case Insensitivity: The method should handle issue in upper, lower, or mixed case (e.g., ISSUE, Issue, etc.).
  3. Branch Name Variations: It should work for different branch naming conventions (e.g., feature/, bugfix/, hotfix/, etc.).
  4. Correct Extraction: The extracted issue number should always be numeric and returned as a string.

Branch Name Examples:

The feature should correctly extract the issue number from the following branch names:

Proposed Solution:

  1. Implement a method using regular expressions to capture the GitHub issue number from a branch name.
    • The regular expression should match:
      • Numerical issue numbers.
      • Optional issue prefix in any case (e.g., issue, ISSUE, etc.).
  2. Return the issue number as a string.
  3. Write unit tests to ensure the method works with different branch naming conventions and formats.

Technical Details:

static string ExtractIssueNumber(string branchName)
    {
        // Regular expression to capture GitHub issue number (just digits)
        string pattern = @"(?i)issue?-?(\d+)";

        // Extracting the issue number
        Match match = Regex.Match(branchName, pattern);

        if (match.Success)
        {
            // Extract the issue number (Group 1)
            string issueNumber = match.Groups[1].Value;
            return issueNumber;
        }
        else
        {
            return "No issue number found.";
        }
    }

gitauto-ai[bot] commented 1 day ago

Hello @guibranco, you have reached your request limit of 5, your cycle will refresh on 2024-09-21 10:07:38+00:00. Consider subscribing if you want more requests. If you have any questions or concerns, please contact us at info@gitauto.ai.