Help us shape the future of Go! Take the 2026 Go Developer Survey

service

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRepoNotFound is returned when a repository is not found.
	ErrRepoNotFound = errors.New("repo not found")

	// ErrTaskNotFound is returned when a sync task is not found.
	ErrTaskNotFound = errors.New("task not found")

	// ErrTaskDisabled is returned when attempting to run a disabled task.
	ErrTaskDisabled = errors.New("task is disabled")

	// ErrTaskRunning is returned when a task is already executing (concurrent run skipped).
	ErrTaskRunning = errors.New("task is already running")

	// ErrTooManyConcurrent is returned when the global concurrency limit is reached.
	ErrTooManyConcurrent = errors.New("too many concurrent sync tasks")

	// ErrRuleNotFound is returned when a webhook rule is not found.
	ErrRuleNotFound = errors.New("rule not found")

	// ErrEventNotFound is returned when a webhook event is not found.
	ErrEventNotFound = errors.New("event not found")
)

Functions

func ClearGitHubAppTokenCache added in v0.6.0

func ClearGitHubAppTokenCache()

ClearGitHubAppTokenCache 清空缓存(测试用)。

func FetchGitHubInstallationToken added in v0.6.0

func FetchGitHubInstallationToken(ctxTimeout time.Duration, apiBase string, appID, installationID int64, privateKeyPEM string) (string, error)

FetchGitHubInstallationToken 用 JWT 换 installation access token。

func IsPersonalOwner added in v0.7.0

func IsPersonalOwner(owner, targetUser string, orgOwners map[string]bool) bool

IsPersonalOwner 粗判:与 known org 集合无关时,调用方可传 org 列表。 默认把「等于 targetUser」或调用方标注的 personal 作为个人仓。

func MintGitHubAppJWT added in v0.6.0

func MintGitHubAppJWT(appID int64, privateKeyPEM string) (string, error)

MintGitHubAppJWT 用 App 私钥签发 JWT(RS256),iss=app_id,有效期最长 10 分钟。 这是 GitHub App 调 API 的第一层凭证,再换 installation access token。

func ResolveOrgTarget added in v0.7.0

func ResolveOrgTarget(strategy OrgMapStrategy, sourceOwner, sourceRepo, targetOrg, targetUser string, sourceIsPersonal bool) (owner, repo string)

ResolveOrgTarget 计算目标 owner/repo。

sourceOwner/sourceRepo 为源路径;targetOrg 用于 single(也可作 mixed 的组织落点);
targetUser 用于 flat。preserve 时若 targetOrg 非空则整体替换 owner。

func ResolvePlatformToken added in v0.6.0

func ResolvePlatformToken(p *model.Platform) (string, error)

ResolvePlatformToken 解析平台实际使用的访问令牌。 优先级:GitHub App installation token(若配置) > AccessToken。 App token 带缓存,过期前自动刷新。

func ValidForcePushPolicy added in v0.6.0

func ValidForcePushPolicy(p string) bool

ValidForcePushPolicy 校验策略字符串。

func ValidOrgMapStrategy added in v0.7.0

func ValidOrgMapStrategy(s string) bool

ValidOrgMapStrategy 校验策略。

Types

type AuditChainResult added in v0.6.0

type AuditChainResult struct {
	OK       bool   `json:"ok"`
	Checked  int    `json:"checked"`
	BrokenAt uint   `json:"broken_at,omitempty"`
	Message  string `json:"message"`
}

AuditChainResult 审计哈希链校验结果。

type AutoDiscoverOptions added in v0.6.0

type AutoDiscoverOptions struct {
	// ImportNew=true 时直接导入新仓库,否则只报告
	ImportNew bool
	Filter    *RepoImportFilter
}

AutoDiscoverOptions 自动发现参数。

type BackupManifest added in v0.6.0

type BackupManifest = executor.BackupManifest

BackupManifest = executor.BackupManifest

type BundleInfo added in v0.5.1

type BundleInfo = executor.BundleInfo

BundleInfo bundle 文件信息(executor 同构,便于壳层直接用)。

type Config

type Config = model.Config

type CreateMirrorChannelInput

type CreateMirrorChannelInput struct {
	Name    string              `json:"name"`
	Mode    string              `json:"mode"`
	RepoKey string              `json:"repoKey"`
	Targets []MirrorTargetInput `json:"targets"`
}

type DiscoveryReport added in v0.6.0

type DiscoveryReport struct {
	PlatformKey string    `json:"platform_key"`
	ScannedAt   time.Time `json:"scanned_at"`
	Found       int       `json:"found"`
	Existing    int       `json:"existing"`
	NewRepos    []string  `json:"new_repos"`
	Imported    int       `json:"imported"`
	Warnings    []string  `json:"warnings,omitempty"`
}

DiscoveryReport 自动发现结果。

type DriftItem added in v0.6.0

type DriftItem struct {
	TaskKey     string `json:"task_key"`
	RepoKey     string `json:"repo_key"`
	Branch      string `json:"branch"`
	LocalRef    string `json:"local_ref"`
	RemoteRef   string `json:"remote_ref,omitempty"`
	Drifted     bool   `json:"drifted"`
	LocalAhead  int    `json:"local_ahead"`
	RemoteAhead int    `json:"remote_ahead"`
	Message     string `json:"message"`
}

DriftItem 单个仓库的漂移检测结果。

type DriftReport added in v0.6.0

type DriftReport struct {
	Generated time.Time   `json:"generated"`
	Checked   int         `json:"checked"`
	Drifted   int         `json:"drifted"`
	Items     []DriftItem `json:"items"`
	Warnings  []string    `json:"warnings,omitempty"`
}

DriftReport 漂移检测汇总。

