Add bulk repository deletion for organizations#36763
Add bulk repository deletion for organizations#36763wxiaoguang merged 51 commits intogo-gitea:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements a new bulk repository deletion API endpoint for organizations, addressing the need for efficient organization cleanup operations. The endpoint allows organization owners to delete all repositories within an organization in a single API call, with graceful error handling that continues processing even when individual repository deletions fail.
Changes:
- Added new
DELETE /api/v1/orgs/{org}/reposAPI endpoint with organization owner authorization - Implemented response structures that track both successful and failed deletions with detailed failure reasons
- Added comprehensive integration tests covering success scenarios, response structure validation, and permission enforcement
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| routers/api/v1/api.go | Registers the new DELETE endpoint on the /orgs/{org}/repos route with reqOrgOwnership middleware |
| routers/api/v1/org/org.go | Implements DeleteOrgRepos handler with per-repository permission checks and error collection |
| modules/structs/repo.go | Defines DeleteOrgReposResponse and DeleteRepoFailure types for structured API responses |
| routers/api/v1/swagger/org.go | Adds swagger response definition for the new endpoint |
| templates/swagger/v1_json.tmpl | Defines swagger documentation including response schemas and operation details |
| tests/integration/api_org_test.go | Adds three test cases covering successful bulk deletion, response structure, and permission enforcement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wxiaoguang
left a comment
There was a problem hiding this comment.
Don't do Reason: err.Error()
Only pass the errors you know to end users, otherwise there will be sensitive information leaking, the Golang error can contain server side paths or URL with passwords.
|
Hi @lunny , just following up on this PR. Could you please take a look when you get a chance? It has been pending for about a week. Thanks! |
|
Looks like this PR's content is outdated, please update. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
wxiaoguang
left a comment
There was a problem hiding this comment.
Cleaned up the AI slop. Don't see why it needs 200+ lines to test such a simple feature.
Ok. I was trying to cover all cases but went overboard with AI generated tests. |
|
the test-mssql is failing due to the system notice that is being created by |
I can raise a new pr for this since it is not related to this pr. |
…license * origin/main: Update go dependencies (go-gitea#37141) Update javascript dependencies (go-gitea#37142) Bump min go version to 1.26.2 (go-gitea#37139) Add bulk repository deletion for organizations (go-gitea#36763) [skip ci] Updated translations via Crowdin # Conflicts: # package.json # pnpm-lock.yaml
* main: models/fixtures: add "DO NOT add more test data" comment to all yml fixture files (go-gitea#37150) Frontport changelog of v1.26.0-rc0 (go-gitea#37138) Update go dependencies (go-gitea#37141) Update javascript dependencies (go-gitea#37142) Bump min go version to 1.26.2 (go-gitea#37139) Add bulk repository deletion for organizations (go-gitea#36763)
Summary
Fixes #36512
This PR adds a new API endpoint to delete all repositories within an organization in a single operation, improving efficiency for organization cleanup and management tasks.
Implementation
• New Endpoint: DELETE /api/v1/orgs/{org}/repos
• Authorization: Requires organization owner permissions
• Asynchronous Processing: Deletion runs in background to avoid request timeouts
• Response Codes:
The endpoint processes all repositories asynchronously in a background goroutine with proper panic recovery. Failures are logged and recorded as system notices for administrator review.
Key Features
• Background Processing: Prevents timeout on large organizations
• Error Handling: Panic recovery with system notice creation
• Empty Organization Handling: Returns 204 when no repositories exist
• Graceful Context: Uses detached context to ensure completion even during shutdown
Usage
Request:
Response:
• 202 Accepted - Deletion started in background
• 204 No Content - No repositories to delete
Testing
The implementation includes comprehensive integration tests covering:
All tests pass with PostgreSQL backend.
Documentation
• Updated Swagger documentation with correct response codes (202, 204, 403, 404)
• Endpoint appears correctly in /api/swagger documentation
Development Notes
Amazon Q Developer was used to understand the codebase structure and identify the appropriate helper functions and patterns used throughout Gitea's API implementation.