Gitee API 开发指南
OAuth2授权流程
1 2 3 4 5
| sequenceDiagram 应用->>Gitee: 1. 跳转授权页面 Gitee->>用户: 2. 登录确认授权 Gitee-->>应用: 3. 返回授权码 应用->>Gitee: 4. 换取access_token
|
企业级API示例
批量创建仓库
1 2 3 4 5 6 7 8 9 10 11 12
| from gitee import RepositoriesApi
api = RepositoriesApi() for project in enterprise_projects: api.post_v5_enterprises_enterprise_repos( enterprise="my-company", body={ "name": project['name'], "private": True, "members": ["dev-lead", "qa-lead"] } )
|
分支保护策略
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| paths: /repos/{owner}/{repo}/branches/{branch}/protection: put: parameters: - name: push_whitelist in: body description: 允许推送的白名单 schema: type: array items: string responses: 200: description: 策略更新成功
|
Webhook配置
1 2 3 4 5 6 7 8 9
| curl -X POST "https://gitee.com/api/v5/repos/{owner}/{repo}/hooks" \ -H "Authorization: Bearer {token}" \ -d '{ "url": "https://ci.example.com/webhook", "encryption_type": "aes-256-cbc", "password": "your_encrypt_key", "events": ["push", "merge_request"] }'
|
最佳实践:使用API请求签名机制保障企业系统间通信安全