type DrillHistoryEntry added in v0.6.0

type DrillHistoryEntry = executor.DrillHistoryEntry

DrillHistoryEntry = executor.DrillHistoryEntry

type DrillReport added in v0.6.0

type DrillReport = executor.DrillReport

DrillReport = executor.DrillReport(壳层直接使用)

type ExecuteMirrorRunInput

type ExecuteMirrorRunInput struct {
	TargetID       uint     `json:"targetId"`
	Tags           []string `json:"tags"`
	AllowOverwrite bool     `json:"allowOverwrite"`
	// Kind 省略时为 publish。
	Kind string `json:"kind"`
	// Module/Version 供 verify 类别使用。
	Version string `json:"-"`
}

type ForcePushPolicy added in v0.6.0

type ForcePushPolicy string

ForcePushPolicy 强制推送保护策略。

const (
	// ForcePushAllow 允许强制覆盖(原 keep_divergent=false 行为)
	ForcePushAllow ForcePushPolicy = "allow"
	// ForcePushBlock 遇分歧直接失败,不覆盖
	ForcePushBlock ForcePushPolicy = "block"
	// ForcePushBackupOnDemand 覆盖前自动打 bundle 快照(可回滚)
	ForcePushBackupOnDemand ForcePushPolicy = "backup_on_demand"
)

func ResolveForcePushPolicy added in v0.6.0

func ResolveForcePushPolicy(t *model.SyncTask) ForcePushPolicy

ResolveForcePushPolicy 从任务配置解析策略。 优先 task.ForcePushPolicy;否则按 keep_divergent 兼容映射。

type ManifestVerifyResult added in v0.6.0

type ManifestVerifyResult = executor.ManifestVerifyResult

ManifestVerifyResult = executor.ManifestVerifyResult

type MirrorService

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

MirrorService 镜像通道编排:通道 CRUD、源仓库本地克隆管理、 预检/执行/验证,底层调用 git-ferry-core/mirror。

func NewMirrorService

func NewMirrorService(svc *Service, db *gorm.DB) (*MirrorService, error)

func (*MirrorService) CreateMirrorChannel

func (m *MirrorService) CreateMirrorChannel(ctx context.Context, in CreateMirrorChannelInput) (*model.MirrorChannel, error)

CreateMirrorChannel 创建通道。publish 模式会先拉取源仓库并读取 go.mod, 提前暴露仓库不可达 / module 缺失 / 目标身份相同等问题。

func (*MirrorService) DeleteMirrorChannel

func (m *MirrorService) DeleteMirrorChannel(confirm string, id uint) error

func (*MirrorService) DeleteMirrorTarget

func (m *MirrorService) DeleteMirrorTarget(targetID uint) error

func (*MirrorService) ExecuteMirrorRun

func (m *MirrorService) ExecuteMirrorRun(ctx context.Context, channelID uint, in ExecuteMirrorRunInput) (*model.MirrorRun, error)

ExecuteMirrorRun 创建并异步执行一条镜像 run。同一通道同时只允许一个 进行中的执行(含预检外的写操作),避免克隆目录竞争。

func (*MirrorService) GetMirrorChannel

func (m *MirrorService) GetMirrorChannel(id uint) (*model.MirrorChannel, error)

func (*MirrorService) GetMirrorRun

func (m *MirrorService) GetMirrorRun(id uint) (*model.MirrorRun, error)

GetMirrorRun 单条执行记录详情。

func (*MirrorService) GetMirrorVersions

func (m *MirrorService) GetMirrorVersions(ctx context.Context, channelID uint) (*MirrorVersionsResult, error)

GetMirrorVersions 通道版本矩阵:tag × target 状态。

func (*MirrorService) ListMirrorChannels

func (m *MirrorService) ListMirrorChannels(page dao.Pagination) ([]*model.MirrorChannel, int64, error)

func (*MirrorService) ListMirrorRuns

func (m *MirrorService) ListMirrorRuns(channelID uint, page dao.Pagination) ([]*model.MirrorRun, int64, error)

ListMirrorRuns 分页列出通道执行记录。

func (*MirrorService) PreviewMirrorRun

func (m *MirrorService) PreviewMirrorRun(ctx context.Context, channelID, targetID uint, tag string) (*mirror.TagReport, error)

PreviewMirrorRun 对单个 tag 做预检(DryRun,不推送)。

func (*MirrorService) TestMirrorTarget

func (m *MirrorService) TestMirrorTarget(ctx context.Context, targetID uint) error

func (*MirrorService) UpdateMirrorTarget

func (m *MirrorService) UpdateMirrorTarget(ctx context.Context, targetID uint, in MirrorTargetInput) (*model.MirrorTarget, error)

UpdateMirrorTarget 更新目标(凭据为空串表示保持不变)。

func (*MirrorService) VerifyMirrorTargetVersion

func (m *MirrorService) VerifyMirrorTargetVersion(ctx context.Context, channelID, targetID uint, tag string) (*model.MirrorRun, error)

VerifyMirrorTargetVersion 验证目标 module@tag 可被 go 工具链消费。

type MirrorTargetInput

type MirrorTargetInput struct {
	Remote       string `json:"remote"`
	RepoURL      string `json:"repoUrl"`
	TargetModule string `json:"targetModule"`
	CredType     string `json:"credType"`
	// Credential 明文仅在创建/更新时提交,格式随 CredType:
	// token→token 值;ssh_key→私钥 PEM。存储前整体加密。
	Credential string `json:"credential"`
	Username   string `json:"username"`
}

type MirrorVersion

type MirrorVersion struct {
	Tag     string                `json:"tag"`
	Commit  string                `json:"commit,omitempty"`
	Targets []MirrorVersionTarget `json:"targets"`
}

