Skip to content

Commit

Permalink
added suggested changes
Browse files Browse the repository at this point in the history
Signed-off-by: adarsh-jaiss <[email protected]>
  • Loading branch information
Adarsh-jaiss committed Sep 10, 2024
1 parent fe51c90 commit d87bf81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions pkg/shp/cmd/build/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package build

import (
Expand All @@ -9,6 +10,7 @@ import (
"github.com/shipwright-io/cli/pkg/shp/params"
"github.com/spf13/cobra"

k8serrors "k8s.io/apimachinery/pkg/api/errors" // Import the k8serrors package
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
)
Expand Down Expand Up @@ -70,14 +72,19 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
}
_, err = k8sclient.CoreV1().Namespaces().Get(c.cmd.Context(), params.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("namespace %s not found. Please ensure that the namespace exists and try again", params.Namespace())
if k8serrors.IsNotFound(err) {
fmt.Fprintf(io.Out, "Namespace '%s' not found. Please ensure that the namespace exists and try again.\n", params.Namespace())
return nil
} else {

Check failure on line 78 in pkg/shp/cmd/build/list.go

View workflow job for this annotation

GitHub Actions / verify

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return err
}
}

if buildList, err = clientset.ShipwrightV1alpha1().Builds(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
return err
}
if len(buildList.Items) == 0 {
fmt.Fprintf(io.Out, "No builds found in namespace '%s'. Please initiate a build or verify the namespace.\n", params.Namespace())
fmt.Fprintf(io.Out, "No builds found in namespace '%s'. Please create a build or verify the namespace.\n", params.Namespace())
return nil
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/shp/cmd/buildrun/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/spf13/cobra"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/duration"
Expand Down Expand Up @@ -73,15 +74,20 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams
}
_, err = k8sclient.CoreV1().Namespaces().Get(c.cmd.Context(), params.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("namespace %s not found. Please ensure that the namespace exists and try again", params.Namespace())
if k8serrors.IsNotFound(err) {
fmt.Fprintf(io.Out, "Namespace '%s' not found. Please ensure that the namespace exists and try again.\n", params.Namespace())
return nil
} else {

Check failure on line 80 in pkg/shp/cmd/buildrun/list.go

View workflow job for this annotation

GitHub Actions / verify

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return err
}
}

var brs *buildv1alpha1.BuildRunList
if brs, err = clientset.ShipwrightV1alpha1().BuildRuns(params.Namespace()).List(c.cmd.Context(), metav1.ListOptions{}); err != nil {
return err
}
if len(brs.Items) == 0 {
fmt.Fprintf(io.Out, "No buildruns found in namespace '%s'. Please initiate a buildrun or verify the namespace.\n", params.Namespace())
fmt.Fprintf(io.Out, "No buildruns found in namespace '%s'. Please create a buildrun or verify the namespace.\n", params.Namespace())
return nil
}

Expand All @@ -105,3 +111,5 @@ func (c *ListCommand) Run(params *params.Params, io *genericclioptions.IOStreams

return writer.Flush()
}


0 comments on commit d87bf81

Please sign in to comment.