From 31b7bd3079d34eea318cfc18b125677167ddd241 Mon Sep 17 00:00:00 2001 From: Julien Castets Date: Mon, 28 Oct 2024 12:27:01 +0100 Subject: [PATCH] unapplied-changes: display "no changes" instead of empty response 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. --- CHANGES.md | 3 +- pkg/koyeb/services_show_unapplied_changes.go | 30 +++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9ca8d7c..115c09e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ ## v5.3.0 (unreleased) -* … +* `koyeb service unapplied-changes `: display "no changes" when there is no stashed deployment, or when the stashed deployment is the same as the current deployment. + - https://github.com/koyeb/koyeb-cli/pull/259 ## v5.2.0 (2024-10-24) diff --git a/pkg/koyeb/services_show_unapplied_changes.go b/pkg/koyeb/services_show_unapplied_changes.go index b15e83a..44b544b 100644 --- a/pkg/koyeb/services_show_unapplied_changes.go +++ b/pkg/koyeb/services_show_unapplied_changes.go @@ -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] @@ -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 @@ -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,