Skip to content

Add bulk repository deletion for organizations#36763

Merged
wxiaoguang merged 51 commits intogo-gitea:mainfrom
karthikbhandary2:main
Apr 8, 2026
Merged

Add bulk repository deletion for organizations#36763
wxiaoguang merged 51 commits intogo-gitea:mainfrom
karthikbhandary2:main

Conversation

@karthikbhandary2
Copy link
Copy Markdown
Contributor

@karthikbhandary2 karthikbhandary2 commented Feb 26, 2026

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:

  • 202 Accepted: Deletion started (when repositories exist)
  • 204 No Content: No repositories to delete
  • 403 Forbidden: Non-owner attempting deletion
  • 404 Not Found: Organization not found

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:

curl -X DELETE "https://gitea.example.com/api/v1/orgs/my-org/repos" \
  -H "Authorization: token YOUR_TOKEN"

Response:
• 202 Accepted - Deletion started in background
• 204 No Content - No repositories to delete

Testing

The implementation includes comprehensive integration tests covering:

  1. Basic deletion: Successfully deletes repositories and returns 202
  2. Permission test: Ensures non-owners receive 403 Forbidden
  3. System notice verification: Confirms no notices created on successful deletion
  4. Empty organization: Returns 204 when no repositories exist
  5. Already deleted: Returns 204 when repositories already deleted

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.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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}/repos API 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.

Comment thread templates/swagger/v1_json.tmpl Outdated
Comment thread modules/structs/repo.go Outdated
Comment thread routers/api/v1/org/org.go
Comment thread routers/api/v1/swagger/org.go Outdated
Comment thread templates/swagger/v1_json.tmpl Outdated
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

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.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2026
Comment thread modules/structs/repo.go Outdated
Comment thread routers/api/v1/org/org.go Outdated
Comment thread routers/api/v1/org/org.go Outdated
@wxiaoguang wxiaoguang requested review from lunny and removed request for wxiaoguang February 27, 2026 17:32
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Feb 28, 2026
@karthikbhandary2
Copy link
Copy Markdown
Contributor Author

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!

Comment thread routers/api/v1/org/org.go Outdated
@lunny
Copy link
Copy Markdown
Member

lunny commented Mar 5, 2026

Looks like this PR's content is outdated, please update.

@lunny lunny requested a review from Copilot March 5, 2026 19:13
@GiteaBot GiteaBot added the lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged label Apr 5, 2026
@wxiaoguang wxiaoguang dismissed lunny’s stale review April 5, 2026 19:33

address the review first.

@bircni

This comment was marked as off-topic.

@wxiaoguang

This comment was marked as off-topic.

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

Cleaned up the AI slop. Don't see why it needs 200+ lines to test such a simple feature.

@karthikbhandary2
Copy link
Copy Markdown
Contributor Author

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.

@karthikbhandary2
Copy link
Copy Markdown
Contributor Author

karthikbhandary2 commented Apr 7, 2026

the test-mssql is failing due to the system notice that is being created by RemoveStorageWithNotice which is giving "File does not exist" notice during repository deletion cleanup. Is this something I have to fix?

@karthikbhandary2
Copy link
Copy Markdown
Contributor Author

the test-mssql is failing due to the system notice that is being created by RemoveStorageWithNotice which is giving "File does not exist" notice. Is this something I have to fix?

I can raise a new pr for this since it is not related to this pr.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Apr 7, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 8, 2026 04:07
@wxiaoguang wxiaoguang merged commit fc178e3 into go-gitea:main Apr 8, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 8, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 8, 2026
…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
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 9, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: API endpoint to delete all repositories in an organization

6 participants