gitlab

package
v0.0.0-...-9e01db0 Latest Latest
Warning

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

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

Documentation

Overview

Package gitlab 提供 GitLab 客户端功能,支持多个 GitLab 实例

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProjectPath

func ParseProjectPath(repoURL string) (string, error)

ParseProjectPath 从仓库 URL 解析出项目路径(path_with_namespace)

Types

type BranchInfo

type BranchInfo struct {
	Name string `json:"name"`
}

BranchInfo 分支信息

type GetBlobResp

type GetBlobResp struct {
	Content  []byte `json:"content"`
	IsBinary bool   `json:"is_binary"`
	Sha      string `json:"sha"`
	Size     int    `json:"size"`
}

GetBlobResp 获取单文件内容响应

type GetGitLogsResp

type GetGitLogsResp struct {
	Count   int               `json:"count"`
	Entries []*GitCommitEntry `json:"entries"`
}

GetGitLogsResp 获取提交历史响应

type GetRepoArchiveResp

type GetRepoArchiveResp struct {
	ContentLength int64
	ContentType   string
	Reader        io.ReadCloser
}

GetRepoArchiveResp 获取仓库压缩包响应

type GetRepoTreeResp

type GetRepoTreeResp struct {
	Entries []*TreeEntry `json:"entries"`
	SHA     string       `json:"sha"`
}

GetRepoTreeResp 获取仓库文件树响应

type GitCommit

type GitCommit struct {
	Author     *GitUser `json:"author"`
	Committer  *GitUser `json:"committer"`
	Message    string   `json:"message"`
	ParentShas []string `json:"parent_shas"`
	Sha        string   `json:"sha"`
	TreeSha    string   `json:"tree_sha"`
}

GitCommit 提交信息

type GitCommitEntry

type GitCommitEntry struct {
	Commit *GitCommit `json:"commit"`
}

GitCommitEntry 包装 commit 对象

type GitUser

type GitUser struct {
	Email string `json:"email"`
	Name  string `json:"name"`
	When  int64  `json:"when"`
}

GitUser 提交用户信息

type Gitlab

type Gitlab struct {
	*gitlab.Client
	// contains filtered or unexported fields
}

Gitlab 客户端

func NewGitlab

func NewGitlab(baseURL, token string, logger *slog.Logger) *Gitlab

NewGitlab 根据 baseURL 和 token 创建 GitLab 客户端

func NewGitlabForBaseURL

func NewGitlabForBaseURL(baseURL string, logger *slog.Logger) *Gitlab

NewGitlabForBaseURL 根据任意 base_url 创建 GitLab 客户端(无默认 token)

func (*Gitlab) Archive

Archive 实现 GitPlatformClient 接口

func (*Gitlab) BaseURL

func (g *Gitlab) BaseURL() string

BaseURL 返回 GitLab base URL

func (*Gitlab) Blob

func (g *Gitlab) Blob(ctx context.Context, opts *domain.BlobOptions) (*domain.GetBlobResp, error)

Blob 实现 GitPlatformClient 接口

func (*Gitlab) Branches

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

Branches 实现 GitPlatformClient 接口

func (*Gitlab) CheckPAT

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

CheckPAT 校验 PAT

func (*Gitlab) CreateProjectWebhook

func (g *Gitlab) CreateProjectWebhook(ctx context.Context, token, repoURL, webhookURL, secretToken string, isOAuth bool) error

CreateProjectWebhook 在 GitLab 项目上注册 webhook

func (*Gitlab) CreateWebhook

func (g *Gitlab) CreateWebhook(ctx context.Context, opts *domain.CreateWebhookOptions) error

CreateWebhook 实现 GitPlatformClient 接口

func (*Gitlab) DeleteWebhook

func (g *Gitlab) DeleteWebhook(ctx context.Context, opts *domain.WebhookOptions) error

DeleteWebhook 实现 GitPlatformClient 接口

func (*Gitlab) DeleteWebhookByURL

func (g *Gitlab) DeleteWebhookByURL(ctx context.Context, token, repoURL, webhookURL string, isOAuth bool) error

DeleteWebhookByURL 根据 webhook URL 精确匹配删除 GitLab 项目上的 webhook

func (*Gitlab) GetAuthorizedRepositories

func (g *Gitlab) GetAuthorizedRepositories(ctx context.Context, token string) ([]domain.AuthRepository, error)

GetAuthorizedRepositories 获取 token 可访问的仓库列表

func (*Gitlab) GetBlob

func (g *Gitlab) GetBlob(ctx context.Context, token, projectPath, ref, path string, isOAuth bool) (*GetBlobResp, error)

GetBlob 获取单文件内容

func (*Gitlab) GetGitLogs

func (g *Gitlab) GetGitLogs(ctx context.Context, token, projectPath, ref, path string, limit, offset int, isOAuth bool) (*GetGitLogsResp, error)

GetGitLogs 获取提交历史

func (*Gitlab) GetRepoArchive

func (g *Gitlab) GetRepoArchive(ctx context.Context, token, projectPath, ref string, isOAuth bool) (*GetRepoArchiveResp, error)

GetRepoArchive 获取仓库压缩包

func (*Gitlab) GetRepoDescription

func (g *Gitlab) GetRepoDescription(ctx context.Context, token, repoURL string, isOAuth bool) (string, error)

GetRepoDescription 获取仓库描述

func (*Gitlab) GetRepoInfoByPAT

func (g *Gitlab) GetRepoInfoByPAT(ctx context.Context, token string, repoURL string) (*gitlab.Project, error)

GetRepoInfoByPAT 根据 PAT 获取仓库信息

func (*Gitlab) GetRepoTree

func (g *Gitlab) GetRepoTree(ctx context.Context, token, projectPath, ref, path string, recursive bool, isOAuth bool) (*GetRepoTreeResp, error)

GetRepoTree 获取仓库文件树

func (*Gitlab) GetUserInfoByPAT

func (g *Gitlab) GetUserInfoByPAT(ctx context.Context, token string) (*domain.PlatformUserInfo, error)

GetUserInfoByPAT 根据 PAT 获取用户信息

func (*Gitlab) ListBranches

func (g *Gitlab) ListBranches(ctx context.Context, token, projectPath string, isOAuth bool, page, perPage int) ([]*BranchInfo, error)

ListBranches 获取仓库分支列表

func (*Gitlab) Logs

Logs 实现 GitPlatformClient 接口

func (*Gitlab) Repositories

func (g *Gitlab) Repositories(ctx context.Context, opts *domain.RepositoryOptions) ([]domain.AuthRepository, error)

Repositories 实现 GitPlatformClient 接口

func (*Gitlab) Token

func (g *Gitlab) Token() string

Token 返回 GitLab token

func (*Gitlab) Tree

Tree 实现 GitPlatformClient 接口

func (*Gitlab) UserInfo

func (g *Gitlab) UserInfo(ctx context.Context, token string) (*domain.PlatformUserInfo, error)

UserInfo 实现 GitPlatformClient 接口

type TreeEntry

type TreeEntry struct {
	Mode int    `json:"mode"`
	Name string `json:"name"`
	Path string `json:"path"`
	Sha  string `json:"sha"`
	Size int    `json:"size"`
}

TreeEntry 文件树节点

Jump to

Keyboard shortcuts

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