(code1, code2 string, fromVersion, toVersion int)
| 723 | } |
| 724 | |
| 725 | func printColorDiff(code1, code2 string, fromVersion, toVersion int) { |
| 726 | diff := difflib.UnifiedDiff{ |
| 727 | A: difflib.SplitLines(code1), |
| 728 | B: difflib.SplitLines(code2), |
| 729 | FromFile: fmt.Sprintf("v%d", fromVersion), |
| 730 | ToFile: fmt.Sprintf("v%d", toVersion), |
| 731 | Context: 3, |
| 732 | } |
| 733 | text, _ := difflib.GetUnifiedDiffString(diff) |
| 734 | |
| 735 | if text == "" { |
| 736 | fmt.Printf("No differences found between v%d and v%d - the code is identical\n", fromVersion, toVersion) |
| 737 | return |
| 738 | } |
| 739 | |
| 740 | fmt.Printf("Comparing v%d → v%d:\n\n", fromVersion, toVersion) |
| 741 | |
| 742 | for _, line := range difflib.SplitLines(text) { |
| 743 | switch { |
| 744 | case len(line) > 0 && line[0] == '+': |
| 745 | fmt.Print(ansi.Green(line)) // Green for additions. |
| 746 | case len(line) > 0 && line[0] == '-': |
| 747 | fmt.Print(ansi.Red(line)) // Red for deletions. |
| 748 | case len(line) > 0 && line[0] == '@': |
| 749 | fmt.Print(ansi.Cyan(line)) // Cyan for hunk headers. |
| 750 | default: |
| 751 | fmt.Println(line) // Default color. |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | func pickTwoVersions(versions []*management.ActionVersion) (int, int, error) { |
| 757 | if len(versions) < 2 { |
no test coverage detected