TeamAI CLI 通过 provider 抽象层支持多个 git 托管平台。当前实现了两个:
| Provider | Host | 认证方式 | 建议场景 |
|---|---|---|---|
github |
github.com | gh CLI 或 GITHUB_TOKEN 环境变量 |
开源项目、外部用户 |
tgit |
git.woa.com | gf CLI(自动下载)+ ~/.netrc |
腾讯内部团队 |
teamai init --repo <input> 根据输入格式自动选择 provider:
yourorg/yourrepo → github(默认)
https://github.com/org/repo(.git) → github
git@github.com:org/repo.git → github
https://git.woa.com/team/repo(.git) → tgit
git@git.woa.com:team/repo.git → tgit
provider 选择会写入 team 仓库的 teamai.yaml 的 provider 字段,后续 push / pull 都按这个值来。
两种方式,推荐用 gh CLI:
方式 1:gh CLI(推荐)
# macOS
brew install gh
# Debian/Ubuntu
sudo apt install gh
# 其他平台见 https://cli.github.com/安装后运行 gh auth login,或直接让 teamai init 触发交互式登录:
teamai init --repo yourorg/yourrepo
# 检测到未登录时会自动调起 gh auth login --web方式 2:GITHUB_TOKEN 环境变量
无法安装 gh CLI 的环境(CI、容器、受限 Linux)可以通过 personal access token 认证:
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxx
teamai init --repo yourorg/yourrepotoken 需要 repo 权限。GH_TOKEN 作为别名也会被识别。
| 操作 | 实现 |
|---|---|
| clone | git clone https://x-access-token:$TOKEN@github.com/... |
| 创建仓库 | POST /user/repos 或 POST /orgs/:org/repos |
| 创建 PR | gh pr create 或 POST /repos/:o/:r/pulls |
| 指定 reviewer | gh pr create -r 或 POST .../requested_reviewers |
GitHub 新仓库默认分支通常是 main。TeamAI 当前实现中 push 的目标分支硬编码为 master(历史遗留)。如果你的 GitHub 仓库使用 main,可以在仓库 Settings → Branches 中将默认分支改为 master,或等待后续版本支持可配置目标分支。
teamai init 会自动下载工蜂 CLI gf 到 ~/.teamai/gf/,然后运行 gf auth login(支持 iOA SSO / 浏览器 device code / 手动 token)。登录后 token 存在 ~/.netrc,所有后续 git 操作自动带上。
TGit 支持 group/subgroup/repo 这种多级路径(GitHub 不支持),provider 里有专门的路径处理逻辑:
https://git.woa.com/Group/Subgroup/repo
git@git.woa.com:Group/Subgroup/repo.git
TGit 会把 git commit email 默认配置为 <username>@tencent.com。GitHub Provider 不设默认域(让用户的全局 git 配置生效)。
除了 URL 自动检测,也可以在 team 仓库的 teamai.yaml 中显式写 provider: github 或 provider: tgit 强制切换。一个典型的 teamai.yaml:
team: my-team
scope: user
description: TeamAI shared resources
repo: https://github.com/yourorg/yourrepo.git
provider: github
reviewers:
- alice
- bobProvider 是一个 TypeScript 接口(见 src/providers/types.ts),新增 GitLab / Bitbucket / Gitea 等只需要:
- 新建
src/providers/<name>/目录 - 实现
GitProvider接口:parseRepoInput/authenticate/cloneRepo/createRepo/createPullRequest/getDefaultEmailDomain - 在
src/providers/registry.ts的HOST_MAP和PROVIDERS中注册 - 写单元测试,参考
src/__tests__/github-provider.test.ts
PR 欢迎。