Documentation
¶
Overview ¶
Package atomgit 提供 atomgit (https://atomgit.com) 客户端。
鉴权: HTTP Header `Authorization: Bearer <token>`, PAT 和 OAuth access_token 共用此格式。 所有 OpenAPI 调用走 https://api.atomgit.com + `/api/v5/` 前缀 (后端复用 GitCode/Gitee 那套, 跟 docs.atomgit.com 上写的裸路径文档对不上)。仓库以 {owner}/{repo} 两段路径定位。
Index ¶
- Constants
- func ParseRepoPath(repoURL string) (owner, repo string, err error)
- type Atomgit
- func (a *Atomgit) Archive(ctx context.Context, opts *domain.ArchiveOptions) (*domain.GetRepoArchiveResp, error)
- func (a *Atomgit) BaseURL() string
- func (a *Atomgit) Blob(ctx context.Context, opts *domain.BlobOptions) (*domain.GetBlobResp, error)
- func (a *Atomgit) Branches(ctx context.Context, opts *domain.BranchesOptions) ([]*domain.BranchInfo, error)
- func (a *Atomgit) CheckPAT(ctx context.Context, token, repoURL string) (bool, *domain.BindRepository, error)
- func (a *Atomgit) CreateWebhook(ctx context.Context, opts *domain.CreateWebhookOptions) error
- func (a *Atomgit) DeleteWebhook(ctx context.Context, opts *domain.WebhookOptions) error
- func (a *Atomgit) Logs(ctx context.Context, opts *domain.LogsOptions) (*domain.GetGitLogsResp, error)
- func (a *Atomgit) Repositories(ctx context.Context, opts *domain.RepositoryOptions) (*domain.RepositoryPage, error)
- func (a *Atomgit) Tree(ctx context.Context, opts *domain.TreeOptions) (*domain.GetRepoTreeResp, error)
- func (a *Atomgit) UserInfo(ctx context.Context, token string) (*domain.PlatformUserInfo, error)
- type Branch
- type CommitSummary
- type Content
- type ContentItem
- type Repository
- type TreeNode
- type TreeResp
- type User
Constants ¶
const ( DefaultAPIHost = "api.atomgit.com" DefaultWebHost = "atomgit.com" // APIPrefix atomgit OpenAPI 全部路径前缀 // // 官方文档站 (docs.atomgit.com) 写的是裸路径 (如 /user/info、/repos/:o/:r), // 但实际部署的后端是 GitCode (Gitee fork), 必须用 /api/v5/ 前缀。亲测: // GET /user/info → 404 openresty // GET /api/v5/user → 200 {login,name,id,avatar_url,...} // 后端返回的 self URL (followers_url 等) 也都带 /api/v5/。 APIPrefix = "/api/v5" )
默认 OpenAPI 域名 (atomgit 后台共用 GitCode 基础设施)
Variables ¶
This section is empty.
Functions ¶
func ParseRepoPath ¶
ParseRepoPath 从仓库 URL 解析出 owner / repo。
支持以下形式:
https://atomgit.com/{owner}/{repo}.git
https://atomgit.com/{owner}/{repo}
git@atomgit.com:{owner}/{repo}.git
Types ¶
type Atomgit ¶
type Atomgit struct {
// contains filtered or unexported fields
}
Atomgit 客户端
func NewAtomgit ¶
NewAtomgit 创建 atomgit 客户端。
- baseURL: OpenAPI 域名 (含 scheme), 空则使用默认 https://api.atomgit.com
func (*Atomgit) Archive ¶
func (a *Atomgit) Archive(ctx context.Context, opts *domain.ArchiveOptions) (*domain.GetRepoArchiveResp, error)
Archive 实现 GitClienter 接口。
atomgit OpenAPI 暂未提供仓库归档下载入口, 返回未实现错误。
func (*Atomgit) Blob ¶
func (a *Atomgit) Blob(ctx context.Context, opts *domain.BlobOptions) (*domain.GetBlobResp, error)
Blob 实现 GitClienter 接口。
GET /api/v5/repos/{owner}/{repo}/contents/{path}?ref=... 返回 Content{type=file, content=base64}。 对 type=dir / symlink / submodule 给出空响应; type=file 时按 encoding 解码。
func (*Atomgit) Branches ¶
func (a *Atomgit) Branches(ctx context.Context, opts *domain.BranchesOptions) ([]*domain.BranchInfo, error)
Branches 实现 GitClienter 接口。
GET /api/v5/repos/{owner}/{repo}/branches?page=&per_page=
func (*Atomgit) CheckPAT ¶
func (a *Atomgit) CheckPAT(ctx context.Context, token, repoURL string) (bool, *domain.BindRepository, error)
CheckPAT 校验 token (PAT 或 OAuth access_token) 对指定仓库的可访问性。
通过 GET /api/v5/repos/{owner}/{repo} 验证。
func (*Atomgit) CreateWebhook ¶
CreateWebhook 实现 GitClienter 接口。
atomgit OpenAPI 暂未提供 webhook 管理接口, 自动 review 暂不可用 (需用户在仓库设置页手工配置)。 同 CNB 的处理方式: Create 返回未实现错误, Delete 走 no-op 让"解绑"动作不至于失败。
func (*Atomgit) DeleteWebhook ¶
DeleteWebhook 实现 GitClienter 接口。
func (*Atomgit) Logs ¶
func (a *Atomgit) Logs(ctx context.Context, opts *domain.LogsOptions) (*domain.GetGitLogsResp, error)
Logs 实现 GitClienter 接口。
atomgit OpenAPI 暂未提供「commit 列表」入口 (仅有 GET /repos/:o/:r/commits/{ref} 拿单条), 这里返回未实现错误。当前业务调用方 (project tree/logs) 已无前端入口, 不影响功能。
func (*Atomgit) Repositories ¶
func (a *Atomgit) Repositories(ctx context.Context, opts *domain.RepositoryOptions) (*domain.RepositoryPage, error)
Repositories 列出当前 token 所属用户可访问的仓库。
走 GET /api/v5/user/repos (Gitee 风格, 拿当前 token 用户的全部仓库, 包括所属组织的仓库)。上限 50 页 = 5000 个仓库。
func (*Atomgit) Tree ¶
func (a *Atomgit) Tree(ctx context.Context, opts *domain.TreeOptions) (*domain.GetRepoTreeResp, error)
Tree 实现 GitClienter 接口。
GET /api/v5/repos/{owner}/{repo}/git/trees/{sha} 返回 sha 所指 tree 的子项数组 (Gitee 风格, 路径里多一段 `/git/`)。{sha} 可以是分支名或 commit sha。 调用方传 Recursive=true 时透传 ?recursive=1。
兼容两种响应形态:
type Branch ¶
type Branch struct {
Name string `json:"name,omitempty"`
Protected bool `json:"protected,omitempty"`
Commit *CommitSummary `json:"commit,omitempty"`
}
Branch 分支信息 (GET /repos/:o/:r/branches)
type CommitSummary ¶
type CommitSummary struct {
SHA string `json:"sha,omitempty"`
}
CommitSummary 分支挂载的提交摘要
type Content ¶
type Content struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
SHA string `json:"sha,omitempty"`
Size int64 `json:"size,omitempty"`
Type string `json:"type,omitempty"`
Encoding string `json:"encoding,omitempty"` // base64
Content string `json:"content,omitempty"`
Entries []*ContentItem `json:"entries,omitempty"`
}
Content 仓库文件或目录内容 (GET /repos/:o/:r/contents/{path})
type 枚举: file / dir / symlink / submodule
- type=file 时 content 为 base64, entries 为空数组
- type=dir 时 entries 列出子项, content 为空
type ContentItem ¶
type ContentItem struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
SHA string `json:"sha,omitempty"`
Size int64 `json:"size,omitempty"`
Type string `json:"type,omitempty"`
Encoding string `json:"encoding,omitempty"`
}
ContentItem dir 类型 Content 的 entries 元素 (与 Content 同形,只是不带 entries)
type Repository ¶
type Repository struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
FullName string `json:"full_name,omitempty"`
Description string `json:"description,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
Private bool `json:"private,omitempty"`
SSHURL string `json:"ssh_url_to_repo,omitempty"` // SSH clone URL
HTTPURL string `json:"http_url_to_repo,omitempty"` // HTTP clone URL
WebURL string `json:"web_url,omitempty"` // 浏览器访问的页面 URL
}
Repository 仓库信息 (GET /api/v5/repos/:o/:r 与 /api/v5/user/repos 元素结构一致)
亲测响应:
{"id":10085664,"full_name":"caiqj/test","name":"test","path":"test",
"description":"","ssh_url_to_repo":"git@gitcode.com:caiqj/test.git",
"http_url_to_repo":"https://atomgit.com/caiqj/test.git",
"web_url":"https://atomgit.com/caiqj/test","default_branch":"...","private":...}
id 是 int64; clone/web URL 三个字段都是 _to_repo / web_url 风格 (Gitee 命名)。
type TreeNode ¶
type TreeNode struct {
Mode string `json:"mode,omitempty"`
Path string `json:"path,omitempty"`
SHA string `json:"sha,omitempty"`
Type string `json:"type,omitempty"`
Size int64 `json:"size,omitempty"`
}
TreeNode 文件树节点 (GET /repos/:o/:r/trees/:sha)
type 枚举: blob / tree / symlink / commit
type TreeResp ¶
TreeResp GET /repos/:o/:r/trees/:sha 响应外层
atomgit 的 trees 接口实际返回是数组形态还是带 `tree` 字段的对象, 文档没给完整 sample。为兼容两种形态:
- 数组形态:由 Tree() 自行 fallback 反序列化为 []TreeNode
- 对象形态:这里给出 sha + tree 字段方便复用
type User ¶
type User struct {
Login string `json:"login,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
}
User 用户信息 (GET /api/v5/user)
字段以亲测响应为准: {login, name, id, avatar_url, html_url, type, url, bio, blog, company, ...}。 id 是字符串形态 (类似 MongoDB ObjectId, 如 "676a6cbb75ce0a14eb004d1c"), 不是 int。