type MirrorVersionTarget

type MirrorVersionTarget struct {
	TargetID   uint   `json:"targetId"`
	Target     string `json:"target"`
	State      string `json:"state"` // unpublished|published|divergent|failed
	ExecutedAt string `json:"executedAt,omitempty"`
	Commit     string `json:"commit,omitempty"`
	Tree       string `json:"tree,omitempty"`
	Verify     string `json:"verify"` // unverified|passed|failed
}

type MirrorVersionsResult

type MirrorVersionsResult struct {
	Mode     string          `json:"mode"`
	Module   string          `json:"module"`
	Versions []MirrorVersion `json:"versions"`
}

type OperationLogService

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

OperationLogService 处理审计日志相关操作。

func NewOperationLogService

func NewOperationLogService(opLogDAO *dao.OperationLogDAO) *OperationLogService

NewOperationLogService 创建新的 OperationLogService 实例。

func (*OperationLogService) List

func (s *OperationLogService) List(ctx context.Context, offset, limit int, filter *dao.OperationLogFilter) ([]*model.OperationLog, int64, error)

List 按过滤条件分页返回审计日志。

func (*OperationLogService) Record

func (s *OperationLogService) Record(ctx context.Context, entry *model.OperationLog) error

Record 记录一条审计日志(best-effort,由调用方决定如何处理错误)。 自动续接哈希链:EntryHash = SHA256(PrevHash || payload)。

func (*OperationLogService) Stats

func (s *OperationLogService) Stats(ctx context.Context) (today, week, total int64, err error)

Stats 返回今日、近 7 天(本周)、总操作数。单次 SQL 查询。

func (*OperationLogService) VerifyAuditChain added in v0.6.0

func (s *OperationLogService) VerifyAuditChain() (*AuditChainResult, error)

VerifyAuditChain 全量校验审计哈希链完整性。

type OrgMapStrategy added in v0.7.0

type OrgMapStrategy string

OrgMapStrategy 批量镜像时目标仓落点策略(对标 gitea-mirror)。

const (
	// OrgMapPreserve 保持源 owner/repo 结构。
	OrgMapPreserve OrgMapStrategy = "preserve"
	// OrgMapSingle 全部落到同一 org,仓库名不变。
	OrgMapSingle OrgMapStrategy = "single"
	// OrgMapFlat 全部落到目标 user,仓库名不变。
	OrgMapFlat OrgMapStrategy = "flat"
	// OrgMapMixed 个人仓→flat;组织仓→preserve。
	OrgMapMixed OrgMapStrategy = "mixed"
)

type PlatformService

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

PlatformService 平台服务

func NewPlatformService

func NewPlatformService(platformDAO *dao.PlatformDAO, repoDAO *dao.RepoDAO, providerMgr *sdkprov.Manager) *PlatformService

NewPlatformService 创建 PlatformService

func (*PlatformService) CountReposByPlatform

func (s *PlatformService) CountReposByPlatform(ctx context.Context, platformKey string) (int64, error)

CountReposByPlatform 统计平台下的仓库数量(不加载数据)

func (*PlatformService) CreatePlatform

func (s *PlatformService) CreatePlatform(ctx context.Context, platform *model.Platform) error

CreatePlatform 创建平台

func (*PlatformService) DeletePlatform

func (s *PlatformService) DeletePlatform(ctx context.Context, key string) error

DeletePlatform 删除平台

func (*PlatformService) GetPlatform

func (s *PlatformService) GetPlatform(ctx context.Context, key string) (*model.Platform, error)

GetPlatform 获取平台

func (*PlatformService) GetPlatformByID

func (s *PlatformService) GetPlatformByID(ctx context.Context, id uint) (*model.Platform, error)

GetPlatformByID 根据 ID 获取平台

func (*PlatformService) ListPlatformRepos

func (s *PlatformService) ListPlatformRepos(ctx context.Context, key, page, perPage string) ([]*sdkprov.PlatformRepo, error)

ListPlatformRepos 列出平台上的仓库

func (*PlatformService) ListPlatforms

func (s *PlatformService) ListPlatforms(ctx context.Context) ([]*model.Platform, error)

ListPlatforms 列出所有平台

func (*PlatformService) ListReposByPlatform

func (s *PlatformService) ListReposByPlatform(ctx context.Context, platformKey string) ([]*model.Repo, error)

ListReposByPlatform 列出平台下的仓库

func (*PlatformService) SetDefaultPlatform

func (s *PlatformService) SetDefaultPlatform(ctx context.Context, key string) error

SetDefaultPlatform 设置默认平台

func (*PlatformService) SyncPlatformRepos

func (s *PlatformService) SyncPlatformRepos(ctx context.Context, key string) (int, error)

SyncPlatformRepos 同步平台仓库到本地 SyncPlatformRepos 同步平台仓库(不过滤)。

func (*PlatformService) SyncPlatformReposFiltered added in v0.5.0

func (s *PlatformService) SyncPlatformReposFiltered(ctx context.Context, key string, filter *RepoImportFilter) (int, error)

SyncPlatformReposFiltered 按过滤器同步平台仓库(排除 archived/fork 等)。

func (*PlatformService) TestPlatformConnection

func (s *PlatformService) TestPlatformConnection(ctx context.Context, key string) (*sdkprov.TestConnectionResult, error)

TestPlatformConnection 测试平台连接

func (*PlatformService) UpdatePlatform

func (s *PlatformService) UpdatePlatform(ctx context.Context, platform *model.Platform) error

UpdatePlatform 更新平台

func (*PlatformService) UpdatePlatformStatus

func (s *PlatformService) UpdatePlatformStatus(ctx context.Context, key, status, testResult string) error

