Add gitea-manager skill for Gitea repository operations
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
This commit is contained in:
339
gitea-manager/SKILL.md
Normal file
339
gitea-manager/SKILL.md
Normal file
@@ -0,0 +1,339 @@
|
||||
---
|
||||
name: gitea-manager
|
||||
description: 管理 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 连接信息:
|
||||
|
||||
```bash
|
||||
export GITEA_URL="https://gitea.example.com"
|
||||
export GITEA_TOKEN="your-api-token-here"
|
||||
```
|
||||
|
||||
可以通过以下方式获取 API Token:
|
||||
1. 登录 Gitea
|
||||
2. 进入「设置」→「应用」
|
||||
3. 创建新的 API Token
|
||||
|
||||
### 初始化客户端
|
||||
|
||||
在 Python 代码中使用:
|
||||
|
||||
```python
|
||||
import sys
|
||||
sys.path.append("/root/.claude/skills/gitea-manager/scripts")
|
||||
from gitea_client import GiteaClient
|
||||
|
||||
client = GiteaClient()
|
||||
```
|
||||
|
||||
或指定自定义配置:
|
||||
|
||||
```python
|
||||
client = GiteaClient(url="https://gitea.example.com", token="your-token")
|
||||
```
|
||||
|
||||
## 仓库操作
|
||||
|
||||
### 列出仓库
|
||||
|
||||
```python
|
||||
repos = client.list_my_repos()
|
||||
for r in repos:
|
||||
print(f"{r['full_name']}: {r.get('description', '')}")
|
||||
```
|
||||
|
||||
### 创建仓库
|
||||
|
||||
```python
|
||||
repo = client.create_repo(
|
||||
name="my-new-repo",
|
||||
description="这是一个新仓库",
|
||||
private=False,
|
||||
auto_init=True
|
||||
)
|
||||
```
|
||||
|
||||
### 在组织下创建仓库
|
||||
|
||||
```python
|
||||
repo = client.create_org_repo(
|
||||
org="my-org",
|
||||
name="org-repo",
|
||||
description="组织仓库",
|
||||
private=True
|
||||
)
|
||||
```
|
||||
|
||||
### 获取仓库信息
|
||||
|
||||
```python
|
||||
repo = client.get_repo("owner", "repo-name")
|
||||
```
|
||||
|
||||
### 删除仓库
|
||||
|
||||
```python
|
||||
client.delete_repo("owner", "repo-name")
|
||||
```
|
||||
|
||||
## 文件操作
|
||||
|
||||
### 读取文件内容
|
||||
|
||||
```python
|
||||
content = client.get_file_content("owner", "repo", "path/to/file.txt", ref="main")
|
||||
```
|
||||
|
||||
### 获取文件信息
|
||||
|
||||
```python
|
||||
info = client.get_file_info("owner", "repo", "path/to/file.txt", ref="main")
|
||||
```
|
||||
|
||||
### 创建或更新文件
|
||||
|
||||
```python
|
||||
client.create_or_update_file(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
path="new-file.txt",
|
||||
content="文件内容",
|
||||
message="添加新文件",
|
||||
branch="main",
|
||||
email="user@example.com",
|
||||
name="Username"
|
||||
)
|
||||
```
|
||||
|
||||
### 删除文件
|
||||
|
||||
```python
|
||||
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"
|
||||
)
|
||||
```
|
||||
|
||||
### 列出目录
|
||||
|
||||
```python
|
||||
files = client.list_directory("owner", "repo", "path/to/dir", ref="main")
|
||||
```
|
||||
|
||||
## 分支操作
|
||||
|
||||
### 列出分支
|
||||
|
||||
```python
|
||||
branches = client.list_branches("owner", "repo")
|
||||
```
|
||||
|
||||
### 获取分支信息
|
||||
|
||||
```python
|
||||
branch = client.get_branch("owner", "repo", "main")
|
||||
```
|
||||
|
||||
### 创建分支
|
||||
|
||||
```python
|
||||
client.create_branch("owner", "repo", "new-branch", "main")
|
||||
```
|
||||
|
||||
### 删除分支
|
||||
|
||||
```python
|
||||
client.delete_branch("owner", "repo", "old-branch")
|
||||
```
|
||||
|
||||
### 设置分支保护
|
||||
|
||||
```python
|
||||
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
|
||||
|
||||
```python
|
||||
issues = client.list_issues("owner", "repo", state="open")
|
||||
```
|
||||
|
||||
### 创建 Issue
|
||||
|
||||
```python
|
||||
issue = client.create_issue(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
title="Bug: 登录失败",
|
||||
body="详细描述问题..."
|
||||
)
|
||||
```
|
||||
|
||||
### 更新 Issue
|
||||
|
||||
```python
|
||||
client.update_issue("owner", "repo", issue_index, title="新标题", state="closed")
|
||||
```
|
||||
|
||||
### 添加评论
|
||||
|
||||
```python
|
||||
comment = client.create_issue_comment("owner", "repo", issue_index, "这是我的评论")
|
||||
```
|
||||
|
||||
## Pull Request 操作
|
||||
|
||||
### 列出 PR
|
||||
|
||||
```python
|
||||
pulls = client.list_pulls("owner", "repo", state="open")
|
||||
```
|
||||
|
||||
### 创建 PR
|
||||
|
||||
```python
|
||||
pr = client.create_pull(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
title="Add new feature",
|
||||
body="PR 描述...",
|
||||
head="feature-branch",
|
||||
base="main"
|
||||
)
|
||||
```
|
||||
|
||||
### 合并 PR
|
||||
|
||||
```python
|
||||
client.merge_pull("owner", "repo", pr_index, merge_style="merge")
|
||||
```
|
||||
|
||||
## 组织操作
|
||||
|
||||
### 列出组织
|
||||
|
||||
```python
|
||||
orgs = client.list_orgs()
|
||||
```
|
||||
|
||||
### 列出组织仓库
|
||||
|
||||
```python
|
||||
repos = client.list_org_repos("my-org")
|
||||
```
|
||||
|
||||
### 创建组织
|
||||
|
||||
```python
|
||||
org = client.create_org(
|
||||
username="new-org",
|
||||
email="org@example.com"
|
||||
)
|
||||
```
|
||||
|
||||
### 列出组织团队
|
||||
|
||||
```python
|
||||
teams = client.list_org_teams("my-org")
|
||||
```
|
||||
|
||||
## Webhook 操作
|
||||
|
||||
### 列出 Webhook
|
||||
|
||||
```python
|
||||
hooks = client.list_hooks("owner", "repo")
|
||||
```
|
||||
|
||||
### 创建 Webhook
|
||||
|
||||
```python
|
||||
hook = client.create_hook(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
config={"url": "https://example.com/webhook", "secret": "secret"},
|
||||
events=["push", "issue", "pull_request"],
|
||||
active=True
|
||||
)
|
||||
```
|
||||
|
||||
### 删除 Webhook
|
||||
|
||||
```python
|
||||
client.delete_hook("owner", "repo", hook_id)
|
||||
```
|
||||
|
||||
## Deploy Key 操作
|
||||
|
||||
### 列出 Deploy Key
|
||||
|
||||
```python
|
||||
keys = client.list_deploy_keys("owner", "repo")
|
||||
```
|
||||
|
||||
### 创建 Deploy Key
|
||||
|
||||
```python
|
||||
key = client.create_deploy_key(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
title="my-deploy-key",
|
||||
key="ssh-rsa AAAA...",
|
||||
read_only=True
|
||||
)
|
||||
```
|
||||
|
||||
### 删除 Deploy Key
|
||||
|
||||
```python
|
||||
client.delete_deploy_key("owner", "repo", key_id)
|
||||
```
|
||||
|
||||
## 搜索操作
|
||||
|
||||
### 搜索仓库
|
||||
|
||||
```python
|
||||
repos = client.search_repos("keyword", limit=20)
|
||||
```
|
||||
|
||||
### 搜索 Issue
|
||||
|
||||
```python
|
||||
issues = client.search_issues("owner", "repo", "bug", limit=20)
|
||||
```
|
||||
|
||||
## 命令行使用
|
||||
|
||||
脚本也支持命令行调用:
|
||||
|
||||
```bash
|
||||
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
|
||||
```
|
||||
Reference in New Issue
Block a user