goharbor / goharbor/harbor-cli

[bug]: webhook list panics when a policy has no targets

Open
#973 1 comment 0 reactions 0 assignees View on GitHub
bug status/in-progress
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

## Description
`harbor webhook list` panics when Harbor returns a webhook policy with an empty `targets` array.

The list view indexes `webhook.Targets[0]` unconditionally, but the generated Harbor client model does not require `targets` to be present or non-empty.

## Steps to Reproduce
1. Run `harbor webhook list ` against a Harbor instance that returns a webhook policy with `targets: []`.
2. Observe the CLI panic in the webhook list view.

A minimal repro at code level is calling the list view with `&models.WebhookPolicy{}`.

## Expected Behavior
The command should render the webhook row and fall back to placeholders when target details are missing.

## Actual Behavior
The CLI panics with an index-out-of-range error while rendering the list.

## Environment
- OS: All
- Tool version: current `main`
- Other relevant details: the generated `WebhookPolicy` model treats `targets` as optional and its validator allows zero values.

## Additional Context
`cmd/harbor/root/webhook/edit.go` already guards `len(selectedWebhook.Targets) > 0`, so the codebase already assumes this shape can happen.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.