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] Implement JIRA Ticket Number Extraction from Branch Name #34

Closed guibranco closed 1 month ago

guibranco commented 1 month ago

Description:

We need to implement a method to extract JIRA ticket numbers from Git branch names. The JIRA ticket number follows the format PROJECTKEY-1234 (case-insensitive) and may or may not contain a hyphen between the project key and the number. The implementation should handle various branch name formats and ensure consistency in the output.

Acceptance Criteria:

  1. Case Insensitivity: The extraction should work regardless of whether the project key is upper, lower, or mixed case.
  2. Optional Hyphen: The project key and ticket number may or may not have a hyphen between them (e.g., XPTO1234 or XPTO-1234).
  3. Branch Name Formats: The extraction should work for branch names with or without prefixes (e.g., feature/, bugfix/, etc.), and should correctly handle branch names with double hyphens or special characters.
  4. Consistent Output: The extracted JIRA ticket should always be returned in uppercase, regardless of how it appears in the branch name. a

Branch Name Examples:

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

Proposed Solution:

  1. Implement a regular expression pattern to match the JIRA ticket number format:
    • (?i)([A-Z]+)-?(\d+)
    • This pattern should be case-insensitive and allow an optional hyphen.
  2. Create a method to extract the JIRA ticket number from the branch name and convert the result to uppercase.
  3. Write unit tests to verify that the method works with various branch name formats, including those mentioned in the examples.

Technical Details:

static string ExtractJiraTicket(string branchName)
{
    // Regular expression to match the JIRA ticket pattern (with or without a hyphen)
    string pattern = @"(?i)([A-Z]+)-?(\d+)";

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

    if (!match.Success)
    {
        return string.Empty;
    }

    // Construct the JIRA ticket number, ensuring the hyphen is present
    string projectKey = match.Groups[1].Value.ToUpper(); // Extract the project key in uppercase
    string issueNumber = match.Groups[2].Value; // Extract the issue number
    // Combine the project key and issue number with a hyphen
    string jiraTicket = $"{projectKey}-{issueNumber}";
    return jiraTicket;
}
gitauto-ai[bot] commented 1 month 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.

gitauto-ai[bot] commented 1 month ago

@guibranco Pull request completed! Check it out here https://github.com/guibranco/dotnet-aicommitmessage/pull/64 πŸš€ Should you have any questions or wish to change settings or limits, please feel free to contact info@gitauto.ai or invite us to Slack Connect.