The diff shows a single-line change in `gitea_api.py` where the URL path for repository deletion was corrected from `{self.api_url}/api/v1/repos/{owner}/{repo_name}` to `{self.api_url}/repos/{owner}/{repo_name}`. This fixes a broken endpoint because `self.api_url` already includes the `/api/v1` base path, causing a double prefix that would result in 404 errors in production.
Gitea Repository Antispam
Solution for repositories created by spammers.
This script deletes Gitea repositories that are likely created by spammers based on the following criteria:
- Repository has no commits
This project is a professional, ready-to-use script for managing Gitea repositories. It allows you to list, check, and delete repositories based on customizable criteria. Designed for efficiency and security, it supports environment variable configuration, command-line parameters, and token-based authentication.
Features
- List all accessible repositories
- Check for existing commits
- Delete repositories that meet specific criteria
- Safe dry-run mode for testing
- Easy token management via Gitea's application settings
Requirements
- Python 3.x
requestslibrary (install viapip install requests)
Environment Variables (Optional)
You can create a .env file in the project directory to set default values for the script. This file is optional but recommended for convenience.
.env file format
GITEA_USERNAME=your_username
GITEA_PASSWORD=your_password
GITEA_API_URL=https://gitea.example.com/api/v1
GITEA_API_TOKEN=your_token
Notes:
- The
.envfile is purely for default values; command-line arguments override these settings. - You should generate a personal access token in Gitea under
/user/settings/applications. Use this token for authentication to avoid exposing your password.
Usage
Example Gitea URL
https://gitea.example.com/api/v1
Creating a Token in Gitea
- Log in to your Gitea account.
- Navigate to
/user/settings/applications. - Create a new application token.
- Use this token as the
GITEA_API_TOKENin your environment or command-line.
Command-line Parameters
python main.py \
--gitea-username your_username \
--gitea-password your_password \
--gitea-api-url https://gitea.example.com \
--gitea-api-token your_token \
--dry-run
--dry-run: Perform a simulation without making any changes (default mode).--no-dry-run: Execute actual deletions and modifications.
Default Behavior
If environment variables are set or .env exists, you can run the script without parameters:
python main.py
The script will run with a configuration time of approximately 10 minutes, suitable for large repositories or extensive operations.
Contact
For support or questions, contact:
retoor retoor@molodetz.nl
License
This project is licensed under the MIT License. Feel free to use, modify, and distribute as you see fit.
Summary
This is a complete, professional solution for managing your Gitea repositories efficiently and securely. No contributions are needed—it's ready to deploy and use in your environment.