github

package
v0.0.0-...-481d40d Latest Latest
Warning

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

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

Documentation

Overview

Package github 提供 GitHub 客户端功能(PAT 模式,不含 GitHub App)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 Github

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

Github GitHub 客户端(PAT 模式)

func NewGithub

func NewGithub(logger *slog.Logger, cfg *config.Config) *Github

NewGithub 创建 GitHub 客户端

func (*Github) Archive

Archive 实现 GitPlatformClient 接口

func (*Github) Blob

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

Blob 实现 GitPlatformClient 接口

func (*Github) Branches

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

Branches 实现 GitPlatformClient 接口

func (*Github) CheckPAT

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

CheckPAT 校验 PAT

func (*Github) CreateRepoWebhook

func (g *Github) CreateRepoWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) error

CreateRepoWebhook 在仓库上注册 webhook

func (*Github) CreateWebhook

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

CreateWebhook 实现 GitPlatformClient 接口

func (*Github) DeleteWebhook

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

DeleteWebhook 实现 GitPlatformClient 接口

func (*Github) DeleteWebhookByURL

func (g *Github) DeleteWebhookByURL(ctx context.Context, token, owner, repo, webhookURL string) error

DeleteWebhookByURL 根据 webhook URL 精确匹配删除 GitHub 仓库上的 webhook

func (*Github) GetAuthorizedRepositories

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

GetAuthorizedRepositories 获取可访问的仓库列表 installID > 0 时使用 GitHub App Installation API,否则使用 PAT 的 /user/repos

func (*Github) GetBlob

func (g *Github) GetBlob(ctx context.Context, installID int64, token, owner, repo, ref, path string) (*GetBlobResp, error)

GetBlob 获取单文件内容(PAT 模式)

func (*Github) GetClient

func (g *Github) GetClient(ctx context.Context, token string, installID int64) (*github.Client, error)

GetClient 使用 PAT 或 Installation 创建 GitHub 客户端

func (*Github) GetGitLogs

func (g *Github) GetGitLogs(ctx context.Context, installID int64, token, owner, repo, ref, path string, limit, offset int) (*GetGitLogsResp, error)

GetGitLogs 获取提交历史(PAT 模式)

func (*Github) GetInstallationToken

func (g *Github) GetInstallationToken(ctx context.Context, installID int64) (string, error)

GetInstallationToken 通过 GitHub App 获取 installation access token

func (*Github) GetRepoArchive

func (g *Github) GetRepoArchive(ctx context.Context, installID int64, token, owner, repo, ref string) (*GetRepoArchiveResp, error)

GetRepoArchive 获取仓库压缩包(PAT 模式)

func (*Github) GetRepoDescription

func (g *Github) GetRepoDescription(ctx context.Context, token, owner, repo string) (string, error)

GetRepoDescription 获取仓库描述(PAT 模式)

func (*Github) GetRepoInfoByPAT

func (g *Github) GetRepoInfoByPAT(ctx context.Context, token string, repoURL string) (*github.Repository, error)

GetRepoInfoByPAT 根据 PAT 获取仓库信息

func (*Github) GetRepoTree

func (g *Github) GetRepoTree(ctx context.Context, installID int64, token, owner, repo, ref, path string, recursive bool) (*GetRepoTreeResp, error)

GetRepoTree 获取仓库文件树(Installation App 模式优先)

func (*Github) GetUserInfoByPAT

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

GetUserInfoByPAT 根据 PAT 获取用户信息

func (*Github) ListBranches

func (g *Github) ListBranches(ctx context.Context, installID int64, token, owner, repo string, page, perPage int) ([]*BranchInfo, error)

ListBranches 获取仓库分支列表(Installation App 模式优先)

func (*Github) ListInstallationRepos

func (g *Github) ListInstallationRepos(ctx context.Context, installID int64) ([]*github.Repository, error)

func (*Github) Logs

Logs 实现 GitPlatformClient 接口

func (*Github) Repositories

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

Repositories 实现 GitPlatformClient 接口

func (*Github) Tree

Tree 实现 GitPlatformClient 接口

func (*Github) UserInfo

func (g *Github) 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"`
	LastModifiedAt int64  `json:"last_modified_at"`
}

TreeEntry 文件树节点

Jump to

Keyboard shortcuts

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