atomgit

package
v0.0.0-...-49f9320 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

View Source
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

func ParseRepoPath(repoURL string) (owner, repo string, err error)

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

func NewAtomgit(baseURL string, logger *slog.Logger) *Atomgit

NewAtomgit 创建 atomgit 客户端。

func (*Atomgit) Archive

Archive 实现 GitClienter 接口。

atomgit OpenAPI 暂未提供仓库归档下载入口, 返回未实现错误。

func (*Atomgit) BaseURL

func (a *Atomgit) BaseURL() string

BaseURL 返回 OpenAPI base URL

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

func (a *Atomgit) CreateWebhook(ctx context.Context, opts *domain.CreateWebhookOptions) error

CreateWebhook 实现 GitClienter 接口。

atomgit OpenAPI 暂未提供 webhook 管理接口, 自动 review 暂不可用 (需用户在仓库设置页手工配置)。 同 CNB 的处理方式: Create 返回未实现错误, Delete 走 no-op 让"解绑"动作不至于失败。

func (*Atomgit) DeleteWebhook

func (a *Atomgit) DeleteWebhook(ctx context.Context, opts *domain.WebhookOptions) error

DeleteWebhook 实现 GitClienter 接口。

func (*Atomgit) Logs

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

Tree 实现 GitClienter 接口。

GET /api/v5/repos/{owner}/{repo}/git/trees/{sha} 返回 sha 所指 tree 的子项数组 (Gitee 风格, 路径里多一段 `/git/`)。{sha} 可以是分支名或 commit sha。 调用方传 Recursive=true 时透传 ?recursive=1。

兼容两种响应形态:

func (*Atomgit) UserInfo

func (a *Atomgit) UserInfo(ctx context.Context, token string) (*domain.PlatformUserInfo, error)

UserInfo 实现 GitClienter 接口。

GET /api/v5/user 返回当前用户详情。

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

type TreeResp struct {
	SHA  string      `json:"sha,omitempty"`
	Tree []*TreeNode `json:"tree,omitempty"`
}

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。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL