adding refactor ability
All checks were successful
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 39s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 12s

This commit is contained in:
2026-03-14 17:01:00 -03:00
parent 86870c22db
commit 3938d1a2b9

View File

@@ -121,18 +121,30 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
continue continue
} }
originalFile := file
// Remove first folder from file path // Remove first folder from file path
file = strings.Join(strings.Split(file, "/")[1:], "/") file = strings.Join(strings.Split(file, "/")[1:], "/")
// Get the specific diff for this file // Note: 'git diff' compares the beginning and end trees, so it has no native concept
cmdDiff := exec.Command("git", "diff", baseCommit, "HEAD", "--", file) // of ignoring intermediate commits. To skip the changes made in "refactor" commits
// without using loops, we use `git log -p` combined with `--invert-grep` to
// natively output the diffs of only the non-refactor commits for this file.
rangeStr := "HEAD"
if baseCommit != "4b825dc642cb6eb9a060e54bf8d69288fbee4904" {
rangeStr = baseCommit + "..HEAD"
}
cmdDiff := exec.Command("git", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile)
cmdDiff.Dir = s.repoDir cmdDiff.Dir = s.repoDir
diffOut, err := cmdDiff.Output() diffOut, err := cmdDiff.Output()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get diff for file %s: %w", file, err) return nil, fmt.Errorf("failed to get diff for file %s: %w", originalFile, err)
} }
mods[file] = string(diffOut) if len(diffOut) > 0 {
mods[file] = string(diffOut)
}
} }
return mods, nil return mods, nil