UpdatePlatformStatus 更新平台状态

type RPOMetric added in v0.6.0

type RPOMetric struct {
	TaskKey      string    `json:"task_key"`
	RepoKey      string    `json:"repo_key,omitempty"`
	LatestBundle string    `json:"latest_bundle"`
	LastBackupAt time.Time `json:"last_backup_at"`
	BundleCount  int       `json:"bundle_count"`
	TotalSize    int64     `json:"total_size"`
	RPOSeconds   int64     `json:"rpo_seconds"`
	RPOHuman     string    `json:"rpo_human"`
	RPOViolated  bool      `json:"rpo_violated"`
	EstRTO       string    `json:"est_rto"`
}

RPOMetric 单任务/仓库的恢复点观测。

type RPOReport added in v0.6.0

type RPOReport struct {
	Generated       time.Time   `json:"generated"`
	BackupDir       string      `json:"backup_dir"`
	RPOMaxSeconds   int64       `json:"rpo_max_seconds"`
	OverallRPOSec   int64       `json:"overall_rpo_seconds"`
	OverallRPOHuman string      `json:"overall_rpo_human"`
	WorstTask       string      `json:"worst_task"`
	Violations      int         `json:"violations"`
	Metrics         []RPOMetric `json:"metrics"`
}

RPOReport 全量 RPO/RTO 观测。

type RepoImportFilter added in v0.5.0

type RepoImportFilter struct {
	ExcludeArchived bool
	ExcludeForks    bool
	MinStars        int
	// IncludeLanguage 只导入该语言(空=不过滤)
	IncludeLanguage string
	// IncludeGlobs / ExcludeGlobs 按 FullName 匹配
	IncludeGlobs []string
	ExcludeGlobs []string
}

RepoImportFilter 平台仓库导入过滤(借鉴 gickup filter.*)。

func (*RepoImportFilter) Allow added in v0.5.0

Allow 判断仓库是否应导入。

type RepoService

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

RepoService handles repository-related operations.

func NewRepoService

func NewRepoService(repoDAO *dao.RepoDAO, platformDAO *dao.PlatformDAO, providerMgr *sdkprov.Manager) *RepoService

NewRepoService creates a new RepoService instance.

func (*RepoService) CountRepos

func (rs *RepoService) CountRepos() (int64, error)

CountRepos returns the total repo count via COUNT aggregate.

func (*RepoService) CreateRepo

func (rs *RepoService) CreateRepo(ctx context.Context, req *model.CreateRepoRequest) (*model.Repo, error)

CreateRepo creates a new repository.

func (*RepoService) DeleteRepo

func (rs *RepoService) DeleteRepo(ctx context.Context, key string) error

DeleteRepo deletes a repository by key.

func (*RepoService) GetRepo

func (rs *RepoService) GetRepo(ctx context.Context, key string) (*model.Repo, error)

GetRepo returns a repository by key.

func (*RepoService) GetRepoByKey

func (rs *RepoService) GetRepoByKey(key string) (*model.Repo, error)

GetRepoByKey returns a repository by key.

func (*RepoService) GetRepoWithProvider

func (rs *RepoService) GetRepoWithProvider(repoKey string) (*model.Repo, sdkprov.Provider, error)

GetRepoWithProvider 一次调用完成 repo 查找 + provider 解析, 消除调用方重复的 "GetRepoByKey → nil check → resolveRepoProvider" 样板。

func (*RepoService) ListBranches

func (rs *RepoService) ListBranches(ctx context.Context, repoKey string) ([]string, error)

ListBranches returns a list of branches for a repository.

func (*RepoService) ListRepos

func (rs *RepoService) ListRepos(ctx context.Context, offset, limit int) ([]*model.Repo, int64, error)

ListRepos returns a paginated list of repositories.

func (*RepoService) ListReposWithFilter

func (rs *RepoService) ListReposWithFilter(ctx context.Context, offset, limit int, filter *dao.RepoFilter) ([]*model.Repo, int64, error)

ListReposWithFilter returns a filtered, sorted, paginated list of repositories.

func (*RepoService) SetWebhookSecret

func (rs *RepoService) SetWebhookSecret(repoKey, secret string) error

SetWebhookSecret 设置仓库的 Webhook 密钥(经 repo_dao 加密落库),供入站验签使用。

func (*RepoService) TestConnection

func (rs *RepoService) TestConnection(ctx context.Context, repoKey string) (*model.TestConnectionResult, error)

TestConnection tests the connection to a repository.

func (*RepoService) UpdateRepo

func (rs *RepoService) UpdateRepo(ctx context.Context, req *model.UpdateRepoRequest) (*model.Repo, error)

UpdateRepo updates an existing repository.

type Service

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

func NewService

func NewService(cfg *Config) (*Service, error)

func (*Service) AutoDiscover added in v0.6.0

func (s *Service) AutoDiscover(ctx context.Context, platformKey string, opts AutoDiscoverOptions) (*DiscoveryReport, error)

AutoDiscover 扫描平台仓库,找出本地尚未登记的(可选自动导入)。 借鉴 gitea-mirror 的 auto-discovery:新仓库自动入册,无需人工点选。

func (*Service) BackupDir added in v0.5.1

func (s *Service) BackupDir() string

BackupDir 返回配置的冷备目录。

func (*Service) BatchDRDrill added in v0.6.0

func (s *Service) BatchDRDrill(ctx context.Context, names []string, max int) ([]*DrillReport, map[string]any, error)

BatchDRDrill 演练多个 bundle(空=目录下全部,最多 max 个)。

func (*Service) BuildBackupManifest added in v0.6.0

func (s *Service) BuildBackupManifest() (*executor.BackupManifest, error)

