Skip to content

feat(cmd): add 'get' subcommand for build and buildrun resources - #412

Open
mohit-bhandari45 wants to merge 1 commit into
shipwright-io:mainfrom
mohit-bhandari45:feat/add-get-and-update-subcommands
Open

mohit-bhandari45 wants to merge 1 commit into
shipwright-io:mainfrom
mohit-bhandari45:feat/add-get-and-update-subcommands

Conversation

@mohit-bhandari45

Copy link
Copy Markdown

Changes

Introduced the missing get subcommand for both build and buildrun resource managers (shp build get and shp buildrun get):

  • shp build get <name>: Retrieves detailed specification and status for a Build object (Source URL, revision, strategy, output image, registration status).
  • shp buildrun get <name>: Retrieves detailed specification and status for a BuildRun execution object (Build ref, status condition, start & completion times).
  • Output Formats: Added support for -o json and -o yaml flags, as well as a default clean key-value summary table.
  • Error Handling: Handled NotFound errors gracefully with friendly messages (e.g. Build 'xyz' not found in namespace 'default'.).
  • Unit Tests: Created comprehensive unit test suites in pkg/shp/cmd/build/get_test.go and pkg/shp/cmd/buildrun/get_test.go (100% passing).

Note: As discussed, the missing update subcommand will be submitted in a separate follow-up PR.

Related Issue

Fixes #411

Type of PR

/kind feature

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Kind label has been set
  • Release notes block has been filled in, or marked NONE

Release Notes

Added `shp build get <name>` and `shp buildrun get <name>` subcommands to inspect Build and BuildRun resources with support for `-o json` and `-o yaml` output formatting.

Copilot AI balanced review requested due to automatic review settings September 8, 2026 06:13
@openshift-ci openshift-ci Bot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 8, 2026
@openshift-ci

openshift-ci Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@pull-request-size pull-request-size Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 8, 2026
@openshift-ci
openshift-ci Bot requested review from kaizakin and rxinui September 8, 2026 06:13
@openshift-ci openshift-ci Bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Sep 8, 2026
@openshift-ci

openshift-ci Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign qu1queee for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mohit-bhandari45

Copy link
Copy Markdown
Author

@kaizakin Please review this pr.

Signed-off-by: mohit-bhandari45 <mohitbhandari852@gmail.com>
@mohit-bhandari45
mohit-bhandari45 force-pushed the feat/add-get-and-update-subcommands branch from 33a2640 to 8ff0a70 Compare September 8, 2026 06:58
@mohit-bhandari45

Copy link
Copy Markdown
Author

@SaschaSchwarze0 Do review this once you get time.

@kaizakin kaizakin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please address my comments

and btw try to reduce duplicated code if possible/applicable

Comment thread pkg/shp/cmd/build/get.go
w := tabwriter.NewWriter(ioStreams.Out, 0, 8, 2, '\t', 0);
fmt.Fprintf(w, "NAME:\t%s\n", build.Name)
fmt.Fprintf(w, "NAMESPACE:\t%s\n", build.Namespace)
if build.Spec.Source.Git != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check Spec.Source is not nil before doing this

Comment thread pkg/shp/cmd/build/get.go
build, err := clientset.ShipwrightV1beta1().Builds(ns).Get(c.cmd.Context(), c.name, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
fmt.Fprintf(ioStreams.Out, "Build '%s' not found in namespace '%s'.\n", c.name, ns)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should propagate the error
and a non-zero exit

Comment thread pkg/shp/cmd/build/get.go
}

func (c *GetCommand) Validate() error {
if c.name == "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check for invalid -o values as well

Comment thread pkg/shp/cmd/build/get.go

switch c.output {
case "json":
data, err := json.MarshalIndent(build, "", " ");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a semi-colon here?

also please make sure you format the code with gofmt

it would be also better if you run golangci-lint as well


// TODO: add support for `update` and `get` commands
command.AddCommand(
runner.NewRunner(p, ioStreams, getCmd()).Cmd(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to generate the docs

there's a makefile target for that

@@ -23,6 +23,7 @@ func Command(p *params.Params, ioStreams *genericclioptions.IOStreams) *cobra.Co

// TODO: add support for `update` and `get` commands

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this TODO is left untouched

update this please

status := "Unknown"
for _, condition := range buildRun.Status.Conditions {
if condition.Type == buildv1beta1.Succeeded {
status = condition.Reason

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check for nil values

Comment thread pkg/shp/cmd/build/get.go

cmd.Flags().StringVarP(&c.output, "output", "o", "", "Output format. Allowed values: json, yaml")
return c
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new line

if err.Error() != expectedErr {
t.Errorf("expected error %q, but got %q", expectedErr, err.Error())
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new line


cmd.Flags().StringVarP(&c.output, "output", "o", "", "Output format. Allowed values: json, yaml")
return c
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add missing get and update subcommands for build and buildrun

4 participants