refactor: improve merge commit detection and update error messages

## CHANGES

- Move merge patterns to package-level variables
- Update date parsing error message for clarity
- Simplify author email field comment
- Extract regex compilation from function scope
- Improve merge commit detection performance
- Clarify RFC3339 fallback error context
This commit is contained in:
Kayvan Sylvan
2025-07-21 18:37:31 -07:00
parent db5aaf9da6
commit 616f51748e
3 changed files with 10 additions and 12 deletions

View File

@@ -207,7 +207,7 @@ func (c *Cache) GetVersions() (map[string]*git.Version, error) {
if err != nil {
v.Date, err = time.Parse(time.RFC3339, dateStr.String)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing date '%s' with RFC3339 for version '%s': %v\n", dateStr.String, v.Name, err)
fmt.Fprintf(os.Stderr, "Error parsing date '%s' with both RFC3339Nano and RFC3339 for version '%s': %v\n", dateStr.String, v.Name, err)
}
}
}

View File

@@ -14,6 +14,14 @@ import (
"github.com/danielmiessler/fabric/cmd/generate_changelog/internal/github"
)
var mergePatterns = []*regexp.Regexp{
regexp.MustCompile(`^Merge pull request #\d+`), // "Merge pull request #123 from..."
regexp.MustCompile(`^Merge branch '.*' into .*`), // "Merge branch 'feature' into main"
regexp.MustCompile(`^Merge remote-tracking branch`), // "Merge remote-tracking branch..."
regexp.MustCompile(`^Merge '.*' into .*`), // "Merge 'feature' into main"
regexp.MustCompile(`^Merge .*`), // General "Merge ..." patterns
}
// isMergeCommit determines if a commit is a merge commit.
//
// This function uses two methods to detect merge commits:
@@ -30,16 +38,6 @@ func isMergeCommit(commit github.PRCommit) bool {
}
// Fallback method: Check commit message patterns
// Common merge commit message patterns
// Pre-compiled regular expressions for common merge commit message patterns
mergePatterns := []*regexp.Regexp{
regexp.MustCompile(`^Merge pull request #\d+`), // "Merge pull request #123 from..."
regexp.MustCompile(`^Merge branch '.*' into .*`), // "Merge branch 'feature' into main"
regexp.MustCompile(`^Merge remote-tracking branch`), // "Merge remote-tracking branch..."
regexp.MustCompile(`^Merge '.*' into .*`), // "Merge 'feature' into main"
regexp.MustCompile(`^Merge .*`), // General "Merge ..." patterns
}
for _, pattern := range mergePatterns {
if pattern.MatchString(commit.Message) {
return true

View File

@@ -26,7 +26,7 @@ type PRCommit struct {
SHA string
Message string
Author string
Email string // Email of the author from GitHub API, empty if not provided by the API (e.g., when the author has not made their email public)
Email string // Author email from GitHub API, empty if not public
Date time.Time // Timestamp field
Parents []string // Parent commits (for merge detection)
}