BuildBackupManifest 生成并保存冷备完整性清单。

func (*Service) CleanupExpiredBackups added in v0.6.0

func (s *Service) CleanupExpiredBackups() (removed int, err error)

CleanupExpiredBackups 按 retention 天数清理过期冷备(legal_hold 时拒绝执行)。 返回删除数量。与 BackupKeep 轮转互补:keep 管数量,retention 管时效。

func (*Service) CleanupOldData

func (s *Service) CleanupOldData(ctx context.Context, maxAge time.Duration) (events, runs, steps int64, err error)

func (*Service) CompleteRun

func (s *Service) CompleteRun(run *model.SyncRun) error

CompleteRun updates a sync run with final status and details. Satisfies executor.RunManager.

func (*Service) CompleteRunWithTaskUpdate

func (s *Service) CompleteRunWithTaskUpdate(run *model.SyncRun, task *model.SyncTask) error

CompleteRunWithTaskUpdate 在同一事务中完成 run + task 更新. Satisfies executor.RunManager.

func (*Service) CountRepos

func (s *Service) CountRepos() (int64, error)

CountRepos returns the total repo count via COUNT aggregate (no row loading).

func (*Service) CountReposByPlatform

func (s *Service) CountReposByPlatform(ctx context.Context, platformKey string) (int64, error)

CountReposByPlatform 统计平台下的仓库数量

func (*Service) CountTasksByStatus

func (s *Service) CountTasksByStatus() (map[string]int64, error)

CountTasksByStatus returns task counts grouped by last_status (key "total" = overall).

func (*Service) CreatePlatform

func (s *Service) CreatePlatform(ctx context.Context, platform *model.Platform) error

CreatePlatform 创建平台

func (*Service) CreateRepo

func (s *Service) CreateRepo(ctx context.Context, req *model.CreateRepoRequest) (*model.Repo, error)

CreateRepo creates a new repository.

func (*Service) CreateRule

func (s *Service) CreateRule(ctx context.Context, req *model.CreateRuleRequest) (*model.WebhookRule, error)

CreateRule creates a new webhook rule.

func (*Service) CreateRun

func (s *Service) CreateRun(task *model.SyncTask, trigger string, webhookEventID *uint) (*model.SyncRun, error)

CreateRun creates a new sync run record. Satisfies executor.RunManager.

func (*Service) CreateRunStep

func (s *Service) CreateRunStep(step *model.SyncRunStep) error

CreateRunStep creates a new sync run step record. Satisfies executor.RunManager.

func (*Service) CreateTask

func (s *Service) CreateTask(ctx context.Context, req *model.CreateTaskRequest) (*model.SyncTask, error)

func (*Service) DeleteHistory

func (s *Service) DeleteHistory(ctx context.Context, id uint) error

DeleteHistory deletes a sync run by ID.

func (*Service) DeletePlatform

func (s *Service) DeletePlatform(ctx context.Context, key string) error

DeletePlatform 删除平台

func (*Service) DeletePlatformWebhook

func (s *Service) DeletePlatformWebhook(ctx context.Context, repoKey string, webhookID int64) error

DeletePlatformWebhook 删除平台侧的 Webhook。

func (*Service) DeleteRepo

func (s *Service) DeleteRepo(ctx context.Context, key string) error

DeleteRepo deletes a repository by key.

func (*Service) DeleteRule

func (s *Service) DeleteRule(ctx context.Context, id uint) error

DeleteRule deletes a webhook rule by ID.

func (*Service) DeleteTask

func (s *Service) DeleteTask(ctx context.Context, key string) error

func (*Service) DetectDrift added in v0.6.0

func (s *Service) DetectDrift(ctx context.Context, taskKeys []string) (*DriftReport, error)

DetectDrift 检测本地 workdir 与目标远端的分支漂移。 用于发现「镜像声称同步成功但 refs 实际不一致」的静默故障。 taskKeys 为空时扫描全部启用任务。

func (*Service) DrillHistory added in v0.6.0

func (s *Service) DrillHistory(limit int) ([]executor.DrillHistoryEntry, error)

DrillHistory 读取演练历史。

func (*Service) ExportDrillHistory added in v0.6.1

func (s *Service) ExportDrillHistory(format string, limit int) (contentType string, data []byte, err error)

ExportDrillHistory 导出演练历史为 JSON 或 CSV(供审计/上报)。

func (*Service) GetConfig

func (s *Service) GetConfig() *model.Config

func (*Service) GetPlatform

func (s *Service) GetPlatform(ctx context.Context, key string) (*model.Platform, error)

GetPlatform 获取平台

func (*Service) GetPlatformByID

func (s *Service) GetPlatformByID(ctx context.Context, id uint) (*model.Platform, error)

GetPlatformByID returns a platform by ID. Satisfies executor.PlatformProvider.

func (*Service) GetRepo

func (s *Service) GetRepo(ctx context.Context, key string) (*model.Repo, error)

GetRepo returns a repository by key.

func (*Service) GetRepoByKey

func (s *Service) GetRepoByKey(key string) (*model.Repo, error)

GetRepoByKey returns a repository by key. Satisfies executor.RepoProvider.

func (*Service) GetRule

func (s *Service) GetRule(ctx context.Context, id uint) (*model.WebhookRule, error)

GetRule returns a webhook rule by ID.

func (*Service) GetTask

func (s *Service) GetTask(ctx context.Context, key string) (*model.SyncTask, error)

GetTask returns a sync task by key.

func (*Service) GetTempDir

func (s *Service) GetTempDir(taskKey string) string

func (*Service) HealthCheck

func (s *Service) HealthCheck() map[string]string

