gitlink-cli/skills/gitlink-webhook/references/webhook-list.md

163 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# gitlink-cli webhook +list
列出仓库的所有 Webhook。
## 命令格式
```bash
gitlink-cli webhook +list [--owner OWNER] [--repo REPO] [--page PAGE] [--limit LIMIT]
```
## 参数说明
| 参数 | 短参数 | 说明 | 是否必须 | 默认值 |
|------|--------|------|----------|--------|
| `--owner` | `-o` | 仓库所有者 | 否 | 自动从 git remote 解析 |
| `--repo` | `-r` | 仓库名称 | 否 | 自动从 git remote 解析 |
| `--page` | `-p` | 页码 | 否 | 1 |
| `--limit` | `-l` | 每页数量 | 否 | 20 |
## 返回值
### 成功返回
```json
{
"ok": true,
"data": {
"webhooks": [
{
"id": "123",
"hook_url": "https://example.com/webhook",
"events": ["push", "pull_request"],
"is_active": true,
"content_type": "json",
"description": "CI/CD webhook",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
],
"total_count": 5,
"page": 1,
"limit": 20
},
"meta": {
"page": 1,
"limit": 20,
"total_count": 5
}
}
```
### 错误返回
```json
{
"ok": false,
"error": {
"code": 401,
"message": "Authentication failed",
"suggestion": "Please run 'gitlink-cli auth login' to authenticate"
}
}
```
## 使用示例
### 基本用法
```bash
# 列出当前仓库的 Webhook需要在 git 仓库目录中)
gitlink-cli webhook +list
# 列出指定仓库的 Webhook
gitlink-cli webhook +list --owner myuser --repo myrepo
# 分页显示
gitlink-cli webhook +list --owner myuser --repo myrepo --page 2 --limit 10
```
### JSON 格式输出AI Agent 使用)
```bash
# 获取 JSON 格式输出便于解析
gitlink-cli webhook +list --owner myuser --repo myrepo --format json
# 使用 jq 处理输出
gitlink-cli webhook +list --format json | jq '.data.webhooks[] | select(.is_active == true)'
# 统计 Webhook 数量
gitlink-cli webhook +list --format json | jq '.data.total_count'
```
### Table 格式输出
```bash
# 表格格式更易阅读(默认)
gitlink-cli webhook +list --format table
# 指定表格格式
gitlink-cli webhook +list --owner myuser --repo myrepo --format table
```
## 错误处理
### 常见错误
#### 1. 认证失败
```bash
Error: [401] Authentication failed
```
**原因**: Token 过期或无效
**解决方案**:
```bash
gitlink-cli auth login
```
#### 2. 权限不足
```bash
Error: [403] You don't have permission to view webhooks
```
**原因**: 用户没有仓库访问权限
**解决方案**: 确认您是仓库成员或公开项目
#### 3. 仓库不存在
```bash
Error: [404] Repository not found
```
**原因**: 仓库名称或所有者错误
**解决方案**: 使用 `gitlink-cli repo +list` 确认仓库名称
## AI Agent 使用建议
### 检查 Webhook 配置
```bash
# 检查是否已配置特定类型的 Webhook
gitlink-cli webhook +list --format json | jq '.data.webhooks[] | select(.hook_url | contains("ci-system"))'
# 检查是否有激活的 Webhook
gitlink-cli webhook +list --format json | jq '.data.webhooks[] | select(.is_active == true)'
# 获取所有 Webhook 的 URL
gitlink-cli webhook +list --format json | jq '.data.webhooks[].hook_url'
```
### 批量操作
```bash
# 获取所有 Webhook ID
webhook_ids=$(gitlink-cli webhook +list --format json | jq -r '.data.webhooks[].id')
# 批量测试所有 Webhook
for id in $webhook_ids; do
gitlink-cli webhook +test --id $id
done
```
## 注意事项
1. **分页查询**: 默认每页显示 20 个,使用 `--limit` 可调整
2. **权限要求**: 至少需要仓库读取权限
3. **自动解析**: 在 git 仓库目录中可省略 `--owner``--repo`
4. **格式选择**: AI Agent 建议使用 `--format json` 便于解析
## 相关命令
- `webhook +create` - 创建新 Webhook
- `webhook +info` - 查看特定 Webhook 详情
- `webhook +events` - 查看支持的事件类型