codeup

package
v0.0.0-...-1ac778f Latest Latest
Warning

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

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

Documentation

Overview

Package codeup 提供阿里云云效 Codeup 客户端。

鉴权:HTTP Header `x-yunxiao-token: <PAT 或 OAuth access_token>`,统一走云效 OpenAPI(公共站 openapi-rdc.aliyuncs.com)。绝大多数接口需要 organizationId 路径参数。

Index

Constants

View Source
const DefaultOpenAPIHost = "openapi-rdc.aliyuncs.com"

默认 OpenAPI 域名(公网公共站)

Variables

This section is empty.

Functions

func ParseRepoPath

func ParseRepoPath(repoURL string) (orgID, identity string, err error)

ParseRepoPath 从仓库 URL 解析 orgId 和 repo 标识(groupPath/repoName)。 支持以下形式:

https://codeup.aliyun.com/{orgId}/{group}/{repo}.git
https://codeup.aliyun.com/{orgId}/{group}/{repo}
git@codeup.aliyun.com:{orgId}/{group}/{repo}.git
https://{orgId}.codeup.aliyun.com/{group}/{repo}.git

Types

type Branch

type Branch struct {
	Name      string         `json:"name,omitempty"`
	Protected bool           `json:"protected,omitempty"`
	Commit    *CommitSummary `json:"commit,omitempty"`
}

Branch 分支

type Codeup

type Codeup struct {
	// contains filtered or unexported fields
}

Codeup 客户端

func NewCodeup

func NewCodeup(openapiBase, orgID string, logger *slog.Logger) *Codeup

NewCodeup 创建 Codeup 客户端。

  • openapiBase: OpenAPI 域名(包含 scheme),空则使用默认 https://openapi-rdc.aliyuncs.com
  • orgID: 组织 ID,可为空(CheckPAT / UserInfo / 自动解析时无需提前知道)

func (*Codeup) Archive

Archive 实现 GitClienter 接口

云效 Codeup 不提供归档下载接口,前端也未调用,这里返回未实现错误以满足接口约定。

func (*Codeup) BaseURL

func (c *Codeup) BaseURL() string

BaseURL 返回 OpenAPI base URL

func (*Codeup) Blob

func (c *Codeup) Blob(ctx context.Context, opts *domain.BlobOptions) (*domain.GetBlobResp, error)

Blob 实现 GitClienter 接口

Codeup 文件内容接口:GET /oapi/v1/codeup/organizations/{orgId}/repositories/{repoIdent}/files/{filePath} filePath 走 path 段,需要 URL-encode(含把 / 编成 %2F);ref 是必填 query。

func (*Codeup) Branches

func (c *Codeup) Branches(ctx context.Context, opts *domain.BranchesOptions) ([]*domain.BranchInfo, error)

Branches 实现 GitClienter 接口

func (*Codeup) CheckPAT

func (c *Codeup) CheckPAT(ctx context.Context, token, repoURL string) (bool, *domain.BindRepository, error)

CheckPAT 校验 PAT。先解析 repoURL 得到 orgId + identity,再调 OpenAPI 验证可访问。

func (*Codeup) CreateWebhook

func (c *Codeup) CreateWebhook(ctx context.Context, opts *domain.CreateWebhookOptions) error

CreateWebhook 实现 GitClienter 接口

Codeup webhook 接口:POST /oapi/v1/codeup/organizations/{orgId}/repositories/{repoIdent}/webhooks

func (*Codeup) DeleteWebhook

func (c *Codeup) DeleteWebhook(ctx context.Context, opts *domain.WebhookOptions) error

DeleteWebhook 实现 GitClienter 接口

func (*Codeup) GetRepoByIdentity

func (c *Codeup) GetRepoByIdentity(ctx context.Context, token, orgID, identity string) (*Repository, error)

GetRepoByIdentity 根据 group/repo 标识获取仓库信息

func (*Codeup) ListOrganizations

func (c *Codeup) ListOrganizations(ctx context.Context, token string) ([]*OrganizationItem, error)

ListOrganizations 列出 PAT 所属的全部云效组织。

GET /oapi/v1/platform/organizations
Header: x-yunxiao-token

中心版/标准版均支持 PAT 调用,返回结构为 [{id, name, ...}]。

func (*Codeup) Logs

Logs 实现 GitClienter 接口

Codeup commits 接口:GET /oapi/v1/codeup/organizations/{orgId}/repositories/{repoIdent}/commits query: refName, path, page, perPage

func (*Codeup) OrgID

func (c *Codeup) OrgID() string

OrgID 返回当前默认组织 ID(可能为空)

func (*Codeup) Repositories

func (c *Codeup) Repositories(ctx context.Context, opts *domain.RepositoryOptions) (*domain.RepositoryPage, error)

Repositories 列出当前用户在组织内可访问的仓库(暂不支持服务端分页,始终返回全量)

func (*Codeup) ResolveOrgID

func (c *Codeup) ResolveOrgID(ctx context.Context, token string) (string, error)

ResolveOrgID 取 PAT 所属的第一个组织的 ID。

多组织时只取第一个;用户若希望使用另一组织,可在编辑身份时手动覆盖 organization_id。