HealthCheck checks the health of all dependencies. Returns a map of component name to "ok" or error message. 内部对每个组件设置 5s 超时:基础设施卡住时健康检查不会无限阻塞。

func (*Service) LegalHold added in v0.6.0

func (s *Service) LegalHold() bool

LegalHold 当前是否处于合规冻结。

func (*Service) ListBranches

func (s *Service) ListBranches(ctx context.Context, repoKey string) ([]string, error)

ListBranches returns a list of branches for a repository.

func (*Service) ListBundles added in v0.5.1

func (s *Service) ListBundles(taskKey string) ([]BundleInfo, error)

ListBundles 列出冷备 bundle。

func (*Service) ListEvents

func (s *Service) ListEvents(ctx context.Context, repoKey string, offset, limit int) ([]*model.WebhookEvent, int64, error)

ListEvents returns webhook events for a repository.

func (*Service) ListHistory

func (s *Service) ListHistory(ctx context.Context, taskKey string, offset, limit int) ([]*model.SyncRun, int64, error)

ListHistory returns a paginated list of sync run history.

func (*Service) ListOperations

func (s *Service) ListOperations(ctx context.Context, offset, limit int, filter *dao.OperationLogFilter) ([]*model.OperationLog, int64, error)

ListOperations 按过滤条件分页返回审计日志。

func (*Service) ListPlatformRepos

func (s *Service) ListPlatformRepos(ctx context.Context, key, page, perPage string) ([]*sdkprov.PlatformRepo, error)

ListPlatformRepos 列出平台上的仓库

func (*Service) ListPlatformWebhooks

func (s *Service) ListPlatformWebhooks(ctx context.Context, repoKey string) ([]*sdkprov.PlatformWebhook, error)

ListPlatformWebhooks 列出平台侧已注册的 Webhook。

func (*Service) ListPlatforms

func (s *Service) ListPlatforms(ctx context.Context) ([]*model.Platform, error)

ListPlatforms 列出所有平台

func (*Service) ListRepos

func (s *Service) ListRepos(ctx context.Context, offset, limit int) ([]*model.Repo, int64, error)

ListRepos returns a paginated list of repositories.

func (*Service) ListReposByPlatform

func (s *Service) ListReposByPlatform(ctx context.Context, platformKey string) ([]*model.Repo, error)

ListReposByPlatform 列出平台下的仓库

func (*Service) ListReposWithFilter

func (s *Service) ListReposWithFilter(ctx context.Context, offset, limit int, filter *dao.RepoFilter) ([]*model.Repo, int64, error)

ListReposWithFilter returns a filtered, sorted, paginated list of repositories.

func (*Service) ListRules

func (s *Service) ListRules(ctx context.Context, repoKey string) ([]*model.WebhookRule, error)

ListRules returns webhook rules for a repository.

func (*Service) ListTasks

func (s *Service) ListTasks(ctx context.Context, repoKey string, offset, limit int) ([]*model.SyncTask, int64, error)

ListTasks returns a paginated list of sync tasks.

func (*Service) Mirror

func (s *Service) Mirror() *MirrorService

Mirror 返回镜像通道服务(开源发布/仓库备份)。

func (*Service) OperationStats

func (s *Service) OperationStats(ctx context.Context) (today, week, total int64, err error)

OperationStats 返回今日、本周、总操作数。

func (*Service) PreviewSync

PreviewSync previews a sync operation.

func (*Service) RPOReport added in v0.6.0

func (s *Service) RPOReport(rpoMaxSeconds int64) (*RPOReport, error)

RPOReport 按冷备目录聚合每个任务的备份新鲜度(RPO)与估算恢复时间(RTO)。 rpoMaxSeconds>0 时标记超标任务。

func (*Service) ReceiveWebhook

func (s *Service) ReceiveWebhook(ctx context.Context, repoKey string, payload *WebhookPayload) error

func (*Service) RecordOperation

func (s *Service) RecordOperation(ctx context.Context, entry *model.OperationLog) error

RecordOperation 记录一条审计日志。

func (*Service) RegisterPlatformWebhook

func (s *Service) RegisterPlatformWebhook(ctx context.Context, repoKey, callbackURL, secret string, events []string) (*sdkprov.PlatformWebhook, error)

RegisterPlatformWebhook 在平台侧为仓库注册 Webhook,回调指向本服务的接收端点 (/api/webhook/receive/:repoKey)。secret 非空时持久化到仓库记录(加密存储), 用于入站事件验签。events 为空时默认订阅 push。

func (*Service) ResolvePlatformToken added in v0.6.0

func (s *Service) ResolvePlatformToken(p *model.Platform) (string, error)

ResolvePlatformToken Service 包装,便于壳层/业务调用。

func (*Service) RestoreBundle added in v0.5.1

func (s *Service) RestoreBundle(ctx context.Context, name, destDir string) error

RestoreBundle 从 bundle 恢复到 destDir。 支持 .bundle 与 .bundle.enc(需配置 backup_encrypt_key)。

func (*Service) RetryEvent

func (s *Service) RetryEvent(ctx context.Context, eventID uint) error

func (*Service) RunDRDrill added in v0.6.0

func (s *Service) RunDRDrill(ctx context.Context, name string) (*DrillReport, error)

RunDRDrill 对指定 bundle 做灾备演练,并写入哈希链历史。

func (*Service) RunTask

func (s *Service) RunTask(ctx context.Context, taskKey string) error

func (*Service) RunTaskAsync

func (s *Service) RunTaskAsync(taskKey, trigger string, webhookEventID *uint) error

