Files
autogits/common/diff_parser.go
Antonello Tartamo 2053454ab9 added some fixes
2025-11-26 14:12:44 +01:00

35 lines
1.1 KiB
Go

package common
import (
"path"
"regexp"
"strings"
)
// ParseSubprojectChangesFromDiff parses a diff string and returns a slice of package names that have changed.
// It identifies subproject changes by looking for "Subproject commit" lines within diff chunks.
func ParseSubprojectChangesFromDiff(diff string) []string {
var changedPackages []string
// This regex finds diff chunks for subprojects.
// It looks for a `diff --git` line, followed by lines indicating a subproject commit change.
re := regexp.MustCompile(`diff --git a\/(.+) b\/(.+)\n`)
matches := re.FindAllStringSubmatch(diff, -1)
for _, match := range matches {
if len(match) > 1 {
// The package path is in the first capturing group.
// We use path.Base to get just the package name from the path (e.g., "rpms/iptraf-ng" -> "iptraf-ng").
pkgPath := strings.TrimSpace(match[1])
basePath := path.Base(pkgPath)
// TODO: parse _manifest files to get real package names
if basePath != ".gitmodules" && basePath != "_config" && basePath != "" {
changedPackages = append(changedPackages, basePath)
}
}
}
return changedPackages
}