func (*Codeup) Tree

Tree 实现 GitClienter 接口

Codeup 文件树接口:GET /oapi/v1/codeup/organizations/{orgId}/repositories/{repoIdent}/files/tree query: ref=branch, path=subdir, type=DIRECT|RECURSIVE|FLATTEN

响应是 TreeNode 数组(当前目录或递归目录下的所有节点)。

func (*Codeup) UserInfo

func (c *Codeup) UserInfo(ctx context.Context, token string) (*domain.PlatformUserInfo, error)

UserInfo 实现 GitClienter 接口。

云效 OpenAPI 没有提供仅凭 PAT 获取当前用户的接口(GetCurrentUser 系列均不存在)。 此处返回空名以满足接口约定;调用方需要时应当从 GitIdentity.Username 字段读取用户绑定时填写的名字。

type CommitItem

type CommitItem struct {
	ID             string       `json:"id,omitempty"`
	ShortID        string       `json:"shortId,omitempty"`
	Title          string       `json:"title,omitempty"`
	Message        string       `json:"message,omitempty"`
	ParentIDs      []string     `json:"parentIds,omitempty"`
	AuthorName     string       `json:"authorName,omitempty"`
	AuthorEmail    string       `json:"authorEmail,omitempty"`
	AuthoredDate   string       `json:"authoredDate,omitempty"`
	CommitterName  string       `json:"committerName,omitempty"`
	CommitterEmail string       `json:"committerEmail,omitempty"`
	CommittedDate  string       `json:"committedDate,omitempty"`
	Stats          *CommitStats `json:"stats,omitempty"`
	WebURL         string       `json:"webUrl,omitempty"`
}

CommitItem 完整提交信息

type CommitStats

type CommitStats struct {
	Additions int `json:"additions,omitempty"`
	Deletions int `json:"deletions,omitempty"`
	Total     int `json:"total,omitempty"`
}

CommitStats 提交变更行数统计

type CommitSummary

type CommitSummary struct {
	ID         string `json:"id,omitempty"`
	ShortID    string `json:"shortId,omitempty"`
	Title      string `json:"title,omitempty"`
	AuthoredAt string `json:"authoredDate,omitempty"`
}

CommitSummary 分支挂载的提交摘要

type FileBlob

type FileBlob struct {
	FileName     string      `json:"fileName,omitempty"`
	FilePath     string      `json:"filePath,omitempty"`
	Size         flexibleInt `json:"size,omitempty"`
	Encoding     string      `json:"encoding,omitempty"` // base64 / text
	Content      string      `json:"content,omitempty"`
	CommitID     string      `json:"commitId,omitempty"`
	LastCommitID string      `json:"lastCommitId,omitempty"`
	Ref          string      `json:"ref,omitempty"`
	BlobID       string      `json:"blobId,omitempty"`
}

FileBlob 文件内容

注意:云效返回的 size 字段有时是字符串(如 "1666"),有时是数字,用 flexibleInt 兼容。

type OrganizationItem

type OrganizationItem struct {
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	CreatorID   string `json:"creatorId,omitempty"`
	DefaultRole string `json:"defaultRole,omitempty"`
	CreatedAt   string `json:"createdAt,omitempty"`
	UpdateAt    string `json:"updateAt,omitempty"`
}

OrganizationItem 云效组织条目(来自 /oapi/v1/platform/organizations)

type Repository

type Repository struct {
	ID            int64    `json:"id,omitempty"`
	Name          string   `json:"name,omitempty"`
	Path          string   `json:"path,omitempty"`
	NameWithNs    string   `json:"nameWithNamespace,omitempty"`
	PathWithNs    string   `json:"pathWithNamespace,omitempty"`
	Description   string   `json:"description,omitempty"`
	Visibility    string   `json:"visibility,omitempty"` // private / internal
	WebURL        string   `json:"webUrl,omitempty"`
	HTTPCloneURL  string   `json:"httpCloneUrl,omitempty"`
	SSHCloneURL   string   `json:"sshCloneUrl,omitempty"`
	DefaultBranch string   `json:"defaultBranch,omitempty"`
	Permissions   []string `json:"permissions,omitempty"`
	Archived      bool     `json:"archived,omitempty"`
}

Repository 仓库信息

字段以「查询代码库列表」文档为准;HTTPCloneURL / SSHCloneURL / DefaultBranch / Permissions 在列表接口里不一定出现,但「查询单个代码库」可能返回,保留为可选字段不影响反序列化。

type TreeNode

type TreeNode struct {
	ID    string `json:"id,omitempty"`
	Name  string `json:"name,omitempty"`
	Type  string `json:"type,omitempty"` // tree / blob / commit
	Path  string `json:"path,omitempty"`
	Mode  string `json:"mode,omitempty"`
	IsLFS bool   `json:"isLFS,omitempty"`
}

TreeNode 文件树节点

type WebhookItem

type WebhookItem struct {
	ID          int64  `json:"id,omitempty"`
	URL         string `json:"url,omitempty"`
	Description string `json:"description,omitempty"`
}

WebhookItem 仓库 webhook

Jump to

Keyboard shortcuts

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