goharbor / goharbor/harbor-cli

[bug]: harbor project delete --force only deletes repos from the first API page — projects with >100 repos fail to delete

Open
#1,010 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
163
Forks
211
Avg merge
1m
Merged PRs (30d)
1

Description

# Description

In `pkg/api/project_handler.go`, `DeleteProject` with `forceDelete=true` calls `ListRepository` once:

```go
resp, err = ListRepository(projectNameOrID, useProjectID)
for _, repo := range resp.Payload {
err = RepoDelete(projectNameOrID, repoName, useProjectID)
}
```

`ListRepository` uses default pagination. A project with more than the default page size of repositories will have only the first page deleted. The subsequent `DeleteProject` API call returns `412 Precondition Failed`.

# Steps to Reproduce

1. Create a project with 110 repositories.
2. Run `harbor project delete --force `.
3. Observe: first ~100 repos deleted, then 412 error — 10 repos are orphaned.

# Expected Behavior

All repositories across all pages are deleted before the project deletion is attempted.

# Actual Behavior

Only the first page of repositories is deleted; the command fails with `412` if more remain.

# Environment

- OS: Any
- Tool version: v0.1.0

# Additional Context

Fix: paginate `ListRepository` in a loop (similar to `fetchProjects` in `cmd/harbor/root/project/list.go`) until all repositories are retrieved and deleted.

Contributor guide

Open the contributing guide

Research direction

Start in pkg/api/project_handler.go at DeleteProject and compare its repository listing with the pagination loop in cmd/harbor/root/project/list.go. Verify the project deletion path retrieves every repository page and deletes all repositories before calling the project deletion API. Reproduce with a project containing more than 100 repositories and confirm the project deletion no longer returns 412.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.