Skip to content

Commit

Permalink
unapplied-changes: display "no changes" instead of empty response
Browse files Browse the repository at this point in the history
The string "no changes" is displayed when the current deployment is not
stashed, or when the stashed deployment has the same definition as the
previous non-stashed deployment.
  • Loading branch information
brmzkw committed Oct 28, 2024
1 parent 2902f9c commit 9d5d448
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## v5.3.0 (unreleased)

*
* `koyeb service unapplied-changes <service_id>`: display "no changes" when there is no stashed deployment, or when the stashed deployment is the same as the current deployment.

## v5.2.0 (2024-10-24)

Expand Down
30 changes: 20 additions & 10 deletions pkg/koyeb/services_show_unapplied_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (h *ServiceHandler) ShowUnappliedChanges(ctx *CLIContext, cmd *cobra.Comman

// Last deployment is not stashed, render an empty diff
if res.Deployments[0].GetStatus() != koyeb.DEPLOYMENTSTATUS_STASHED {
// xx := NewShowDeploymentsDiff(jsondiff.Patch{})
// ctx.Renderer.Render(xx)
showUnappliedChangesReply := NewShowDeploymentsDiff(nil, nil)
ctx.Renderer.Render(showUnappliedChangesReply)
return nil
}
stashedDeployment = &res.Deployments[0]
Expand Down Expand Up @@ -116,6 +116,10 @@ func (ShowDeploymentsDiff) Title() string {
}

func (r *ShowDeploymentsDiff) MarshalBinary() ([]byte, error) {
if r.diff == nil {
return nil, nil
}

formatter := formatter.NewDeltaFormatter()
diffString, _ := formatter.Format(r.diff)
return []byte(diffString), nil
Expand All @@ -126,16 +130,22 @@ func (r *ShowDeploymentsDiff) Headers() []string {
}

func (r *ShowDeploymentsDiff) Fields() []map[string]string {
config := formatter.AsciiFormatterConfig{
ShowArrayIndex: true,
Coloring: true,
}
var diffString string

if r.diff == nil || len(r.diff.Deltas()) == 0 {
diffString = "No unapplied changes"
} else {
config := formatter.AsciiFormatterConfig{
ShowArrayIndex: true,
Coloring: true,
}

var aJson map[string]interface{}
_ = json.Unmarshal(r.lhs, &aJson)
var aJson map[string]interface{}
_ = json.Unmarshal(r.lhs, &aJson)

formatter := formatter.NewAsciiFormatter(aJson, config)
diffString, _ := formatter.Format(r.diff)
formatter := formatter.NewAsciiFormatter(aJson, config)
diffString, _ = formatter.Format(r.diff)
}

fields := map[string]string{
"diff": diffString,
Expand Down

0 comments on commit 9d5d448

Please sign in to comment.