5.7 KiB
5.7 KiB
name, description
| name | description |
|---|---|
| gitea-manager | 管理 Gitea 仓库的全能工具,支持仓库创建删除、文件操作、分支管理、Issue/PR 管理、组织和用户操作、仓库设置配置等。使用场景:(1) 创建或删除 Gitea 仓库 (2) 管理仓库文件和目录 (3) 操作分支和保护规则 (4) 创建和管理 Issue 和 Pull Request (5) 管理组织和团队成员 (6) 配置 Webhook 和 Deploy Key (7) 搜索仓库和 Issue。必需环境变量:GITEA_URL(实例地址)和 GITEA_TOKEN(API 令牌)。 |
Gitea Manager
快速开始
环境配置
使用此 skill 前需要配置 Gitea 连接信息:
export GITEA_URL="https://gitea.example.com"
export GITEA_TOKEN="your-api-token-here"
可以通过以下方式获取 API Token:
- 登录 Gitea
- 进入「设置」→「应用」
- 创建新的 API Token
初始化客户端
在 Python 代码中使用:
import sys
sys.path.append("/root/.claude/skills/gitea-manager/scripts")
from gitea_client import GiteaClient
client = GiteaClient()
或指定自定义配置:
client = GiteaClient(url="https://gitea.example.com", token="your-token")
仓库操作
列出仓库
repos = client.list_my_repos()
for r in repos:
print(f"{r['full_name']}: {r.get('description', '')}")
创建仓库
repo = client.create_repo(
name="my-new-repo",
description="这是一个新仓库",
private=False,
auto_init=True
)
在组织下创建仓库
repo = client.create_org_repo(
org="my-org",
name="org-repo",
description="组织仓库",
private=True
)
获取仓库信息
repo = client.get_repo("owner", "repo-name")
删除仓库
client.delete_repo("owner", "repo-name")
文件操作
读取文件内容
content = client.get_file_content("owner", "repo", "path/to/file.txt", ref="main")
获取文件信息
info = client.get_file_info("owner", "repo", "path/to/file.txt", ref="main")
创建或更新文件
client.create_or_update_file(
owner="owner",
repo="repo",
path="new-file.txt",
content="文件内容",
message="添加新文件",
branch="main",
email="user@example.com",
name="Username"
)
删除文件
info = client.get_file_info("owner", "repo", "file.txt")
client.delete_file(
owner="owner",
repo="repo",
path="file.txt",
message="删除文件",
branch="main",
sha=info["sha"],
email="user@example.com",
name="Username"
)
列出目录
files = client.list_directory("owner", "repo", "path/to/dir", ref="main")
分支操作
列出分支
branches = client.list_branches("owner", "repo")
获取分支信息
branch = client.get_branch("owner", "repo", "main")
创建分支
client.create_branch("owner", "repo", "new-branch", "main")
删除分支
client.delete_branch("owner", "repo", "old-branch")
设置分支保护
client.set_protected_branch(
owner="owner",
repo="repo",
branch="main",
enable_push=True,
enable_push_whitelist=["developers"],
require_pull_request=True,
require_approvals=2
)
Issue 操作
列出 Issue
issues = client.list_issues("owner", "repo", state="open")
创建 Issue
issue = client.create_issue(
owner="owner",
repo="repo",
title="Bug: 登录失败",
body="详细描述问题..."
)
更新 Issue
client.update_issue("owner", "repo", issue_index, title="新标题", state="closed")
添加评论
comment = client.create_issue_comment("owner", "repo", issue_index, "这是我的评论")
Pull Request 操作
列出 PR
pulls = client.list_pulls("owner", "repo", state="open")
创建 PR
pr = client.create_pull(
owner="owner",
repo="repo",
title="Add new feature",
body="PR 描述...",
head="feature-branch",
base="main"
)
合并 PR
client.merge_pull("owner", "repo", pr_index, merge_style="merge")
组织操作
列出组织
orgs = client.list_orgs()
列出组织仓库
repos = client.list_org_repos("my-org")
创建组织
org = client.create_org(
username="new-org",
email="org@example.com"
)
列出组织团队
teams = client.list_org_teams("my-org")
Webhook 操作
列出 Webhook
hooks = client.list_hooks("owner", "repo")
创建 Webhook
hook = client.create_hook(
owner="owner",
repo="repo",
config={"url": "https://example.com/webhook", "secret": "secret"},
events=["push", "issue", "pull_request"],
active=True
)
删除 Webhook
client.delete_hook("owner", "repo", hook_id)
Deploy Key 操作
列出 Deploy Key
keys = client.list_deploy_keys("owner", "repo")
创建 Deploy Key
key = client.create_deploy_key(
owner="owner",
repo="repo",
title="my-deploy-key",
key="ssh-rsa AAAA...",
read_only=True
)
删除 Deploy Key
client.delete_deploy_key("owner", "repo", key_id)
搜索操作
搜索仓库
repos = client.search_repos("keyword", limit=20)
搜索 Issue
issues = client.search_issues("owner", "repo", "bug", limit=20)
命令行使用
脚本也支持命令行调用:
python gitea_client.py list-repos
python gitea_client.py get-repo owner/repo
python gitea_client.py create-repo my-repo "描述"
python gitea_client.py delete-repo owner/repo