RunTaskAsync 异步触发一次同步:校验与并发快速失败在调用方 goroutine 内完成, 实际执行纳入 WaitGroup + bgCtx(优雅关停时被等待/取消),适合 HTTP 手动触发路径, 避免 handler 被分钟级同步任务挂住。返回 nil 仅代表"已受理",结果见执行历史。

func (*Service) RunTaskWithTrigger

func (s *Service) RunTaskWithTrigger(ctx context.Context, taskKey, trigger string, webhookEventID *uint) error

func (*Service) SetDefaultPlatform

func (s *Service) SetDefaultPlatform(ctx context.Context, key string) error

SetDefaultPlatform 设置默认平台

func (*Service) SetForcePushApprover added in v0.7.1

func (s *Service) SetForcePushApprover(a executor.ForcePushApprover)

SetForcePushApprover 注入 force-push 审批器(壳层 force-push-approvals)。 block 策略触发分歧时:已放行则继续,否则登记 pending 并拒绝。

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop()

func (*Service) SyncPlatformRepos

func (s *Service) SyncPlatformRepos(ctx context.Context, key string) (int, error)

SyncPlatformRepos 同步平台仓库到本地

func (*Service) SyncPlatformReposFiltered added in v0.5.0

func (s *Service) SyncPlatformReposFiltered(ctx context.Context, key string, filter *RepoImportFilter) (int, error)

SyncPlatformReposFiltered 按过滤条件导入平台仓库。

func (*Service) TestConnection

func (s *Service) TestConnection(ctx context.Context, repoKey string) (*model.TestConnectionResult, error)

TestConnection tests the connection to a repository.

func (*Service) TestPlatformConnection

func (s *Service) TestPlatformConnection(ctx context.Context, key string) (*sdkprov.TestConnectionResult, error)

TestPlatformConnection 测试平台连接

func (*Service) UpdatePlatform

func (s *Service) UpdatePlatform(ctx context.Context, platform *model.Platform) error

UpdatePlatform 更新平台

func (*Service) UpdatePlatformStatus

func (s *Service) UpdatePlatformStatus(ctx context.Context, key, status, testResult string) error

UpdatePlatformStatus 更新平台状态

func (*Service) UpdateRepo

func (s *Service) UpdateRepo(ctx context.Context, req *model.UpdateRepoRequest) (*model.Repo, error)

UpdateRepo updates an existing repository.

func (*Service) UpdateRule

func (s *Service) UpdateRule(ctx context.Context, req *model.UpdateRuleRequest) (*model.WebhookRule, error)

UpdateRule updates an existing webhook rule.

func (*Service) UpdateRunStep

func (s *Service) UpdateRunStep(step *model.SyncRunStep) error

UpdateRunStep updates an existing sync run step record. Satisfies executor.RunManager.

func (*Service) UpdateTask

func (s *Service) UpdateTask(ctx context.Context, req *model.UpdateTaskRequest) (*model.SyncTask, error)

func (*Service) UpdateTaskLastRun

func (s *Service) UpdateTaskLastRun(task *model.SyncTask, run *model.SyncRun) error

UpdateTaskLastRun updates the task's last run status. Satisfies executor.RunManager.

func (*Service) VerifyAuditChain added in v0.6.0

func (s *Service) VerifyAuditChain() (*AuditChainResult, error)

VerifyAuditChain 校验审计哈希链。

func (*Service) VerifyBackupManifest added in v0.6.0

func (s *Service) VerifyBackupManifest() (*executor.ManifestVerifyResult, error)

VerifyBackupManifest 现场重算并比对清单。

func (*Service) VerifyBundle added in v0.5.1

func (s *Service) VerifyBundle(ctx context.Context, name string) (*BundleInfo, error)

VerifyBundle 校验 bundle 完整性。 自动识别 .enc 加密冷备:先解密到临时目录再校验。

func (*Service) VerifyDrillChain added in v0.6.0

func (s *Service) VerifyDrillChain() (bool, int, string)

VerifyDrillChain 校验演练历史哈希链。

type TaskService

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

TaskService handles sync task-related operations.

func NewTaskService

func NewTaskService(taskDAO *dao.SyncTaskDAO, runDAO *dao.SyncRunDAO, runStepDAO *dao.SyncRunStepDAO, repoDAO *dao.RepoDAO) *TaskService

NewTaskService creates a new TaskService instance.

func (*TaskService) CleanupOldRunSteps

func (ts *TaskService) CleanupOldRunSteps(ctx context.Context, maxAge time.Duration) (int64, error)

CleanupOldRunSteps removes sync run steps older than the specified duration.

func (*TaskService) CleanupOldRuns

func (ts *TaskService) CleanupOldRuns(ctx context.Context, maxAge time.Duration) (int64, error)

CleanupOldRuns removes sync runs older than the specified duration.

func (*TaskService) CompleteRun

func (ts *TaskService) CompleteRun(run *model.SyncRun) error

CompleteRun updates a sync run with final status and details.

func (*TaskService) CompleteRunWithTaskUpdate

func (ts *TaskService) CompleteRunWithTaskUpdate(run *model.SyncRun, task *model.SyncTask) error

CompleteRunWithTaskUpdate 在同一事务中完成 run 更新 + task 状态更新,保证原子性。

func (*TaskService) CountTasksByStatus

func (ts *TaskService) CountTasksByStatus() (map[string]int64, error)

CountTasksByStatus returns task counts grouped by last_status (key "total" = overall).

func (*TaskService) CreateRun

func (ts *TaskService) CreateRun(task *model.SyncTask, trigger string, webhookEventID *uint) (*model.SyncRun, error)

CreateRun creates a new sync run record for a task.

func (*TaskService) CreateRunStep

func (ts *TaskService) CreateRunStep(step *model.SyncRunStep) error

CreateRunStep creates a new sync run step record.

func (*TaskService) CreateTask

