From 0285c4d72792236dcbdd0d1b529365587eb58fc1 Mon Sep 17 00:00:00 2001 From: ZackJagger Date: Wed, 25 Oct 2023 17:40:12 +0100 Subject: [PATCH 1/3] fix: handle null get current preview --- pkg/cmd/get/get.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cmd/get/get.go b/pkg/cmd/get/get.go index 0c3471d..de460b3 100644 --- a/pkg/cmd/get/get.go +++ b/pkg/cmd/get/get.go @@ -3,6 +3,7 @@ package get import ( "context" "fmt" + "github.com/jenkins-x/jx-logging/v3/pkg/log" "os" "time" @@ -140,6 +141,11 @@ func (o *Options) CurrentPreviewURL() error { } } + if currentPreview == nil { + log.Logger().Infof("No preview found for PR %v", o.Number) + return nil + } + t := table.CreateTable(os.Stdout) t.AddRow("PULL REQUEST", "NAMESPACE", "APPLICATION") t.AddRow(currentPreview.Spec.PullRequest.URL, From 92d143380a7adb0a27b5e6a099da4704897009ab Mon Sep 17 00:00:00 2001 From: ZackJagger Date: Wed, 25 Oct 2023 17:40:31 +0100 Subject: [PATCH 2/3] fix: wait for preview url to be populated --- pkg/cmd/get/get.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/get/get.go b/pkg/cmd/get/get.go index de460b3..402a3f0 100644 --- a/pkg/cmd/get/get.go +++ b/pkg/cmd/get/get.go @@ -194,7 +194,7 @@ func (o *Options) listPreviews() (*v1alpha1.PreviewList, error) { } func (o *Options) waitForCommit() (*v1alpha1.Preview, error) { - fmt.Printf("Waiting for preview with commit: %s\n", o.LatestCommit) + log.Logger().Infof("Waiting for preview with commit: %s\n", o.LatestCommit) for { previewList, err := o.listPreviews() @@ -206,7 +206,8 @@ func (o *Options) waitForCommit() (*v1alpha1.Preview, error) { if err != nil { return nil, err } - if preview != nil && preview.Spec.PullRequest.LatestCommit == o.LatestCommit { + if preview != nil && preview.Spec.PullRequest.LatestCommit == o.LatestCommit && + preview.Spec.Resources.URL != "" { return preview, nil } From 54e8b80b042160bd6fc541d851671e7bbe5b9f87 Mon Sep 17 00:00:00 2001 From: ZackJagger Date: Thu, 26 Oct 2023 16:58:07 +0100 Subject: [PATCH 3/3] chore: lint --- pkg/cmd/get/get.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/get/get.go b/pkg/cmd/get/get.go index 402a3f0..d798344 100644 --- a/pkg/cmd/get/get.go +++ b/pkg/cmd/get/get.go @@ -3,7 +3,6 @@ package get import ( "context" "fmt" - "github.com/jenkins-x/jx-logging/v3/pkg/log" "os" "time" @@ -16,6 +15,7 @@ import ( "github.com/jenkins-x/jx-helpers/v3/pkg/cobras/templates" "github.com/jenkins-x/jx-helpers/v3/pkg/scmhelpers" "github.com/jenkins-x/jx-helpers/v3/pkg/table" + "github.com/jenkins-x/jx-logging/v3/pkg/log" "github.com/pkg/errors" "github.com/spf13/cobra" apierrors "k8s.io/apimachinery/pkg/api/errors"