Skip to content

Commit

Permalink
Use unified diff util (grafana#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes authored Feb 26, 2021
1 parent 7a96373 commit aa89a90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mitchellh/gox v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.3.3
github.com/pmezard/go-difflib v1.0.0
github.com/rivo/tview v0.0.0-20200818120338-53d50e499bf9
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20200422194213-44a606286825
Expand Down
11 changes: 9 additions & 2 deletions pkg/grafana/dashboard-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"

"github.com/grafana/grizzly/pkg/grizzly"
"github.com/kylelemons/godebug/diff"
"github.com/mitchellh/mapstructure"
"github.com/pmezard/go-difflib/difflib"
)

/*
Expand Down Expand Up @@ -152,7 +152,14 @@ func (h *DashboardHandler) Diff(notifier grizzly.Notifier, resources grizzly.Res
if local == remoteRepresentation {
notifier.NoChanges(resource)
} else {
difference := diff.Diff(remoteRepresentation, local)
diff := difflib.UnifiedDiff{
A: difflib.SplitLines(remoteRepresentation),
B: difflib.SplitLines(local),
FromFile: "Remote",
ToFile: "Local",
Context: 3,
}
difference, _ := difflib.GetUnifiedDiffString(diff)
notifier.HasChanges(resource, difference)
}
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/grizzly/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/google/go-jsonnet"
"github.com/grafana/grizzly/pkg/term"
"github.com/kylelemons/godebug/diff"
"github.com/pmezard/go-difflib/difflib"
"golang.org/x/crypto/ssh/terminal"
"gopkg.in/fsnotify.v1"
)
Expand Down Expand Up @@ -196,7 +196,14 @@ func Diff(config Config, resources Resources) error {
if local == remoteRepresentation {
config.Notifier.NoChanges(resource)
} else {
difference := diff.Diff(remoteRepresentation, local)
diff := difflib.UnifiedDiff{
A: difflib.SplitLines(remoteRepresentation),
B: difflib.SplitLines(local),
FromFile: "Remote",
ToFile: "Local",
Context: 3,
}
difference, _ := difflib.GetUnifiedDiffString(diff)
config.Notifier.HasChanges(resource, difference)
}
}
Expand Down

0 comments on commit aa89a90

Please sign in to comment.