func (ts *TaskService) CreateTask(ctx context.Context, req *model.CreateTaskRequest) (*model.SyncTask, error)

CreateTask creates a new sync task.

func (*TaskService) DeleteHistory

func (ts *TaskService) DeleteHistory(ctx context.Context, id uint) error

DeleteHistory deletes a sync run by ID.

func (*TaskService) DeleteTask

func (ts *TaskService) DeleteTask(ctx context.Context, key string) error

DeleteTask deletes a sync task by key.

func (*TaskService) FindAllEnabledTasks

func (ts *TaskService) FindAllEnabledTasks() ([]*model.SyncTask, error)

FindAllEnabledTasks returns all enabled sync tasks.

func (*TaskService) FindTaskByKey

func (ts *TaskService) FindTaskByKey(key string) (*model.SyncTask, error)

FindTaskByKey returns a sync task by key (internal use).

func (*TaskService) GetTask

func (ts *TaskService) GetTask(ctx context.Context, key string) (*model.SyncTask, error)

GetTask returns a sync task by key.

func (*TaskService) ListHistory

func (ts *TaskService) ListHistory(ctx context.Context, taskKey string, offset, limit int) ([]*model.SyncRun, int64, error)

ListHistory returns a paginated list of sync run history.

func (*TaskService) ListTasks

func (ts *TaskService) ListTasks(ctx context.Context, repoKey string, offset, limit int) ([]*model.SyncTask, int64, error)

ListTasks returns a paginated list of sync tasks.

func (*TaskService) PreviewSync

PreviewSync previews a sync operation.

func (*TaskService) UpdateRunStep

func (ts *TaskService) UpdateRunStep(step *model.SyncRunStep) error

UpdateRunStep updates an existing sync run step record.

func (*TaskService) UpdateTask

func (ts *TaskService) UpdateTask(ctx context.Context, req *model.UpdateTaskRequest) (*model.SyncTask, error)

UpdateTask updates an existing sync task.

func (*TaskService) UpdateTaskLastRun

func (ts *TaskService) UpdateTaskLastRun(task *model.SyncTask, run *model.SyncRun) error

UpdateTaskLastRun updates the task's last run time and status.

type WebhookPayload

type WebhookPayload struct {
	Method     string
	Path       string
	Header     map[string][]string
	Body       []byte
	RemoteAddr string
}

WebhookPayload 是协议无关的入站 Webhook 载荷。 core 不提供 HTTP 服务端;壳层(hz/gin/…)负责收包后转成该结构再调用。 内部会拼一个临时 *http.Request 交给 git-platform-sdk 做验签/解析(SDK 契约如此), 库对外 API 不暴露 Web 服务器语义。

type WebhookService

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

WebhookService handles webhook-related operations.

func NewWebhookService

func NewWebhookService(ruleDAO *dao.WebhookRuleDAO, eventDAO *dao.WebhookEventDAO, repoDAO *dao.RepoDAO) *WebhookService

NewWebhookService creates a new WebhookService instance.

func (*WebhookService) ApplyRules

func (ws *WebhookService) ApplyRules(ctx context.Context, repoKey string, event *model.WebhookEvent, lastTriggerTime *sync.Map, runTaskFn func(ctx context.Context, taskKey, trigger string, webhookEventID *uint) error, webhookEventID *uint)

ApplyRules applies webhook rules to an event.

func (*WebhookService) CleanupOldEvents

func (ws *WebhookService) CleanupOldEvents(ctx context.Context, maxAge time.Duration) (int64, error)

CleanupOldEvents removes webhook events older than the specified duration.

func (*WebhookService) CreateRule

CreateRule creates a new webhook rule.

func (*WebhookService) CreateWebhookEvent

func (ws *WebhookService) CreateWebhookEvent(event *model.WebhookEvent) error

CreateWebhookEvent creates a new webhook event.

func (*WebhookService) DeleteRule

func (ws *WebhookService) DeleteRule(ctx context.Context, id uint) error

DeleteRule deletes a webhook rule by ID.

func (*WebhookService) FindEventByEventID

func (ws *WebhookService) FindEventByEventID(eventID string) (*model.WebhookEvent, error)

FindEventByEventID returns a webhook event by event ID (internal use).

func (*WebhookService) FindEventByID

func (ws *WebhookService) FindEventByID(id uint) (*model.WebhookEvent, error)

FindEventByID returns a webhook event by ID (internal use).

func (*WebhookService) GetRule

func (ws *WebhookService) GetRule(ctx context.Context, id uint) (*model.WebhookRule, error)

GetRule returns a webhook rule by ID.

func (*WebhookService) ListEvents

func (ws *WebhookService) ListEvents(ctx context.Context, repoKey string, offset, limit int) ([]*model.WebhookEvent, int64, error)

ListEvents returns webhook events for a repository.

func (*WebhookService) ListRules

func (ws *WebhookService) ListRules(ctx context.Context, repoKey string) ([]*model.WebhookRule, error)

ListRules returns webhook rules for a repository.

func (*WebhookService) MarkEventProcessed

func (ws *WebhookService) MarkEventProcessed(event *model.WebhookEvent) error

MarkEventProcessed 标记事件为 processed(处理完成后调用)。 用 targeted UPDATE 仅写 status+processed_at,避免全字段回写大 payload。

func (*WebhookService) MarkEventProcessing

func (ws *WebhookService) MarkEventProcessing(ctx context.Context, eventID uint) (*model.WebhookEvent, error)

MarkEventProcessing 查找事件并标记为 processing,返回该事件供后续处理。

func (*WebhookService) UpdateRule

UpdateRule updates an existing webhook rule.

Jump to

Keyboard shortcuts

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