清理gitea的垃圾用户
Go to file
2026-01-03 20:42:55 +08:00
.env.example Initialize Gitea user cleanup tool with main script, README, environment configuration, and dependencies. Added .env.example and .gitignore files for environment variable management and to exclude sensitive files from version control. 2026-01-03 01:18:26 +08:00
.gitignore Initialize Gitea user cleanup tool with main script, README, environment configuration, and dependencies. Added .env.example and .gitignore files for environment variable management and to exclude sensitive files from version control. 2026-01-03 01:18:26 +08:00
main.py 更新 main.py 2026-01-03 20:42:55 +08:00
README.md Initialize Gitea user cleanup tool with main script, README, environment configuration, and dependencies. Added .env.example and .gitignore files for environment variable management and to exclude sensitive files from version control. 2026-01-03 01:18:26 +08:00
requirements.txt Initialize Gitea user cleanup tool with main script, README, environment configuration, and dependencies. Added .env.example and .gitignore files for environment variable management and to exclude sensitive files from version control. 2026-01-03 01:18:26 +08:00

Gitea 用户清理工具

一个用于清理 Gitea 实例中不在指定组织内的用户的 Python 脚本。

功能特性

  • 获取 Gitea 实例中的所有用户
  • 获取指定组织的所有成员
  • 自动删除不在组织内的用户及其所有仓库
  • 使用进度条显示删除进度

环境要求

  • Python 3.11
  • Gitea 实例访问权限
  • Gitea API Token管理员权限

安装

  1. 克隆或下载此项目

  2. 安装依赖:

pip install -r requirements.txt

配置

在项目根目录创建 .env 文件,配置以下环境变量:

GITEA_URL=https://your-gitea-instance.com
GITEA_API_TOKEN=your_api_token_here

获取 API Token

  1. 登录 Gitea 实例
  2. 进入 设置应用生成新令牌
  3. 选择权限范围(需要管理员权限)
  4. 复制生成的令牌到 .env 文件

使用方法

基本使用

运行脚本将自动:

  1. 获取所有用户列表
  2. 获取指定组织的成员列表(默认为 "TianMa431"
  3. 删除不在组织内的用户及其所有仓库
python main.py

自定义组织名称

main.py 中修改 get_org_user_names() 函数的默认参数:

org_user_names = get_org_user_names("YourOrgName")

单独删除用户

取消注释并修改以下代码来删除特定用户:

delete_user("username")

主要函数

get_user_names()

获取 Gitea 实例中的所有用户名列表。

get_org_user_names(org_name="TianMa431")

获取指定组织的所有成员用户名列表。

delete_user(username)

删除指定用户及其所有仓库。此操作不可逆!

⚠️ 警告

  • 此脚本会永久删除用户及其所有仓库数据,操作不可恢复!
  • 使用前请确保已备份重要数据
  • 建议先在测试环境验证
  • 确保 API Token 具有足够的权限

依赖包

  • requests - HTTP 请求库
  • python-dotenv - 环境变量管理
  • tqdm - 进度条显示

许可证

本项目仅供学习和内部使用。