Documentation
¶
Index ¶
- Constants
- Variables
- func ClearGitHubAppTokenCache()
- func FetchGitHubInstallationToken(ctxTimeout time.Duration, apiBase string, appID, installationID int64, ...) (string, error)
- func IsPersonalOwner(owner, targetUser string, orgOwners map[string]bool) bool
- func MintGitHubAppJWT(appID int64, privateKeyPEM string) (string, error)
- func ResolvePlatformToken(p *model.Platform) (string, error)
- func RewriteRepoURL(raw, owner, repo string) string
- func ValidForcePushPolicy(p string) bool
- func ValidOrgMapStrategy(s string) bool
- type AuditChainResult
- type AutoDiscoverOptions
- type AutoRetryPolicy
- type BackupManifest
- type BulkMirrorItem
- type BulkMirrorRequest
- type BulkMirrorResult
- type BundleInfo
- type Config
- type CreateMirrorChannelInput
- type CredentialStatus
- type Decision
- type DiscoveryReport
- type DriftItem
- type DriftReport
- type DrillHistoryEntry
- type DrillReport
- type ErrorClass
- type ExecuteMirrorRunInput
- type ForcePushApproval
- type ForcePushPolicy
- type ForcePushStore
- func (st *ForcePushStore) Approve(id, actor string) (found bool, err error)
- func (st *ForcePushStore) ConsumeForcePushApproval(taskKey, branch, targetRef string)
- func (st *ForcePushStore) IsForcePushApproved(taskKey, branch, targetRef string) bool
- func (st *ForcePushStore) List() []ForcePushApproval
- func (st *ForcePushStore) PendingCount() int
- func (st *ForcePushStore) Request(taskKey, branch, reason, targetRef string) (ForcePushApproval, error)
- func (st *ForcePushStore) RequestApproval(taskKey, branch, reason, targetRef string)
- func (st *ForcePushStore) Revoke(id, actor string) (found bool, err error)
- type GateReport
- type HealthScoreItem
- type HealthSnapshot
- type HealthSummary
- type HistoryChainResult
- type HistoryChannelDTO
- type HistoryChannelInput
- type HistoryCredentialInput
- type HistoryOptionsDTO
- type HistoryOverrideDTO
- type HistoryOverrideInput
- type HistoryPlanDTO
- type HistoryPushDTO
- type HistoryPushOptions
- type HistoryRollbackDTO
- type HistoryRunDTO
- type HistoryService
- func (h *HistoryService) CreateHistoryChannel(_ context.Context, in HistoryChannelInput) (*HistoryChannelDTO, error)
- func (h *HistoryService) CreateHistoryTarget(_ context.Context, channelID uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
- func (h *HistoryService) DeleteHistoryChannel(ctx context.Context, id uint) error
- func (h *HistoryService) DeleteHistoryOverride(_ context.Context, id uint) error
- func (h *HistoryService) DeleteHistoryTarget(_ context.Context, id uint) error
- func (h *HistoryService) GetHistoryChannel(_ context.Context, id uint) (*HistoryChannelDTO, error)
- func (h *HistoryService) GetHistoryRun(_ context.Context, id uint) (*HistoryRunDTO, error)
- func (h *HistoryService) HistoryApply(ctx context.Context, channelID uint) (*HistoryRunDTO, error)
- func (h *HistoryService) HistoryPlan(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
- func (h *HistoryService) HistoryPreview(ctx context.Context, channelID uint) (*PreviewReport, error)
- func (h *HistoryService) HistoryPush(ctx context.Context, channelID uint) (*HistoryPushDTO, error)
- func (h *HistoryService) HistoryPushRun(ctx context.Context, runID uint) (*HistoryPushDTO, error)
- func (h *HistoryService) HistoryPushWithOptions(ctx context.Context, channelID uint, opts HistoryPushOptions) (*HistoryPushDTO, error)
- func (h *HistoryService) HistoryResolve(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
- func (h *HistoryService) HistoryRollback(ctx context.Context, runID uint, ref string) (*HistoryRollbackDTO, error)
- func (h *HistoryService) HistorySync(ctx context.Context, opts HistorySyncOptions) (*HistorySyncReport, error)
- func (h *HistoryService) ListHistoryChannels(_ context.Context, offset, limit int) ([]*HistoryChannelDTO, int64, error)
- func (h *HistoryService) ListHistoryOverrides(_ context.Context, channelID uint) ([]*HistoryOverrideDTO, error)
- func (h *HistoryService) ListHistoryRuns(_ context.Context, channelID uint, offset, limit int) ([]*HistoryRunDTO, int64, error)
- func (h *HistoryService) ListHistoryTargets(_ context.Context, channelID uint) ([]*HistoryTargetDTO, error)
- func (h *HistoryService) MaterializeRuns() int64
- func (h *HistoryService) RotateHistoryTargetCredential(_ context.Context, id uint, in HistoryCredentialInput) (*HistoryTargetDTO, error)
- func (h *HistoryService) SetHistoryOverride(ctx context.Context, channelID uint, in HistoryOverrideInput) (*HistoryOverrideDTO, error)
- func (h *HistoryService) UpdateHistoryChannel(ctx context.Context, id uint, in HistoryChannelInput) (*HistoryChannelDTO, error)
- func (h *HistoryService) UpdateHistoryTarget(_ context.Context, id uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
- func (h *HistoryService) VerifyHistoryChannelChain(_ context.Context, channelID uint) (*HistoryChainResult, error)
- type HistorySyncOptions
- type HistorySyncReport
- type HistoryTargetDTO
- type HistoryTargetInput
- type IdentityRuleDTO
- type InventoryItem
- type InventoryResult
- type ManifestVerifyResult
- type MetadataBackupInfo
- type MetadataBackupOptions
- type MetadataBackupResult
- type MetadataSnapshot
- type MirrorScrubRuleInput
- type MirrorService
- func (m *MirrorService) CreateMirrorChannel(ctx context.Context, in CreateMirrorChannelInput) (*model.MirrorChannel, error)
- func (m *MirrorService) DeleteMirrorChannel(confirm string, id uint) error
- func (m *MirrorService) DeleteMirrorTarget(targetID uint) error
- func (m *MirrorService) ExecuteMirrorRun(ctx context.Context, channelID uint, in ExecuteMirrorRunInput) (*model.MirrorRun, error)
- func (m *MirrorService) GetMirrorChannel(id uint) (*model.MirrorChannel, error)
- func (m *MirrorService) GetMirrorRun(id uint) (*model.MirrorRun, error)
- func (m *MirrorService) GetMirrorVersions(ctx context.Context, channelID uint) (*MirrorVersionsResult, error)
- func (m *MirrorService) ListMirrorChannels(page dao.Pagination) ([]*model.MirrorChannel, int64, error)
- func (m *MirrorService) ListMirrorRuns(channelID uint, page dao.Pagination) ([]*model.MirrorRun, int64, error)
- func (m *MirrorService) PreviewMirrorRun(ctx context.Context, channelID, targetID uint, tag string) (*mirror.TagReport, error)
- func (m *MirrorService) TestMirrorTarget(ctx context.Context, targetID uint) error
- func (m *MirrorService) UpdateMirrorTarget(ctx context.Context, targetID uint, in MirrorTargetInput) (*model.MirrorTarget, error)
- func (m *MirrorService) VerifyMirrorTargetVersion(ctx context.Context, channelID, targetID uint, tag string) (*model.MirrorRun, error)
- type MirrorTargetInput
- type MirrorVersion
- type MirrorVersionTarget
- type MirrorVersionsResult
- type OperationLogService
- func (s *OperationLogService) List(ctx context.Context, offset, limit int, filter *dao.OperationLogFilter) ([]*model.OperationLog, int64, error)
- func (s *OperationLogService) Record(ctx context.Context, entry *model.OperationLog) error
- func (s *OperationLogService) Stats(ctx context.Context) (today, week, total int64, err error)
- func (s *OperationLogService) VerifyAuditChain() (*AuditChainResult, error)
- type OpsTodoItem
- type OpsTrendsResult
- type Option
- type OrgMapOptions
- type OrgMapResult
- type OrgMapStrategy
- type OrgRepoItem
- type PathRuleDTO
- type PlatformService
- func (s *PlatformService) CountReposByPlatform(ctx context.Context, platformKey string) (int64, error)
- func (s *PlatformService) CreatePlatform(ctx context.Context, platform *model.Platform) error
- func (s *PlatformService) DeletePlatform(ctx context.Context, key string) error
- func (s *PlatformService) GetPlatform(ctx context.Context, key string) (*model.Platform, error)
- func (s *PlatformService) GetPlatformByID(ctx context.Context, id uint) (*model.Platform, error)
- func (s *PlatformService) ListPlatformRepos(ctx context.Context, key, page, perPage string) ([]*sdkprov.PlatformRepo, error)
- func (s *PlatformService) ListPlatforms(ctx context.Context) ([]*model.Platform, error)
- func (s *PlatformService) ListReposByPlatform(ctx context.Context, platformKey string) ([]*model.Repo, error)
- func (s *PlatformService) SetDefaultPlatform(ctx context.Context, key string) error
- func (s *PlatformService) SyncPlatformRepos(ctx context.Context, key string) (int, error)
- func (s *PlatformService) SyncPlatformReposFiltered(ctx context.Context, key string, filter *RepoImportFilter) (int, error)
- func (s *PlatformService) TestPlatformConnection(ctx context.Context, key string) (*sdkprov.TestConnectionResult, error)
- func (s *PlatformService) UpdatePlatform(ctx context.Context, platform *model.Platform) error
- func (s *PlatformService) UpdatePlatformStatus(ctx context.Context, key, status, testResult string) error
- type PreviewReport
- type PublicOrgImportRequest
- type PublicOrgImportResult
- type RPOMetric
- type RPOReport
- type RepoImportFilter
- type RepoService
- func (rs *RepoService) CountRepos() (int64, error)
- func (rs *RepoService) CreateRepo(ctx context.Context, req *model.CreateRepoRequest) (*model.Repo, error)
- func (rs *RepoService) DeleteRepo(ctx context.Context, key string) error
- func (rs *RepoService) GetRepo(ctx context.Context, key string) (*model.Repo, error)
- func (rs *RepoService) GetRepoByKey(key string) (*model.Repo, error)
- func (rs *RepoService) GetRepoWithProvider(repoKey string) (*model.Repo, sdkprov.Provider, error)
- func (rs *RepoService) ListBranches(ctx context.Context, repoKey string) ([]string, error)
- func (rs *RepoService) ListRepos(ctx context.Context, offset, limit int) ([]*model.Repo, int64, error)
- func (rs *RepoService) ListReposWithFilter(ctx context.Context, offset, limit int, filter *dao.RepoFilter) ([]*model.Repo, int64, error)
- func (rs *RepoService) SetWebhookSecret(repoKey, secret string) error
- func (rs *RepoService) TestConnection(ctx context.Context, repoKey string) (*model.TestConnectionResult, error)
- func (rs *RepoService) UpdateRepo(ctx context.Context, req *model.UpdateRepoRequest) (*model.Repo, error)
- type RestoreItem
- type RestoreKindStat
- type RestoreRequest
- type RestoreResult
- type RetryTracker
- type RunEvent
- type ScrubRuleDTO
- type Service
- func (s *Service) ApplyTemplate(ctx context.Context, templateID string, dryRun bool) (*TemplateApplyResult, error)
- func (s *Service) AutoDiscover(ctx context.Context, platformKey string, opts AutoDiscoverOptions) (*DiscoveryReport, error)
- func (s *Service) AutoRetry() *RetryTracker
- func (s *Service) BackupDir() string
- func (s *Service) BackupGists(ctx context.Context, prov sdkprov.Provider, destDir string, maxGists int) (count int, warnings []string, err error)
- func (s *Service) BackupMetadata(ctx context.Context, o MetadataBackupOptions) (*MetadataBackupResult, error)
- func (s *Service) BatchDRDrill(ctx context.Context, names []string, max int) ([]*DrillReport, map[string]any, error)
- func (s *Service) BuildBackupManifest() (*executor.BackupManifest, error)
- func (s *Service) BulkMirrorOrg(ctx context.Context, req BulkMirrorRequest) (*BulkMirrorResult, error)
- func (s *Service) CleanupExpiredBackups() (removed int, err error)
- func (s *Service) CleanupOldData(ctx context.Context, maxAge time.Duration) (events, runs, steps int64, err error)
- func (s *Service) CompleteRun(run *model.SyncRun) error
- func (s *Service) CompleteRunWithTaskUpdate(run *model.SyncRun, task *model.SyncTask) error
- func (s *Service) CountRepos() (int64, error)
- func (s *Service) CountReposByPlatform(ctx context.Context, platformKey string) (int64, error)
- func (s *Service) CountTasksByStatus() (map[string]int64, error)
- func (s *Service) CreateHistoryChannel(ctx context.Context, in HistoryChannelInput) (*HistoryChannelDTO, error)
- func (s *Service) CreateHistoryTarget(ctx context.Context, channelID uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
- func (s *Service) CreatePlatform(ctx context.Context, platform *model.Platform) error
- func (s *Service) CreateRepo(ctx context.Context, req *model.CreateRepoRequest) (*model.Repo, error)
- func (s *Service) CreateRule(ctx context.Context, req *model.CreateRuleRequest) (*model.WebhookRule, error)
- func (s *Service) CreateRun(task *model.SyncTask, trigger string, webhookEventID *uint) (*model.SyncRun, error)
- func (s *Service) CreateRunStep(step *model.SyncRunStep) error
- func (s *Service) CreateTask(ctx context.Context, req *model.CreateTaskRequest) (*model.SyncTask, error)
- func (s *Service) DeleteHistory(ctx context.Context, id uint) error
- func (s *Service) DeleteHistoryChannel(ctx context.Context, id uint) error
- func (s *Service) DeleteHistoryOverride(ctx context.Context, id uint) error
- func (s *Service) DeleteHistoryTarget(ctx context.Context, id uint) error
- func (s *Service) DeletePlatform(ctx context.Context, key string) error
- func (s *Service) DeletePlatformWebhook(ctx context.Context, repoKey string, webhookID int64) error
- func (s *Service) DeleteRepo(ctx context.Context, key string) error
- func (s *Service) DeleteRule(ctx context.Context, id uint) error
- func (s *Service) DeleteTask(ctx context.Context, key string) error
- func (s *Service) DetectDrift(ctx context.Context, taskKeys []string) (*DriftReport, error)
- func (s *Service) DownloadReleaseAssets(ctx context.Context, prov sdkprov.Provider, owner, repo string, ...) (saved, warnings []string, err error)
- func (s *Service) DrillHistory(limit int) ([]executor.DrillHistoryEntry, error)
- func (s *Service) ExportDrillHistory(format string, limit int) (contentType string, data []byte, err error)
- func (s *Service) ForcePushApprovals() *ForcePushStore
- func (s *Service) GetConfig() *model.Config
- func (s *Service) GetHistoryChannel(ctx context.Context, id uint) (*HistoryChannelDTO, error)
- func (s *Service) GetHistoryRun(ctx context.Context, id uint) (*HistoryRunDTO, error)
- func (s *Service) GetPlatform(ctx context.Context, key string) (*model.Platform, error)
- func (s *Service) GetPlatformByID(ctx context.Context, id uint) (*model.Platform, error)
- func (s *Service) GetRepo(ctx context.Context, key string) (*model.Repo, error)
- func (s *Service) GetRepoByKey(key string) (*model.Repo, error)
- func (s *Service) GetRepoDir(taskKey string) string
- func (s *Service) GetRule(ctx context.Context, id uint) (*model.WebhookRule, error)
- func (s *Service) GetTask(ctx context.Context, key string) (*model.SyncTask, error)
- func (s *Service) GetTempDir(taskKey string) string
- func (s *Service) HealthCheck() map[string]string
- func (s *Service) HealthSnapshot(ctx context.Context, limit int, driftByTask map[string]int) (*HealthSnapshot, error)
- func (s *Service) History() *HistoryService
- func (s *Service) HistoryApply(ctx context.Context, channelID uint) (*HistoryRunDTO, error)
- func (s *Service) HistoryPlan(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
- func (s *Service) HistoryPreview(ctx context.Context, channelID uint) (*PreviewReport, error)
- func (s *Service) HistoryPreviewMarkdown(ctx context.Context, channelID uint) (string, error)
- func (s *Service) HistoryPush(ctx context.Context, channelID uint) (*HistoryPushDTO, error)
- func (s *Service) HistoryPushRun(ctx context.Context, runID uint) (*HistoryPushDTO, error)
- func (s *Service) HistoryPushWithOptions(ctx context.Context, channelID uint, opts HistoryPushOptions) (*HistoryPushDTO, error)
- func (s *Service) HistoryResolve(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
- func (s *Service) HistoryRollback(ctx context.Context, runID uint, ref string) (*HistoryRollbackDTO, error)
- func (s *Service) HistorySync(ctx context.Context, opts HistorySyncOptions) (*HistorySyncReport, error)
- func (s *Service) ImportPublicOrg(ctx context.Context, req PublicOrgImportRequest) (*PublicOrgImportResult, error)
- func (s *Service) LegalHold() bool
- func (s *Service) ListBranches(ctx context.Context, repoKey string) ([]string, error)
- func (s *Service) ListBundles(taskKey string) ([]BundleInfo, error)
- func (s *Service) ListEvents(ctx context.Context, repoKey string, offset, limit int) ([]*model.WebhookEvent, int64, error)
- func (s *Service) ListHistory(ctx context.Context, taskKey string, offset, limit int) ([]*model.SyncRun, int64, error)
- func (s *Service) ListHistoryChannels(ctx context.Context, offset, limit int) ([]*HistoryChannelDTO, int64, error)
- func (s *Service) ListHistoryOverrides(ctx context.Context, channelID uint) ([]*HistoryOverrideDTO, error)
- func (s *Service) ListHistoryRuns(ctx context.Context, channelID uint, offset, limit int) ([]*HistoryRunDTO, int64, error)
- func (s *Service) ListHistoryTargets(ctx context.Context, channelID uint) ([]*HistoryTargetDTO, error)
- func (s *Service) ListMetadataBackups(_ context.Context, repoKey string) ([]MetadataBackupInfo, error)
- func (s *Service) ListOperations(ctx context.Context, offset, limit int, filter *dao.OperationLogFilter) ([]*model.OperationLog, int64, error)
- func (s *Service) ListPlatformRepos(ctx context.Context, key, page, perPage string) ([]*sdkprov.PlatformRepo, error)
- func (s *Service) ListPlatformWebhooks(ctx context.Context, repoKey string) ([]*sdkprov.PlatformWebhook, error)
- func (s *Service) ListPlatforms(ctx context.Context) ([]*model.Platform, error)
- func (s *Service) ListRepos(ctx context.Context, offset, limit int) ([]*model.Repo, int64, error)
- func (s *Service) ListReposByPlatform(ctx context.Context, platformKey string) ([]*model.Repo, error)
- func (s *Service) ListReposWithFilter(ctx context.Context, offset, limit int, filter *dao.RepoFilter) ([]*model.Repo, int64, error)
- func (s *Service) ListRules(ctx context.Context, repoKey string) ([]*model.WebhookRule, error)
- func (s *Service) ListStarredRepos(ctx context.Context, platformKey string, max int) ([]*sdkprov.PlatformRepo, error)
- func (s *Service) ListTasks(ctx context.Context, repoKey string, offset, limit int) ([]*model.SyncTask, int64, error)
- func (s *Service) MetadataBackupDir() string
- func (s *Service) Mirror() *MirrorService
- func (s *Service) OperationStats(ctx context.Context) (today, week, total int64, err error)
- func (s *Service) OpsTodo(ctx context.Context) []OpsTodoItem
- func (s *Service) OpsTrends(ctx context.Context, days int) (*OpsTrendsResult, error)
- func (s *Service) PreviewSync(ctx context.Context, req *model.PreviewSyncRequest) (*model.PreviewSyncResult, error)
- func (s *Service) PreviewTemplate(ctx context.Context, templateID string) (*tpl.Template, []TemplateMatch, error)
- func (s *Service) ProviderForPlatform(p *model.Platform, tokenOverride string) (sdkprov.Provider, error)
- func (s *Service) PushTaskBackup(ctx context.Context, task *model.SyncTask, workDir, remoteURL, refspec string, ...) (string, error)
- func (s *Service) RPOReport(rpoMaxSeconds int64) (*RPOReport, error)
- func (s *Service) ReceiveWebhook(ctx context.Context, repoKey string, payload *WebhookPayload) error
- func (s *Service) RecordOperation(ctx context.Context, entry *model.OperationLog) error
- func (s *Service) RegisterPlatformWebhook(ctx context.Context, repoKey, callbackURL, secret string, events []string) (*sdkprov.PlatformWebhook, error)
- func (s *Service) RepoInventory(ctx context.Context) (*InventoryResult, error)
- func (s *Service) ResolvePlatformToken(p *model.Platform) (string, error)
- func (s *Service) RestoreBundle(ctx context.Context, name, destDir string) error
- func (s *Service) RestoreMetadata(ctx context.Context, req RestoreRequest) (*RestoreResult, error)
- func (s *Service) RetryEvent(ctx context.Context, eventID uint) error
- func (s *Service) RotateHistoryTargetCredential(ctx context.Context, id uint, in HistoryCredentialInput) (*HistoryTargetDTO, error)
- func (s *Service) RunDRDrill(ctx context.Context, name string) (*DrillReport, error)
- func (s *Service) RunTask(ctx context.Context, taskKey string) error
- func (s *Service) RunTaskAsync(taskKey, trigger string, webhookEventID *uint) error
- func (s *Service) RunTaskWithTrigger(ctx context.Context, taskKey, trigger string, webhookEventID *uint) error
- func (s *Service) SampleMetadataVerify(_ context.Context, repoKey string, n int) (VerifyReport, error)
- func (s *Service) SetDefaultPlatform(ctx context.Context, key string) error
- func (s *Service) SetForcePushApprover(a executor.ForcePushApprover)
- func (s *Service) SetHistoryOverride(ctx context.Context, channelID uint, in HistoryOverrideInput) (*HistoryOverrideDTO, error)
- func (s *Service) SetTemplates(st TemplateStore)
- func (s *Service) Start() error
- func (s *Service) Stop()
- func (s *Service) SubscribeRuns(fn func(RunEvent)) (cancel func())
- func (s *Service) SyncPlatformRepos(ctx context.Context, key string) (int, error)
- func (s *Service) SyncPlatformReposFiltered(ctx context.Context, key string, filter *RepoImportFilter) (int, error)
- func (s *Service) Templates() TemplateStore
- func (s *Service) TestConnection(ctx context.Context, repoKey string) (*model.TestConnectionResult, error)
- func (s *Service) TestPlatformConnection(ctx context.Context, key string) (*sdkprov.TestConnectionResult, error)
- func (s *Service) UpdateHistoryChannel(ctx context.Context, id uint, in HistoryChannelInput) (*HistoryChannelDTO, error)
- func (s *Service) UpdateHistoryTarget(ctx context.Context, id uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
- func (s *Service) UpdatePlatform(ctx context.Context, platform *model.Platform) error
- func (s *Service) UpdatePlatformStatus(ctx context.Context, key, status, testResult string) error
- func (s *Service) UpdateRepo(ctx context.Context, req *model.UpdateRepoRequest) (*model.Repo, error)
- func (s *Service) UpdateRule(ctx context.Context, req *model.UpdateRuleRequest) (*model.WebhookRule, error)
- func (s *Service) UpdateRunStep(step *model.SyncRunStep) error
- func (s *Service) UpdateTask(ctx context.Context, req *model.UpdateTaskRequest) (*model.SyncTask, error)
- func (s *Service) UpdateTaskLastRun(task *model.SyncTask, run *model.SyncRun) error
- func (s *Service) VerifyAuditChain() (*AuditChainResult, error)
- func (s *Service) VerifyBackupManifest() (*executor.ManifestVerifyResult, error)
- func (s *Service) VerifyBundle(ctx context.Context, name string) (*BundleInfo, error)
- func (s *Service) VerifyDrillChain() (bool, int, string)
- func (s *Service) VerifyHistoryChannelChain(ctx context.Context, channelID uint) (*HistoryChainResult, error)
- type TargetImpact
- type TaskService
- func (ts *TaskService) CleanupOldRunSteps(ctx context.Context, maxAge time.Duration) (int64, error)
- func (ts *TaskService) CleanupOldRuns(ctx context.Context, maxAge time.Duration) (int64, error)
- func (ts *TaskService) CompleteRun(run *model.SyncRun) error
- func (ts *TaskService) CompleteRunWithTaskUpdate(run *model.SyncRun, task *model.SyncTask) error
- func (ts *TaskService) CountTasksByStatus() (map[string]int64, error)
- func (ts *TaskService) CreateRun(task *model.SyncTask, trigger string, webhookEventID *uint) (*model.SyncRun, error)
- func (ts *TaskService) CreateRunStep(step *model.SyncRunStep) error
- func (ts *TaskService) CreateTask(ctx context.Context, req *model.CreateTaskRequest) (*model.SyncTask, error)
- func (ts *TaskService) DeleteHistory(ctx context.Context, id uint) error
- func (ts *TaskService) DeleteTask(ctx context.Context, key string) error
- func (ts *TaskService) FindAllEnabledTasks() ([]*model.SyncTask, error)
- func (ts *TaskService) FindTaskByKey(key string) (*model.SyncTask, error)
- func (ts *TaskService) GetTask(ctx context.Context, key string) (*model.SyncTask, error)
- func (ts *TaskService) ListHistory(ctx context.Context, taskKey string, offset, limit int) ([]*model.SyncRun, int64, error)
- func (ts *TaskService) ListTasks(ctx context.Context, repoKey string, offset, limit int) ([]*model.SyncTask, int64, error)
- func (ts *TaskService) PreviewSync(ctx context.Context, req *model.PreviewSyncRequest) (*model.PreviewSyncResult, error)
- func (ts *TaskService) RecentRuns(offset, limit int) ([]*model.SyncRun, error)
- func (ts *TaskService) UpdateRunStep(step *model.SyncRunStep) error
- func (ts *TaskService) UpdateTask(ctx context.Context, req *model.UpdateTaskRequest) (*model.SyncTask, error)
- func (ts *TaskService) UpdateTaskLastRun(task *model.SyncTask, run *model.SyncRun) error
- type TemplateApplyResult
- type TemplateChange
- type TemplateMatch
- type TemplateStore
- type TrendPoint
- type VerifyReport
- type WebhookPayload
- type WebhookService
- func (ws *WebhookService) ApplyRules(ctx context.Context, repoKey string, event *model.WebhookEvent, ...)
- func (ws *WebhookService) CleanupOldEvents(ctx context.Context, maxAge time.Duration) (int64, error)
- func (ws *WebhookService) CreateRule(ctx context.Context, req *model.CreateRuleRequest) (*model.WebhookRule, error)
- func (ws *WebhookService) CreateWebhookEvent(event *model.WebhookEvent) error
- func (ws *WebhookService) DeleteRule(ctx context.Context, id uint) error
- func (ws *WebhookService) FindEventByEventID(eventID string) (*model.WebhookEvent, error)
- func (ws *WebhookService) FindEventByID(id uint) (*model.WebhookEvent, error)
- func (ws *WebhookService) GetRule(ctx context.Context, id uint) (*model.WebhookRule, error)
- func (ws *WebhookService) ListEvents(ctx context.Context, repoKey string, offset, limit int) ([]*model.WebhookEvent, int64, error)
- func (ws *WebhookService) ListRules(ctx context.Context, repoKey string) ([]*model.WebhookRule, error)
- func (ws *WebhookService) MarkEventProcessed(event *model.WebhookEvent) error
- func (ws *WebhookService) MarkEventProcessing(ctx context.Context, eventID uint) (*model.WebhookEvent, error)
- func (ws *WebhookService) UpdateRule(ctx context.Context, req *model.UpdateRuleRequest) (*model.WebhookRule, error)
Constants ¶
const ( // ForcePushAllow 允许强制覆盖目标侧独有提交 ForcePushAllow = model.ForcePushAllow // ForcePushBlock 遇分歧直接失败,不覆盖 ForcePushBlock = model.ForcePushBlock // ForcePushBackupOnDemand 覆盖前自动打 bundle 快照(可回滚) ForcePushBackupOnDemand = model.ForcePushBackupOnDemand )
const DriftDetectBudget = 30 * time.Second
DriftDetectBudget 漂移检测的**总**预算。
每个漂移任务都要 fetch 一次源端才能算出 ahead/behind(见 fetchDriftSource), 耗时与"漂移任务数 × 单次 fetch 耗时"成正比。上游慢、任务多时(200 个漂移任务 × 30s 拨号超时)整轮能跑到几十分钟,而调用方(HTTP/健康评分)早超时了 —— 服务端还在空转。
预算耗尽后,剩下的任务标为"未检查"如实报出,而不是继续跑或假装检查过。
Variables ¶
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") // ErrPlatformNotFound 平台记录缺失:查询"任意错误或空记录"统一归一化为此哨兵, // 文案是对外契约(壳层 404 回传),不可改动。 ErrPlatformNotFound = errors.New("platform not found") // ErrTargetPlatformNotFound 元数据回灌目标平台缺失(target_platform 查无记录)。 ErrTargetPlatformNotFound = errors.New("target platform not found") // ErrTemplateNotFound 策略模板缺失(壳层回 404,文案是对外契约)。 ErrTemplateNotFound = errors.New("template not found") // ErrTemplateCycle 模板继承链成环(壳层回 400,完整文案带链路)。 ErrTemplateCycle = errors.New("template extends cycle") // ErrStarredUnsupported 平台不支持 starred 列举(壳层回 400,文案是对外契约)。 ErrStarredUnsupported = errors.New("starred import currently supports github only") // ErrMetadataValidation 元数据请求/快照读取类错误的分类哨兵(壳层据此回 400)。 // 具体文案由 metadataError.Error() 给出(如 "no snapshot for <key>"、 // "sync.backup_dir not configured"),保持逐字契约。 ErrMetadataValidation = errors.New("metadata validation") // ErrBackupDisabled 冷备未启用(没配 sync.backup_dir)。 // 导出以便壳层把它映射成"可读提示"而不是笼统的 500。 ErrBackupDisabled = errors.New("backup dir not configured (sync.backup_dir)") )
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。 平台实现带 ctx;这里沿用历史签名(ctxTimeout),包一层超时。
func IsPersonalOwner ¶ added in v0.7.0
IsPersonalOwner 判定源 owner 是否个人命名空间。 orgOwners 为已知组织集合;owner 不在其中且等于 targetUser 时判为个人仓。
func MintGitHubAppJWT ¶ added in v0.6.0
MintGitHubAppJWT 用 App 私钥签发 JWT(RS256),iss=app_id,有效期最长 10 分钟。 这是 GitHub App 调 API 的第一层凭证,再换 installation access token。 签发逻辑在平台 githubapp.MintJWT,这里只保留导出名与错误风格。
func ResolvePlatformToken ¶ added in v0.6.0
ResolvePlatformToken 解析平台实际使用的访问令牌。 优先级:GitHub App installation token(若配置) > AccessToken。 App token 带缓存,过期前自动刷新。
func RewriteRepoURL ¶ added in v0.9.0
RewriteRepoURL 把 clone URL 中的 owner/repo 换成目标(支持 https 与 ssh)。
func ValidForcePushPolicy ¶ added in v0.6.0
ValidForcePushPolicy 校验策略字符串。
func ValidOrgMapStrategy ¶ added in v0.7.0
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 AutoRetryPolicy ¶ added in v0.9.0
type AutoRetryPolicy struct {
// MaxAutoRetries 失败后的自动重跑次数;0=不自动重跑
MaxAutoRetries int
// Cooldown 两次自动重跑之间的冷却
Cooldown time.Duration
}
AutoRetryPolicy 同一运行失败后的自动重跑策略。
type BackupManifest ¶ added in v0.6.0
type BackupManifest = executor.BackupManifest
BackupManifest = executor.BackupManifest
type BulkMirrorItem ¶ added in v0.9.0
BulkMirrorItem 单仓映射结果。Action: planned|imported|task_created|skipped|failed
type BulkMirrorRequest ¶ added in v0.9.0
type BulkMirrorRequest struct {
SourcePlatformKey string
SourceOrg string
// TargetPlatform 已校验存在的目标平台(建仓用 ID / InstanceURL)。
TargetPlatform *model.Platform
Strategy OrgMapStrategy
TargetOrg string
TargetUser string
ImportNew bool
CreateTasks bool
DryRun bool
}
BulkMirrorRequest 组织镜像请求(平台存在性校验由壳层完成并保留其文案)。
type BulkMirrorResult ¶ added in v0.9.0
type BulkMirrorResult struct {
Planned int
Imported int
TasksCreated int
Items []*BulkMirrorItem
Warnings []string
}
BulkMirrorResult 组织镜像结果。
type BundleInfo ¶ added in v0.5.1
type BundleInfo = executor.BundleInfo
BundleInfo bundle 文件信息(executor 同构,便于壳层直接用)。
type CreateMirrorChannelInput ¶
type CreateMirrorChannelInput struct {
Name string `json:"name"`
Mode string `json:"mode"`
RepoKey string `json:"repoKey"`
Targets []MirrorTargetInput `json:"targets"`
// ScrubRules 痕迹清理规则:发布前把内容里的内网痕迹清掉。
//
// 身份改写只管 module path;内网 registry / 部署代号 / 令牌
// 原样进公开 module 就是泄漏。
ScrubRules []MirrorScrubRuleInput `json:"scrubRules"`
}
type CredentialStatus ¶ added in v0.12.0
type CredentialStatus struct {
// TargetID 目标 ID。
TargetID uint `json:"target_id"`
// Name 目标名。
Name string `json:"name"`
// HasCredential 是否有凭据。
HasCredential bool `json:"has_credential"`
// UpdatedAt 凭据最后更新时间。
UpdatedAt string `json:"updated_at,omitempty"`
// ExpiresAt 凭据到期时间。
ExpiresAt string `json:"expires_at,omitempty"`
// Expired 已过期。
Expired bool `json:"expired"`
// ExpiringSoon 临期(7 天内)。
ExpiringSoon bool `json:"expiring_soon"`
// Note 说明。
Note string `json:"note"`
}
CredentialStatus 是一个推送目标的凭据状态。
type Decision ¶ added in v0.9.0
type Decision struct {
// Retry 是否应触发自动重跑
Retry bool
// Attempt 本次将要进行的第几次重跑(1 起)
Attempt int
// Reason 不重跑时的原因(可日志输出)
Reason string
}
Decision 一次判定结果。
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"`
// TargetBranch 目标分支(与实际比对的 SourceBranch 相对)。
TargetBranch string `json:"target_branch,omitempty"`
}
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 ErrorClass ¶ added in v0.9.0
type ErrorClass string
ErrorClass 错误到传输层(HTTP)的分类契约:壳层据此选状态码, 不必逐个 errors.Is 哨兵。core 只给类别,不绑任何 Web 框架。
const ( ErrorClassNotFound ErrorClass = "not_found" ErrorClassConflict ErrorClass = "conflict" ErrorClassValidation ErrorClass = "validation" ErrorClassAuth ErrorClass = "auth" ErrorClassRateLimited ErrorClass = "rate_limited" ErrorClassInternal ErrorClass = "internal" )
func Classify ¶ added in v0.9.0
func Classify(err error) ErrorClass
Classify 归类错误;err 为 nil 返回空串。 优先哨兵错误,其次 SDK provider 结构化错误,最后回落 internal。
type ExecuteMirrorRunInput ¶
type ForcePushApproval ¶ added in v0.9.0
type ForcePushApproval = model.ForcePushApproval
ForcePushApproval 一条审批记录(JSON 契约与历史文件逐字兼容)。
type ForcePushPolicy ¶ added in v0.6.0
type ForcePushPolicy = model.ForcePushPolicy
ForcePushPolicy 强制推送保护策略。 **权威实现在 model 包**(model.ResolveForcePushPolicy)——service 与 executor 共用同一份,避免两份平行实现漂移。此处保留别名,保持既有调用点不变。
func ResolveForcePushPolicy ¶ added in v0.6.0
func ResolveForcePushPolicy(t *model.SyncTask) ForcePushPolicy
ResolveForcePushPolicy 从任务配置解析策略。 委托 model.ResolveForcePushPolicy(唯一实现):空值 ⇒ block(最安全)。
type ForcePushStore ¶ added in v0.9.0
type ForcePushStore struct {
// contains filtered or unexported fields
}
ForcePushStore 审批存储,满足 executor.ForcePushApprover。
func NewForcePushStore ¶ added in v0.9.0
func NewForcePushStore(d *dao.ForcePushApprovalDAO) *ForcePushStore
NewForcePushStore 打开审批存储。
func (*ForcePushStore) Approve ¶ added in v0.9.0
func (st *ForcePushStore) Approve(id, actor string) (found bool, err error)
Approve 放行指定审批;未找到返回 found=false。
func (*ForcePushStore) ConsumeForcePushApproval ¶ added in v0.14.0
func (st *ForcePushStore) ConsumeForcePushApproval(taskKey, branch, targetRef string)
ConsumeForcePushApproval 消费掉一次放行(放行是一次性的)。
契约:"Admin 一次性放行后允许**本次** force" —— 用掉之后,同一任务同一分支 再出现分歧必须重新审批。记录保留(标 consumed_at),留住审计线索。
**targetRef 必须与判定时用的那个一致**:消费要精确落在"判定通过的那条"上, 否则被消费掉的可能是另一条放行,真正授权的那条仍可反复用(一次性形同常驻)。
func (*ForcePushStore) IsForcePushApproved ¶ added in v0.9.0
func (st *ForcePushStore) IsForcePushApproved(taskKey, branch, targetRef string) bool
IsForcePushApproved 查询任务+分支是否已放行**且尚未被用掉**(executor 分歧保护回调)。
func (*ForcePushStore) List ¶ added in v0.9.0
func (st *ForcePushStore) List() []ForcePushApproval
List 返回全部审批(按创建时间升序,与历史文件 append 顺序一致)。
func (*ForcePushStore) PendingCount ¶ added in v0.9.0
func (st *ForcePushStore) PendingCount() int
PendingCount 未放行条数。
func (*ForcePushStore) Request ¶ added in v0.9.0
func (st *ForcePushStore) Request(taskKey, branch, reason, targetRef string) (ForcePushApproval, error)
Request 追加一条 pending 审批(HTTP 端点语义:不幂等,调用方校验入参)。
func (*ForcePushStore) RequestApproval ¶ added in v0.9.0
func (st *ForcePushStore) RequestApproval(taskKey, branch, reason, targetRef string)
RequestApproval 满足 executor.ForcePushApprover:同 task+branch 已有 pending 则跳过, 写失败 best-effort(不影响同步主流程)。
type GateReport ¶ added in v0.12.0
type GateReport struct {
// OK 全部门禁通过。
OK bool `json:"ok"`
// GofmtViolations 物化结果中违反 gofmt 的文件。
GofmtViolations []string `json:"gofmt_violations,omitempty"`
// TypeCheckErr 类型门禁的错误信息。
TypeCheckErr string `json:"type_check_err,omitempty"`
// Note 结论说明。
Note string `json:"note"`
}
GateReport 是发布前的门禁结果。
type HealthScoreItem ¶ added in v0.9.0
type HealthScoreItem struct {
Key string `json:"key"`
Name string `json:"name"`
Score int `json:"score"` // 0-100
Level string `json:"level"` // gold/silver/bronze/basic
Issues []string `json:"issues,omitempty"`
// Dimensions 分项:reliability / freshness / schedule / safety / completeness
Dimensions []health.Dimension `json:"dimensions,omitempty"`
// Actions 建议动作(CLI 命令或人工步骤)
Actions []string `json:"actions,omitempty"`
// ActionItems 结构化动作(带可复制命令)
ActionItems []health.Action `json:"action_items,omitempty"`
}
HealthScoreItem 单仓库/任务健康分(含 Scorecards 风格维度)。 JSON 标签与壳层历史响应逐字一致,前端/CLI 依赖。
type HealthSnapshot ¶ added in v0.9.0
type HealthSnapshot struct {
Items []HealthScoreItem
Summary HealthSummary
}
HealthSnapshot 一次评分的完整结果。
type HealthSummary ¶ added in v0.9.0
type HealthSummary struct {
Levels map[string]int `json:"levels"`
BelowSilver int `json:"below_silver"`
TopActions []string `json:"top_actions"`
Attention []HealthScoreItem `json:"attention"`
}
HealthSummary 评分列表的聚合视图。
type HistoryChainResult ¶ added in v0.12.0
type HistoryChainResult struct {
// OK 链完整。
OK bool `json:"ok"`
// Checked 已校验的记录数。
Checked int `json:"checked"`
// BrokenAt 链断裂处的记录 ID。
BrokenAt uint `json:"broken_at,omitempty"`
// Message 结论说明。
Message string `json:"message"`
}
HistoryChainResult 是通道内执行记录链的校验结果。
type HistoryChannelDTO ¶ added in v0.12.0
type HistoryChannelDTO struct {
ID uint `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
// Targets 推送目标(顺序 = 优先级:先留底后发布)。
Targets []*HistoryTargetDTO `json:"targets,omitempty"`
}
HistoryChannelDTO 是通道的响应视图。
type HistoryChannelInput ¶ added in v0.12.0
type HistoryChannelInput struct {
// Name 通道名(唯一)。
Name string `json:"name"`
//
// 下面这些字段用**指针**:区分「未指定」(nil)与「显式给值」
// (含显式清空 —— 指向空串)。
//
// 为什么必须区分:更新是**部分更新**语义。用普通 string 的话,
// 「只改一下目录」会把没提到的字段一起抹成空 ——
// 身份映射(module_source/module_target)被抹掉后,
// 执行时就没有任何身份规则,内网 module path 会**原样**进公开仓。
// 这不是理论风险:只传目录的更新请求就能造成。
//
// 线上格式不变:指针与值序列化出来是同一个 JSON,
// 缺字段 → nil,给了空串 → 指向空串。
//
// SourceRepoKey / TargetRepoKey 两侧仓库 key(取自 Repo 表)。
SourceRepoKey *string `json:"source_repo_key"`
TargetRepoKey *string `json:"target_repo_key"`
// SourceDir / TargetDir 本地路径直连(与 repo key 二选一)。
SourceDir *string `json:"source_dir"`
TargetDir *string `json:"target_dir"`
// ModuleSource / ModuleTarget 身份映射(创建时必填)。
ModuleSource *string `json:"module_source"`
ModuleTarget *string `json:"module_target"`
// HostSource / HostTarget 主机名映射(可选)。
HostSource *string `json:"host_source"`
HostTarget *string `json:"host_target"`
// AuthorName / AuthorEmail 目标侧新提交的作者身份(公开形态)。
//
// 留空则用中性的公开身份。**不继承源提交的作者** ——
// 源侧作者是内网开发者,继承等于把内网人员信息发到公开仓。
AuthorName *string `json:"author_name"`
AuthorEmail *string `json:"author_email"`
// PathRules 路径规则。
PathRules []PathRuleDTO `json:"path_rules"`
// ScrubRules 痕迹规则。
ScrubRules []ScrubRuleDTO `json:"scrub_rules"`
// ConflictRules 冲突自动判据;空 = 不启用。
ConflictRules []history.ConflictRuleConfig `json:"conflict_rules,omitempty"`
// SourceBranch / TargetBranch 分支。
SourceBranch *string `json:"source_branch"`
TargetBranch *string `json:"target_branch"`
// Enabled 是否启用。
//
// 用指针区分「未指定」(nil:创建时默认启用,更新时保持原值)
// 与「显式禁用」(false)—— 用普通 bool 的话,false 与未指定无法区分。
Enabled *bool `json:"enabled,omitempty"`
}
HistoryChannelInput 通道的创建/更新入参。
type HistoryCredentialInput ¶ added in v0.12.0
type HistoryCredentialInput struct {
// CredType 凭据类型:none / token / ssh_key。
CredType string `json:"cred_type"`
// Credential 凭据明文(明文只在传输中出现,落库即加密)。
Credential string `json:"credential"`
// Username HTTPS Basic 用户名(token 类用)。
Username string `json:"username"`
// ExpiresAt 凭据到期时间(可选)。
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
HistoryCredentialInput 是轮换凭据的入参。
轮换**只换密钥**:URL、目标名都不动 —— 换密钥是常规运维动作, 不该有机会顺手改掉推送到哪里。
type HistoryOptionsDTO ¶ added in v0.12.0
type HistoryOptionsDTO struct {
// SourceDir 内部源仓本地路径。
SourceDir string `json:"source_dir"`
// TargetDir 公开目标仓本地路径。
TargetDir string `json:"target_dir"`
// SourceRef 源仓比对 ref,默认 HEAD。
SourceRef string `json:"source_ref"`
// TargetRef 目标仓分支,默认 main。
TargetRef string `json:"target_ref"`
// Rules 身份映射规则。
Rules []IdentityRuleDTO `json:"rules"`
// PathRules 路径规则。
PathRules []PathRuleDTO `json:"path_rules"`
// ScrubRules 痕迹规则。
ScrubRules []ScrubRuleDTO `json:"scrub_rules"`
// ConflictRules 冲突自动判据;空 = 不启用。
ConflictRules []history.ConflictRuleConfig `json:"conflict_rules,omitempty"`
}
HistoryOptionsDTO 一次历史同步的**执行参数**(由通道解析而来)。
调用方不直接构造它:走 HistoryPlan/HistoryResolve 等方法时传 channel id, 由服务端按通道配置解析。保留它只是为了给「预演一份未入库的配置」用。
type HistoryOverrideDTO ¶ added in v0.12.0
type HistoryOverrideDTO struct {
ID uint `json:"id"`
ChannelID uint `json:"channel_id"`
Path string `json:"path"`
SourcePath string `json:"source_path"`
Verdict string `json:"verdict"`
Content string `json:"content,omitempty"`
Reason string `json:"reason"`
DecidedBy string `json:"decided_by"`
CreatedAt string `json:"created_at"`
}
HistoryOverrideDTO 是裁决的响应视图。
type HistoryOverrideInput ¶ added in v0.12.0
type HistoryOverrideInput struct {
// Path 目标侧路径(裁决定位键)。
Path string `json:"path"`
// SourcePath 源侧路径(可选,回溯用)。
SourcePath string `json:"source_path"`
// Verdict 裁决:keep_target / take_source / merged。
Verdict string `json:"verdict"`
// Content 裁决后的内容(仅 merged 时必填)。
Content string `json:"content"`
// Reason 裁决理由(审计用)。
Reason string `json:"reason"`
// DecidedBy 裁决者(人工或 AI 标识)。
DecidedBy string `json:"decided_by"`
}
HistoryOverrideInput 是裁决的入参。
type HistoryPlanDTO ¶ added in v0.12.0
type HistoryPlanDTO struct {
// ChannelID 计划所属的通道。
ChannelID uint `json:"channel_id"`
// Summary 统计。
Summary history.Summary `json:"summary"`
// Files 逐文件处置。
Files []history.FilePlan `json:"files"`
// Commits 按源侧提交分组的回滚视图。
Commits []history.CommitPlan `json:"commits"`
// Resolutions hold 文件的解法。
Resolutions map[string]history.Resolution `json:"resolutions,omitempty"`
// Dossiers 仍需人工裁决的卷宗(仅 resolve 时返回)。
Dossiers []history.ConflictDossier `json:"dossiers,omitempty"`
}
HistoryPlanDTO 是一份同步计划的精简视图。
type HistoryPushDTO ¶ added in v0.12.0
type HistoryPushDTO struct {
// RunID 被推送的执行记录。
RunID uint `json:"run_id"`
// Pushed 成功推送的远端(按顺序)。
Pushed []string `json:"pushed"`
// Heads 各远端推送后的 HEAD。
Heads map[string]string `json:"heads"`
// Error 推送失败的原因(成功时为空)。
//
// 推送失败时**仍然要带回这条**:
// 「移植成功、推送失败」是最需要人接手的局面 ——
// 产物已经在本地,重试推送靠的就是它。
Error string `json:"error,omitempty"`
}
HistoryPushDTO 是一次推送的结果。
type HistoryPushOptions ¶ added in v0.13.0
type HistoryPushOptions struct {
// Force 强制推送:即使远端与本次移植的基线已分叉也照样覆盖。
//
// 默认不强制 —— 强推会把远端的提交**静默丢掉**
// (实测:远端别人的提交被丢弃后只剩 0 条)。
// 要强制,必须由人明确指定。
Force bool `json:"force,omitempty"`
// ForceApprovedBy 强制推送的批准者标识。
//
// **强制推送必须有批准者**:入口层校验角色是 admin 后把批准者填进来,
// core 只认「有人批准过」这个事实。
//
// 为什么要下沉到 core:入口有三条(HTTP / MCP / AI 助手),
// 任何一条忘了判角色,闸门就形同虚设 —— 放在 core 才能一劳永逸。
// (实测:MCP 端点只判了「能写」,operator 就能强推覆盖远端提交。)
ForceApprovedBy string `json:"force_approved_by,omitempty"`
}
HistoryPushOptions 是推送的选项。
type HistoryRollbackDTO ¶ added in v0.12.0
type HistoryRollbackDTO struct {
// RunID 回滚依据的执行记录。
RunID uint `json:"run_id"`
// Ref 回滚到的 ref。
Ref string `json:"ref"`
// Pushed 执行回滚的远端。
Pushed []string `json:"pushed"`
// Heads 回滚后各远端的 HEAD。
Heads map[string]string `json:"heads"`
}
HistoryRollbackDTO 是回滚的结果。
type HistoryRunDTO ¶ added in v0.12.0
type HistoryRunDTO struct {
ID uint `json:"id"`
ChannelID uint `json:"channel_id"`
// Kind 记录类别:apply / push / rollback。
Kind string `json:"kind"`
// PushedRunID push/rollback 引用被操作的 apply 记录。
PushedRunID uint `json:"pushed_run_id,omitempty"`
Status string `json:"status"`
BaseHead string `json:"base_head"`
Head string `json:"head"`
PlanSummary string `json:"plan_summary"`
Commits string `json:"commits"`
Files string `json:"files"`
Skipped string `json:"skipped"`
// ScrubReport 痕迹检测报告(JSON 字符串)。
//
// 形状:{"hits":[{rule,category,line,text,mandatory}...],
// "mandatory":[{...}...]}
// - hits:本次发布涉及的全部痕迹命中(含已自动清理的);
// - mandatory:其中**强制人工处理**的子集(密钥类)。
//
// 两者必须分开:自动清理类的命中**已随内容发布**,
// 强制人工类的命中意味着**这个文件没有被发布**。
// 混在一起会让人以为密钥已处理。
ScrubReport string `json:"scrub_report"`
GateReport string `json:"gate_report"`
RefsBefore string `json:"refs_before"`
RefsAfter string `json:"refs_after"`
Error string `json:"error"`
PrevHash string `json:"prev_hash"`
EntryHash string `json:"entry_hash"`
StartedAt string `json:"started_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
DurationMs int64 `json:"duration_ms"`
CreatedAt string `json:"created_at"`
}
HistoryRunDTO 是执行记录的响应视图。
type HistoryService ¶ added in v0.12.0
type HistoryService struct {
// contains filtered or unexported fields
}
HistoryService 历史同步服务。
**接口是通道优先的**:
- 配置只存在通道里(通道 + 推送目标两张表),调用方不重传规则;
- 执行按 channel id 进行:plan / resolve / apply / push;
- apply 产出**执行记录(run)**,服务端自己记住产物路径, 调用方不必回传服务端的临时路径;
- run 同时是审计留痕与回滚锚点。
与 MirrorService(身份镜像)并存,语义不同:
- MirrorService:同一仓库的多个身份,每 tag 一个孤儿快照;
- HistoryService:两个有完整历史的仓库,按内容差异叠加, 目标树的既有提交原样保留。
func NewHistoryService ¶ added in v0.12.0
func NewHistoryService(svc *Service, db *gorm.DB) (*HistoryService, error)
NewHistoryService 构造历史同步服务。
func (*HistoryService) CreateHistoryChannel ¶ added in v0.12.0
func (h *HistoryService) CreateHistoryChannel(_ context.Context, in HistoryChannelInput) (*HistoryChannelDTO, error)
CreateHistoryChannel 新建历史同步通道。
func (*HistoryService) CreateHistoryTarget ¶ added in v0.12.0
func (h *HistoryService) CreateHistoryTarget(_ context.Context, channelID uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
CreateHistoryTarget 新建推送目标。
目标顺序即推送优先级:**第一个是留底,其后才是发布**。
func (*HistoryService) DeleteHistoryChannel ¶ added in v0.12.0
func (h *HistoryService) DeleteHistoryChannel(ctx context.Context, id uint) error
DeleteHistoryChannel 删除通道(连同其推送目标)。
func (*HistoryService) DeleteHistoryOverride ¶ added in v0.12.0
func (h *HistoryService) DeleteHistoryOverride(_ context.Context, id uint) error
DeleteHistoryOverride 删除一条裁决(回到自动判定)。
func (*HistoryService) DeleteHistoryTarget ¶ added in v0.12.0
func (h *HistoryService) DeleteHistoryTarget(_ context.Context, id uint) error
DeleteHistoryTarget 删除推送目标。
func (*HistoryService) GetHistoryChannel ¶ added in v0.12.0
func (h *HistoryService) GetHistoryChannel(_ context.Context, id uint) (*HistoryChannelDTO, error)
GetHistoryChannel 取通道详情。
func (*HistoryService) GetHistoryRun ¶ added in v0.12.0
func (h *HistoryService) GetHistoryRun(_ context.Context, id uint) (*HistoryRunDTO, error)
GetHistoryRun 取执行记录详情。
func (*HistoryService) HistoryApply ¶ added in v0.12.0
func (h *HistoryService) HistoryApply(ctx context.Context, channelID uint) (*HistoryRunDTO, error)
HistoryApply 按通道把计划落到目标树,产出执行记录。
纯本地操作:不推送、不改原始目标仓。 产物路径记在执行记录里,推送时服务端自己取。
func (*HistoryService) HistoryPlan ¶ added in v0.12.0
func (h *HistoryService) HistoryPlan(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
HistoryPlan 按通道生成同步计划(纯读)。
func (*HistoryService) HistoryPreview ¶ added in v0.12.0
func (h *HistoryService) HistoryPreview(ctx context.Context, channelID uint) (*PreviewReport, error)
HistoryPreview 执行预检。
**不推送、不改原始目标仓**:物化与门禁都在临时工作副本上进行。 预检的结论必须与真正执行时的结论一致 —— 两者跑的是同一套代码路径。
func (*HistoryService) HistoryPush ¶ added in v0.12.0
func (h *HistoryService) HistoryPush(ctx context.Context, channelID uint) (*HistoryPushDTO, error)
HistoryPush 按通道推送**最近一次**执行记录的产物。
func (*HistoryService) HistoryPushRun ¶ added in v0.12.0
func (h *HistoryService) HistoryPushRun(ctx context.Context, runID uint) (*HistoryPushDTO, error)
HistoryPushRun 推送指定执行记录的产物。
func (*HistoryService) HistoryPushWithOptions ¶ added in v0.13.0
func (h *HistoryService) HistoryPushWithOptions(ctx context.Context, channelID uint, opts HistoryPushOptions) (*HistoryPushDTO, error)
HistoryPushWithOptions 按通道推送**最近一次**执行记录的产物。
Force=true 时跳过**分叉检查**:远端有我们不知道的提交也照样覆盖。 默认跳过 —— 强推会把远端的提交静默丢掉(实测:远端别人的提交 被丢弃后只剩 0 条),这种事必须由人明确点头。
func (*HistoryService) HistoryResolve ¶ added in v0.12.0
func (h *HistoryService) HistoryResolve(ctx context.Context, channelID uint) (*HistoryPlanDTO, error)
HistoryResolve 按通道生成计划并计算 hold 的自动解法。
func (*HistoryService) HistoryRollback ¶ added in v0.12.0
func (h *HistoryService) HistoryRollback(ctx context.Context, runID uint, ref string) (*HistoryRollbackDTO, error)
HistoryRollback 把目标树回滚到指定 ref。
保障来自通道的**留底目标**(第一个):从留底取回该 ref 的对象, 再强推到发布目标。危险操作:调用方须显式确认。
func (*HistoryService) HistorySync ¶ added in v0.12.0
func (h *HistoryService) HistorySync(ctx context.Context, opts HistorySyncOptions) (*HistorySyncReport, error)
HistorySync 一次跑完「预检 → 移植 → 推送」。
有阻塞项时**停下并报告**,不擅自往下走:
- 门禁不通过(推出去编译不过);
- 还有待人工裁决的冲突;
- 需要强推(可能覆盖远端别人的提交)。
这三件事都不是「程序能替用户决定的」—— 停下让人看,比推上去再回滚便宜。
func (*HistoryService) ListHistoryChannels ¶ added in v0.12.0
func (h *HistoryService) ListHistoryChannels(_ context.Context, offset, limit int) ([]*HistoryChannelDTO, int64, error)
ListHistoryChannels 列出通道。
func (*HistoryService) ListHistoryOverrides ¶ added in v0.12.0
func (h *HistoryService) ListHistoryOverrides(_ context.Context, channelID uint) ([]*HistoryOverrideDTO, error)
ListHistoryOverrides 列出通道的裁决。
func (*HistoryService) ListHistoryRuns ¶ added in v0.12.0
func (h *HistoryService) ListHistoryRuns(_ context.Context, channelID uint, offset, limit int) ([]*HistoryRunDTO, int64, error)
ListHistoryRuns 列出通道的执行记录。
func (*HistoryService) ListHistoryTargets ¶ added in v0.12.0
func (h *HistoryService) ListHistoryTargets(_ context.Context, channelID uint) ([]*HistoryTargetDTO, error)
ListHistoryTargets 列出通道的推送目标(按推送优先级)。
func (*HistoryService) MaterializeRuns ¶ added in v0.13.0
func (h *HistoryService) MaterializeRuns() int64
MaterializeRuns 返回本进程累计的物化次数(可观测性指标)。
func (*HistoryService) RotateHistoryTargetCredential ¶ added in v0.12.0
func (h *HistoryService) RotateHistoryTargetCredential(_ context.Context, id uint, in HistoryCredentialInput) (*HistoryTargetDTO, error)
RotateHistoryTargetCredential 轮换一个推送目标的凭据。
与 UpdateHistoryTarget 的区别:**只改凭据**,不碰 URL / 目标名 —— 换密钥是常规运维动作,不该有机会顺手改掉推送到哪里。
func (*HistoryService) SetHistoryOverride ¶ added in v0.12.0
func (h *HistoryService) SetHistoryOverride(ctx context.Context, channelID uint, in HistoryOverrideInput) (*HistoryOverrideDTO, error)
SetHistoryOverride 写入(或覆盖)一条裁决。
裁决只对 hold 生效;写入后重新 resolve 即按裁决出解,apply 时用裁决内容。
func (*HistoryService) UpdateHistoryChannel ¶ added in v0.12.0
func (h *HistoryService) UpdateHistoryChannel(ctx context.Context, id uint, in HistoryChannelInput) (*HistoryChannelDTO, error)
UpdateHistoryChannel 更新通道。
func (*HistoryService) UpdateHistoryTarget ¶ added in v0.12.0
func (h *HistoryService) UpdateHistoryTarget(_ context.Context, id uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
UpdateHistoryTarget 更新推送目标。
func (*HistoryService) VerifyHistoryChannelChain ¶ added in v0.12.0
func (h *HistoryService) VerifyHistoryChannelChain(_ context.Context, channelID uint) (*HistoryChainResult, error)
VerifyHistoryChannelChain 校验通道内执行记录的哈希链。
与既有审计链(OperationLog)同构,但**链在通道内**: 不同通道的同步记录混在一条链里没有意义,而且链会随通道数无限增长。
执行中的记录(没有哈希)被跳过,但会记在结论里 —— 它们不是链的一部分。
type HistorySyncOptions ¶ added in v0.12.0
type HistorySyncOptions struct {
// ChannelID 通道 ID。
ChannelID uint
// Force 有阻塞项时也继续(调用方仍应让用户确认)。
Force bool
// ForcePush 强制推送:远端与本次移植的基线已分叉也照样覆盖。
//
// 与 Force 分开:「忽略阻塞项继续」和「覆盖远端已有的提交」是两件事,
// 不该共用一个开关 —— 后者会丢掉远端别人的提交。
ForcePush bool
// ForcePushApprovedBy 强制推送的批准者标识(非空 = 已有人批准)。
//
// **强制推送必须有批准者**:入口层校验角色是 admin 后把批准者填进来,
// core 只认「有人批准过」这个事实。放在 core 才能一劳永逸 ——
// 入口有三条(HTTP / MCP / AI 助手),任何一条忘了判角色闸门就形同虚设。
ForcePushApprovedBy string
}
HistorySyncOptions 是一次同步的选项。
type HistorySyncReport ¶ added in v0.12.0
type HistorySyncReport struct {
// Preview 预检结论。
Preview *PreviewReport `json:"preview"`
// Apply 移植结果(未执行时为空)。
Apply *HistoryRunDTO `json:"apply,omitempty"`
// Push 推送结果(未执行时为空)。
Push *HistoryPushDTO `json:"push,omitempty"`
// Blocked 阻塞项;非空表示**没有往下走**。
Blocked []string `json:"blocked,omitempty"`
}
HistorySyncReport 是一次同步的结果。
type HistoryTargetDTO ¶ added in v0.12.0
type HistoryTargetDTO struct {
ID uint `json:"id"`
ChannelID uint `json:"channel_id"`
Name string `json:"name"`
RepoURL string `json:"repo_url"`
CredType string `json:"cred_type"`
Username string `json:"username"`
HasCredential bool `json:"has_credential"`
}
HistoryTargetDTO 是推送目标的响应视图(不回显凭据)。
type HistoryTargetInput ¶ added in v0.12.0
type HistoryTargetInput struct {
// Name 目标名(backup / publish)。
Name string `json:"name"`
// RepoURL 远端地址。
RepoURL string `json:"repo_url"`
// CredType 凭据类型:none / token / ssh_key。
CredType string `json:"cred_type"`
// Credential 凭据明文(入参);落库时加密,响应不回显。
Credential string `json:"credential"`
// Username HTTPS Basic 用户名(token 类凭据用)。
Username string `json:"username"`
}
HistoryTargetInput 是推送目标的创建/更新入参。
type IdentityRuleDTO ¶ added in v0.12.0
type IdentityRuleDTO struct {
// Source 待替换的源标识。
Source string `json:"source"`
// Target 替换后的目标标识;为空表示剥离。
Target string `json:"target"`
// Kind 规则种类:module / host / literal,默认 module。
Kind string `json:"kind"`
}
IdentityRuleDTO 是一条身份映射规则。
type InventoryItem ¶ added in v0.9.0
type InventoryItem struct {
RepoKey string `json:"repo_key"`
RepoName string `json:"repo_name"`
Platform string `json:"platform,omitempty"`
Status string `json:"status,omitempty"`
HasTask bool `json:"has_task"`
TaskKeys []string `json:"task_keys,omitempty"`
LastRunStatus string `json:"last_run_status,omitempty"`
LastRunAt string `json:"last_run_at,omitempty"`
Coverage string `json:"coverage"` // covered | no_task | stale | failing
}
InventoryItem 仓库资产盘点项:有没有任务覆盖、最近执行。
type InventoryResult ¶ added in v0.9.0
type InventoryResult struct {
Items []InventoryItem
Covered int
Orphan int
Failing int
}
InventoryResult 资产盘点汇总。
type ManifestVerifyResult ¶ added in v0.6.0
type ManifestVerifyResult = executor.ManifestVerifyResult
ManifestVerifyResult = executor.ManifestVerifyResult
type MetadataBackupInfo ¶ added in v0.9.0
type MetadataBackupInfo = MetadataSnapshot
MetadataBackupInfo 列表条目(与快照清单同构)。
type MetadataBackupOptions ¶ added in v0.9.0
type MetadataBackupOptions struct {
RepoKey string
MaxIssues int
MaxPRs int
MaxReleases int
MaxGists int
MaxAssets int
IncludeIssues bool
IncludePRs bool
IncludeReleases bool
IncludeSource bool // 源码归档(原 with_archives)
IncludeAssets bool // Release 附件(另受 Capabilities().ReleaseAssets 门控)
IncludeGists bool // Gists(另受 Capabilities().Gists 门控)
Since string
DryRun bool // 预留:当前备份无 dry-run 入参(壳层恒 false),不影响落盘行为
}
MetadataBackupOptions 元数据备份入参。 上限 ≤0 时按引擎缺省:issues/PRs/releases=500(>2000 截到 2000,与壳 max_items 口径一致)、gists=200、assets=100。 Include* 为解析后的布尔(壳层 optBoolDefault 缺省全开语义在壳侧完成)。 Since 为 RFC3339 增量:仅保留 updatedAt >= since 的 issue。
type MetadataBackupResult ¶ added in v0.9.0
type MetadataBackupResult struct {
MetadataSnapshot
Truncated bool
}
MetadataBackupResult 备份结果:嵌入快照字段(壳层整体转换为 ops.MetadataSnapshot)。 Truncated 为信息性标记(任一集合拉满上限即 true),不进 manifest/HTTP 响应。
type MetadataSnapshot ¶ added in v0.9.0
type MetadataSnapshot struct {
RepoKey string `json:"repo_key"`
Platform string `json:"platform"`
Owner string `json:"owner"`
Repo string `json:"repo"`
CreatedAt string `json:"created_at"`
Dir string `json:"dir"`
Counts map[string]int32 `json:"counts"`
Files []string `json:"files"`
Archives []string `json:"archives"`
Assets []string `json:"assets"`
Warnings []string `json:"warnings"`
// contains filtered or unexported fields
}
MetadataSnapshot 元数据快照清单(manifest.json 与 HTTP 响应共用结构)。 字段顺序与 JSON 标签对齐壳层 biz/model/ops.MetadataSnapshot(IDL 生成), 保证落盘文件与响应体逐字节兼容。
type MirrorScrubRuleInput ¶ added in v0.13.0
type MirrorScrubRuleInput struct {
// Name 规则名(出现在命中报告里)。
Name string `json:"name"`
// Category 类别分组(如 "internal-host" / "secret"),仅用于展示。
Category string `json:"category"`
// Pattern 正则源码。
Pattern string `json:"pattern"`
// Severity 处理强度:auto / mandatory,默认 auto。
//
// mandatory(密钥类)命中即**中止发布** —— 不做自动替换,
// 也不允许它进公开 module。
Severity string `json:"severity"`
// Replacement 命中后的替换文本;auto 且为空表示删除。
Replacement string `json:"replacement"`
}
MirrorScrubRuleInput 是一条痕迹清理规则的入参。
形状与历史同步侧一致(见 service.ScrubRuleDTO)。
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"`
// InsecureSkipTLS 跳过 TLS 校验(SSH 下等价于跳过主机密钥校验)。
InsecureSkipTLS bool `json:"insecureSkipTLS"`
// HostKeyFingerprint 期望的 SSH 主机公钥指纹("SHA256:xxx" 或裸 base64)。
// 设置后连接时校验公钥指纹必须一致,否则拒绝(防 MITM)。
HostKeyFingerprint string `json:"hostKeyFingerprint"`
// KnownHostsPath 指定 known_hosts 文件(空 = 用 ~/.ssh/known_hosts)。
KnownHostsPath string `json:"knownHostsPath"`
}
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 OpsTodoItem ¶ added in v0.9.0
type OpsTodoItem struct {
ID string `json:"id"`
Kind string `json:"kind"` // health | orphan | rpo | drift
Priority int `json:"priority"` // 1=紧急
TaskKey string `json:"task_key,omitempty"`
RepoKey string `json:"repo_key,omitempty"`
Title string `json:"title"`
Reason string `json:"reason,omitempty"`
Actions []health.Action `json:"actions,omitempty"`
}
OpsTodoItem 统一待办项(Renovate Dependency Dashboard 模式)。
type OpsTrendsResult ¶ added in v0.9.0
type OpsTrendsResult struct {
Days int
Items []*TrendPoint
Total int
Success int
Failed int
SuccessRate float64
}
OpsTrendsResult 趋势序列 + 汇总。
type Option ¶ added in v0.9.0
type Option func(*serviceOptions)
Option 装配期依赖注入。全部在 NewService 之前生效, 取代此前"先 SetProviderHooks 再 NewService"的时序约定。
func WithForcePushApprover ¶ added in v0.9.0
func WithForcePushApprover(a executor.ForcePushApprover) Option
WithForcePushApprover 注入分歧保护的审批实现(壳层 HTTP 审批流)。
func WithProviderHooks ¶ added in v0.9.0
WithProviderHooks 注入 provider 请求/响应生命周期钩子(壳层限流指标等)。 每次 provider 构造都会带上,无需再在 NewService 之前调用全局 SetProviderHooks。
type OrgMapOptions ¶ added in v0.9.0
type OrgMapOptions struct {
// Strategy 策略;空视为 preserve。
Strategy OrgMapStrategy
// TargetOrg single 落点;MixedOrgToTarget 时作 mixed 组织仓落点。
TargetOrg string
// TargetUser flat 与 mixed 个人仓落点。
TargetUser string
// SourceIsPersonal 源为个人命名空间(mixed 个人仓判定)。
// 组织镜像侧可用 IsPersonalOwner(owner, TargetUser, nil) 得到「owner 已等于目标用户」的等价判定。
SourceIsPersonal bool
// PreserveRedirect=true 时 preserve 分支按落点重定向:
// 组织仓→TargetOrg、个人仓→TargetUser;false 保持源 owner。
PreserveRedirect bool
// MixedOrgToTarget=true 时 mixed 组织仓落 TargetOrg;false 保持源 owner。
MixedOrgToTarget bool
// RequireTarget=true 时 single/flat/mixed 个人仓缺落点返回错误;false 回落源 owner。
RequireTarget bool
// SourceKey owner/repo 为空时从此解析,支持 "platform/owner/repo" 或 "owner/repo"。
SourceKey string
// TargetPlatform 非空时拼 Result.Key。
TargetPlatform string
}
OrgMapOptions 目标 owner/repo 落点选项。
各调用方语义不同,用显式开关表达,core 不做隐式改写:
导入(org_import):RequireTarget=true, MixedOrgToTarget=false, PreserveRedirect=false 组织镜像(org_mirror):MixedOrgToTarget=true, PreserveRedirect=false 落点缺失时 RequireTarget=true 报错,false 静默回落源 owner。
type OrgMapResult ¶ added in v0.9.0
type OrgMapResult struct {
Owner string
Repo string
// Key 形如 <platform>/<owner>/<repo>,仅 TargetPlatform 非空时填充。
Key string
}
OrgMapResult 映射结果。
func ResolveOrgTarget ¶ added in v0.7.0
func ResolveOrgTarget(sourceOwner, sourceRepo string, o OrgMapOptions) (OrgMapResult, error)
ResolveOrgTarget 计算目标 owner/repo。策略语义见 OrgMapOptions 注释。
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;组织仓→见 OrgMapOptions.MixedOrgToTarget。 OrgMapMixed OrgMapStrategy = "mixed" )
func ParseStrategy ¶ added in v0.9.0
func ParseStrategy(s string) (OrgMapStrategy, error)
ParseStrategy 解析策略名;空串视为 preserve。
type OrgRepoItem ¶ added in v0.9.0
OrgRepoItem 公开组织仓预览项。
type PathRuleDTO ¶ added in v0.12.0
type PathRuleDTO struct {
// From 源仓路径前缀。
From string `json:"from"`
// To 目标仓路径前缀;为空表示排除。
To string `json:"to"`
}
PathRuleDTO 是一条路径规则。
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 ¶
CreatePlatform 创建平台
func (*PlatformService) DeletePlatform ¶
func (s *PlatformService) DeletePlatform(ctx context.Context, key string) error
DeletePlatform 删除平台
func (*PlatformService) GetPlatform ¶
GetPlatform 获取平台
func (*PlatformService) GetPlatformByID ¶
GetPlatformByID 根据 ID 获取平台
func (*PlatformService) ListPlatformRepos ¶
func (s *PlatformService) ListPlatformRepos(ctx context.Context, key, page, perPage string) ([]*sdkprov.PlatformRepo, error)
ListPlatformRepos 列出平台上的仓库
func (*PlatformService) ListPlatforms ¶
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 ¶
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 ¶
UpdatePlatform 更新平台
func (*PlatformService) UpdatePlatformStatus ¶
func (s *PlatformService) UpdatePlatformStatus(ctx context.Context, key, status, testResult string) error
UpdatePlatformStatus 更新平台状态
type PreviewReport ¶ added in v0.12.0
type PreviewReport struct {
// ChannelID 通道 ID。
ChannelID uint `json:"channel_id"`
// ChannelName 通道名。
ChannelName string `json:"channel_name"`
// Summary 计划统计。
Summary history.Summary `json:"summary"`
// BaseHead 目标侧当前 HEAD(既有提交原样保留的基线)。
BaseHead string `json:"base_head"`
// NewHead 预演后的 HEAD(推送后会变成这样)。
NewHead string `json:"new_head"`
// Commits 将要产生的提交。
Commits []history.AppliedCommit `json:"commits"`
// AppliedFiles 将要应用的文件。
AppliedFiles []string `json:"applied_files"`
// SkippedFiles 不会带过去的文件(待人工裁决/排除)。
SkippedFiles []string `json:"skipped_files"`
// ProtectedCount 受保护文件数(不会动)。
ProtectedCount int `json:"protected_count"`
// PendingConflicts 待人工裁决的冲突。
PendingConflicts []history.ConflictDossier `json:"pending_conflicts,omitempty"`
// ScrubHits 痕迹命中。
ScrubHits []history.ScrubHit `json:"scrub_hits,omitempty"`
// Gate 门禁结果。
Gate GateReport `json:"gate"`
// Targets 各推送目标的影响面。
Targets []TargetImpact `json:"targets"`
// Credentials 各推送目标的凭据状态。
Credentials []CredentialStatus `json:"credentials,omitempty"`
// NeedsForce 是否需要强推。
NeedsForce bool `json:"needs_force"`
// Warnings 警告(不阻断,但要让人看见)。
Warnings []string `json:"warnings,omitempty"`
// PlanMarkdown 计划的 Markdown 视图(便于人读)。
PlanMarkdown string `json:"plan_markdown,omitempty"`
}
PreviewReport 是预检报告。
预检 = **把这次同步的全部影响面摊开**,但不推送: 计划统计、将产生的提交、将改动的文件、门禁结果(推出去能不能编译)、 每个推送目标的 ref 变化与是否需要强推、待人工裁决的冲突。
type PublicOrgImportRequest ¶ added in v0.9.0
type PublicOrgImportRequest struct {
PlatformKey string
Org string
CreateTasks bool
TargetPlatform string
TargetOrg string
Filter *RepoImportFilter
DryRun bool
Max int
}
PublicOrgImportRequest 公开组织仓导入请求(入参已由壳层校验/归一化)。
type PublicOrgImportResult ¶ added in v0.9.0
type PublicOrgImportResult struct {
Items []OrgRepoItem
Warnings []string
Imported int
CreatedTasks int
}
PublicOrgImportResult 导入结果。
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
func (f *RepoImportFilter) Allow(r *sdkprov.PlatformRepo) bool
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) GetRepoByKey ¶
func (rs *RepoService) GetRepoByKey(key string) (*model.Repo, error)
GetRepoByKey returns a repository by key.
func (*RepoService) GetRepoWithProvider ¶
GetRepoWithProvider 一次调用完成 repo 查找 + provider 解析, 消除调用方重复的 "GetRepoByKey → nil check → resolveRepoProvider" 样板。
func (*RepoService) ListBranches ¶
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 RestoreItem ¶ added in v0.9.0
type RestoreItem struct {
Kind string `json:"kind"`
Name string `json:"name"`
Action string `json:"action"` // created | updated | skipped | failed(dry-run 下 created/updated 表示"将会创建/将会覆盖")
Error string `json:"error,omitempty"`
// Note 补充说明这次到底改了什么(如"颜色 f00→0f0")。
// 覆盖是破坏性动作,不说清楚就没法审。
Note string `json:"note,omitempty"`
}
RestoreItem 回灌逐条明细。
type RestoreKindStat ¶ added in v0.9.0
type RestoreKindStat struct {
Planned int `json:"planned"`
Created int `json:"created"`
// Updated 是"覆盖更新"的条目数,**与 Created 分开记**。
//
// 原来 overwrite 走的是 UpdateLabel,却把计数记成 created ⇒
// 报告说"新建了 N 条",实际是"改写了 N 条已存在的东西" ——
// 报告与事实相反,比失败本身更危险(运维以为在补建,其实在覆盖)。
Updated int `json:"updated"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
}
RestoreKindStat 单类回灌统计(JSON 标签与壳 ops.RestoreKindStat 一致)。
type RestoreRequest ¶ added in v0.9.0
type RestoreRequest struct {
RepoKey string
SnapshotDir string
Kinds []string
DryRun bool
Overwrite bool
TargetPlatform string // 平台 key,空 = repo 关联平台
TargetOwner string // 空 = repo.PlatformOwner
TargetRepo string // 空 = repo.PlatformRepo
}
RestoreRequest 元数据回灌入参。Kinds 空时按快照内存在的分片推导 (labels|milestones|issues|prs|releases)。
type RestoreResult ¶ added in v0.9.0
type RestoreResult struct {
SnapshotDir string `json:"snapshot_dir"`
Target string `json:"target"`
Stats map[string]*RestoreKindStat `json:"stats"`
Warnings []string `json:"warnings"`
DryRun bool `json:"dry_run"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
Applied int `json:"applied"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
Details []RestoreItem `json:"details"`
}
RestoreResult 回灌结果。SnapshotDir/Target/Stats/Warnings/DryRun/StartedAt/ FinishedAt 与壳 ops.MetadataRestoreResult 同构(历史落盘走 restoreHistoryRecord, 文件格式不含扩展字段);Applied/Skipped/Failed 是 Stats 的聚合视图, Details 为逐条明细。
type RetryTracker ¶ added in v0.9.0
type RetryTracker struct {
// contains filtered or unexported fields
}
RetryTracker 自动重跑计数器(进程内;多实例部署时各实例只认自己触发的重跑, 与 runwatch 历史行为一致)。
func NewRetryTracker ¶ added in v0.9.0
func NewRetryTracker(maxKeep int) *RetryTracker
NewRetryTracker 创建计数器;maxKeep<=0 时用默认 1000。
func (*RetryTracker) ShouldRetry ¶ added in v0.9.0
func (t *RetryTracker) ShouldRetry(run *model.SyncRun, p AutoRetryPolicy) Decision
ShouldRetry 判定该失败运行是否应自动重跑,并在放行时记账。 只对 Status=failed 的运行放行;成功运行直接跳过。
type RunEvent ¶ added in v0.9.0
type RunEvent struct {
TaskKey string
// Run 完成态快照(CreateRun 失败时为 nil)。
Run *model.SyncRun
Trigger string
// Err Execute 返回的错误(结果本身以 Run.Status 为准)。
Err error
At time.Time
}
RunEvent 一次运行结束的事件。
type ScrubRuleDTO ¶ added in v0.12.0
type ScrubRuleDTO struct {
// Name 规则名。
Name string `json:"name"`
// Category 类别分组。
Category string `json:"category"`
// Pattern 正则源码。
Pattern string `json:"pattern"`
// Severity 处理强度:auto / mandatory,默认 auto。
Severity string `json:"severity"`
// Replacement 命中后的替换文本;auto 且为空表示删除。
Replacement string `json:"replacement"`
}
ScrubRuleDTO 是一条痕迹检测与清理规则。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) ApplyTemplate ¶ added in v0.9.0
func (s *Service) ApplyTemplate(ctx context.Context, templateID string, dryRun bool) (*TemplateApplyResult, error)
ApplyTemplate 批量套用策略模板:沿 Extends 链合并 Spec(子覆盖父), 只更新已存在任务的 cron/启用位;不隐式创建任务,避免误建。
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) AutoRetry ¶ added in v0.9.0
func (s *Service) AutoRetry() *RetryTracker
AutoRetry 返回失败自动补偿的策略计数器(NewService 建好)。
func (*Service) BackupGists ¶ added in v0.9.0
func (s *Service) BackupGists(ctx context.Context, prov sdkprov.Provider, destDir string, maxGists int) (count int, warnings []string, err error)
BackupGists 拉取 token 用户可见的 gists(分页到 maxGists 为止)并逐个写 JSON 文件。 返回成功落盘条数与逐条 warning;平台不声明 Gists 能力时报错。
func (*Service) BackupMetadata ¶ added in v0.9.0
func (s *Service) BackupMetadata(ctx context.Context, o MetadataBackupOptions) (*MetadataBackupResult, error)
BackupMetadata 抓取 issues/PR/labels/milestones/releases 元数据快照, 可选下载 source archive / GitHub Release 附件 / Gists。 provider 经 ProviderForPlatform 获取(Manager 缓存 + GitHub App token 感知)。 校验顺序与历史壳层一致:repo → platform → provider → backup_dir → 落盘。
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) BulkMirrorOrg ¶ added in v0.9.0
func (s *Service) BulkMirrorOrg(ctx context.Context, req BulkMirrorRequest) (*BulkMirrorResult, error)
BulkMirrorOrg 按策略把源组织仓库映射到目标命名空间,并可选建同步任务。 顺序:(可选)同步源平台仓库 → 过滤源组织 → 映射 → 建仓 → 建任务。
func (*Service) CleanupExpiredBackups ¶ added in v0.6.0
CleanupExpiredBackups 按 retention 天数清理过期冷备(legal_hold 时拒绝执行)。 返回删除数量。与 BackupKeep 轮转互补:keep 管数量,retention 管时效。
func (*Service) CleanupOldData ¶
func (*Service) CompleteRun ¶
CompleteRun updates a sync run with final status and details. Satisfies executor.RunManager.
func (*Service) CompleteRunWithTaskUpdate ¶
CompleteRunWithTaskUpdate 在同一事务中完成 run + task 更新. Satisfies executor.RunManager.
func (*Service) CountRepos ¶
CountRepos returns the total repo count via COUNT aggregate (no row loading).
func (*Service) CountReposByPlatform ¶
CountReposByPlatform 统计平台下的仓库数量
func (*Service) CountTasksByStatus ¶
CountTasksByStatus returns task counts grouped by last_status (key "total" = overall).
func (*Service) CreateHistoryChannel ¶ added in v0.12.0
func (s *Service) CreateHistoryChannel(ctx context.Context, in HistoryChannelInput) (*HistoryChannelDTO, error)
CreateHistoryChannel 新建历史同步通道。
func (*Service) CreateHistoryTarget ¶ added in v0.12.0
func (s *Service) CreateHistoryTarget(ctx context.Context, channelID uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
CreateHistoryTarget 新建推送目标。
func (*Service) CreatePlatform ¶
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 (*Service) DeleteHistory ¶
DeleteHistory deletes a sync run by ID.
func (*Service) DeleteHistoryChannel ¶ added in v0.12.0
DeleteHistoryChannel 删除历史同步通道。
func (*Service) DeleteHistoryOverride ¶ added in v0.12.0
DeleteHistoryOverride 删除一条裁决。
func (*Service) DeleteHistoryTarget ¶ added in v0.12.0
DeleteHistoryTarget 删除推送目标。
func (*Service) DeletePlatform ¶
DeletePlatform 删除平台
func (*Service) DeletePlatformWebhook ¶
DeletePlatformWebhook 删除平台侧的 Webhook。
func (*Service) DeleteRepo ¶
DeleteRepo deletes a repository by key.
func (*Service) DeleteRule ¶
DeleteRule deletes a webhook rule by ID.
func (*Service) DetectDrift ¶ added in v0.6.0
DetectDrift 检测**源端与目标端**的分支漂移。
用于发现「镜像声称同步成功但 refs 实际不一致」的静默故障。 taskKeys 为空时扫描全部启用任务。
**语义(重写)**:漂移 = 目标端与源端不一致。
原来比的是"工作区本地分支 vs 源端远端" ⇒ 报出来的多半是"源端前进了" —— 那是**正常状态**(下次同步就推上去了),不是漂移; 而真正该报的"目标端跑偏了(目标有源端没有的提交)"**从来没被检查过**。
另外三处一并修掉:
- **带凭证**:原来走 `git ls-remote`,而平台的 RunRaw 固定用空凭证 ⇒ 私有仓(本产品的主要场景)永远 "cannot resolve refs", 漂移检测形同虚设;现在用带凭证的 fetch 取两端状态。
- **专用工作目录**:不复用 executor 的 workdir —— 检测时的 fetch 会写 git 锁,和正在跑的同步抢同一份目录会互相报错。
- **不静默截断**:任务列表被上限截断时如实报"未检查"。
func (*Service) DownloadReleaseAssets ¶ added in v0.9.0
func (s *Service) DownloadReleaseAssets(ctx context.Context, prov sdkprov.Provider, owner, repo string, releases []*sdkprov.ReleaseInfo, destDir string, maxAssets int) (saved, warnings []string, err error)
DownloadReleaseAssets 下载 release 附件到 destDir(流式写盘)。 releases 非空时直接复用(带 Assets 元数据,不重复请求);否则现拉 ListReleases。 文件名 tag__name(均经路径清洗),上限 maxAssets,warning 文案逐附件。 平台不声明 ReleaseAssets 能力时报错。
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) ForcePushApprovals ¶ added in v0.9.0
func (s *Service) ForcePushApprovals() *ForcePushStore
ForcePushApprovals 返回 force-push 审批存储。
func (*Service) GetHistoryChannel ¶ added in v0.12.0
GetHistoryChannel 取历史同步通道详情。
func (*Service) GetHistoryRun ¶ added in v0.12.0
GetHistoryRun 取执行记录详情。
func (*Service) GetPlatform ¶
GetPlatform 获取平台
func (*Service) GetPlatformByID ¶
GetPlatformByID returns a platform by ID. Satisfies executor.PlatformProvider.
func (*Service) GetRepoByKey ¶
GetRepoByKey returns a repository by key. Satisfies executor.RepoProvider.
func (*Service) GetRepoDir ¶ added in v0.13.0
GetRepoDir 返回任务的 git 工作区路径(<tempDir>/<taskKey>/repo)。
GetTempDir 返回的是**父目录**,真正的 git 仓库在 repo 子目录里 —— 把父目录当仓库用会得到 "repository does not exist"。
func (*Service) GetTempDir ¶
func (*Service) HealthCheck ¶
HealthCheck checks the health of all dependencies. Returns a map of component name to "ok" or error message. 内部对每个组件设置 5s 超时:基础设施卡住时健康检查不会无限阻塞。
func (*Service) HealthSnapshot ¶ added in v0.9.0
func (s *Service) HealthSnapshot(ctx context.Context, limit int, driftByTask map[string]int) (*HealthSnapshot, error)
HealthSnapshot 按维度规则给任务打分(借鉴 OpenSSF Scorecards)。 维度:reliability(35) / freshness(20) / schedule(15) / safety(15) / completeness(15)
limit ≤0 → 50,>200 → 200;driftByTask 非空时折入 safety 维度 (with_drift 的网络开销由调用方决定是否触发 DetectDrift)。
func (*Service) History ¶ added in v0.12.0
func (s *Service) History() *HistoryService
History 返回历史同步服务。
func (*Service) HistoryApply ¶ added in v0.12.0
HistoryApply 按通道把计划落到目标树,产出执行记录(本地,不推送)。
func (*Service) HistoryPlan ¶ added in v0.12.0
HistoryPlan 按通道生成同步计划。
func (*Service) HistoryPreview ¶ added in v0.12.0
HistoryPreview 执行预检(不推送)。
func (*Service) HistoryPreviewMarkdown ¶ added in v0.12.0
HistoryPreviewMarkdown 把预检报告渲染成可读文档。
func (*Service) HistoryPush ¶ added in v0.12.0
HistoryPush 按通道推送最近一次执行记录的产物。
func (*Service) HistoryPushRun ¶ added in v0.12.0
HistoryPushRun 推送指定执行记录的产物。
func (*Service) HistoryPushWithOptions ¶ added in v0.13.0
func (s *Service) HistoryPushWithOptions(ctx context.Context, channelID uint, opts HistoryPushOptions) (*HistoryPushDTO, error)
HistoryPushWithOptions 按通道推送(可指定强制推送)。
func (*Service) HistoryResolve ¶ added in v0.12.0
HistoryResolve 按通道生成计划并计算 hold 的自动解法。
func (*Service) HistoryRollback ¶ added in v0.12.0
func (s *Service) HistoryRollback(ctx context.Context, runID uint, ref string) (*HistoryRollbackDTO, error)
HistoryRollback 把目标树回滚到指定 ref。
func (*Service) HistorySync ¶ added in v0.12.0
func (s *Service) HistorySync(ctx context.Context, opts HistorySyncOptions) (*HistorySyncReport, error)
HistorySync 一次跑完「预检 → 移植 → 推送」,有阻塞项则停下。
func (*Service) ImportPublicOrg ¶ added in v0.9.0
func (s *Service) ImportPublicOrg(ctx context.Context, req PublicOrgImportRequest) (*PublicOrgImportResult, error)
ImportPublicOrg 列出组织公开仓并可选建同步任务(默认只导入仓库记录)。
顺序与历史壳层一致:列仓(仅 GitHub)→ 导入仓库记录 → 批量建任务; DryRun 时跳过后两步(由壳层追加 dry_run 警告)。
func (*Service) ListBranches ¶
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) ListHistoryChannels ¶ added in v0.12.0
func (s *Service) ListHistoryChannels(ctx context.Context, offset, limit int) ([]*HistoryChannelDTO, int64, error)
ListHistoryChannels 列出历史同步通道。
func (*Service) ListHistoryOverrides ¶ added in v0.12.0
func (s *Service) ListHistoryOverrides(ctx context.Context, channelID uint) ([]*HistoryOverrideDTO, error)
ListHistoryOverrides 列出通道的裁决。
func (*Service) ListHistoryRuns ¶ added in v0.12.0
func (s *Service) ListHistoryRuns(ctx context.Context, channelID uint, offset, limit int) ([]*HistoryRunDTO, int64, error)
ListHistoryRuns 列出通道的执行记录。
func (*Service) ListHistoryTargets ¶ added in v0.12.0
func (s *Service) ListHistoryTargets(ctx context.Context, channelID uint) ([]*HistoryTargetDTO, error)
ListHistoryTargets 列出通道的推送目标。
func (*Service) ListMetadataBackups ¶ added in v0.9.0
func (s *Service) ListMetadataBackups(_ context.Context, repoKey string) ([]MetadataBackupInfo, error)
ListMetadataBackups 扫描 MetadataBackupDir 下的 manifest.json; 读取/解析失败的条目静默跳过(与历史行为一致)。repoKey 非空时按快照 repo_key 过滤。BackupDir 未配置时返回空列表。
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 ¶
ListPlatforms 列出所有平台
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) ListStarredRepos ¶ added in v0.9.0
func (s *Service) ListStarredRepos(ctx context.Context, platformKey string, max int) ([]*sdkprov.PlatformRepo, error)
ListStarredRepos 拉取平台 starred 仓库(能力门控 + 分页拉到 max 条)。
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) MetadataBackupDir ¶ added in v0.9.0
MetadataBackupDir 元数据快照根目录 = BackupDir()+"/metadata",目录布局唯一来源。
func (*Service) OperationStats ¶
OperationStats 返回今日、本周、总操作数。
func (*Service) OpsTodo ¶ added in v0.9.0
func (s *Service) OpsTodo(ctx context.Context) []OpsTodoItem
OpsTodo 聚合健康 attention + 孤儿仓库 + RPO 超标,按优先级输出可执行队列。 排序:优先级 → kind → id。
func (*Service) OpsTrends ¶ added in v0.9.0
OpsTrends 同步成功率/耗时时间序列。
取全局最近 trendsHistoryLimit 条 run 按日聚合(id DESC → 新日期在前, 顺序沿用历史实现)。days ≤0 或 >365 由调用方归一化为 30。
func (*Service) PreviewSync ¶
func (s *Service) PreviewSync(ctx context.Context, req *model.PreviewSyncRequest) (*model.PreviewSyncResult, error)
PreviewSync previews a sync operation.
func (*Service) PreviewTemplate ¶ added in v0.9.0
func (s *Service) PreviewTemplate(ctx context.Context, templateID string) (*tpl.Template, []TemplateMatch, error)
PreviewTemplate 套用前预览命中结果(Renovate dry-run 语义)。
func (*Service) ProviderForPlatform ¶ added in v0.8.0
func (s *Service) ProviderForPlatform(p *model.Platform, tokenOverride string) (sdkprov.Provider, error)
ProviderForPlatform 按平台取 provider,供壳层复用: tokenOverride 非空优先,否则 ResolvePlatformToken(GitHub App 感知)。
func (*Service) PushTaskBackup ¶ added in v0.8.0
func (s *Service) PushTaskBackup(ctx context.Context, task *model.SyncTask, workDir, remoteURL, refspec string, force bool) (string, error)
PushTaskBackup 把任务 mirror 工作区(workDir)推到任意备份远端(github/gitlab 任意 git remote)。与 executor/backup_remote.go 同套路:临时 remote + backend.Push, 推送带仓库凭证——裸 exec git push 无凭证,https 私有仓必败。
- refspec 原样传入(壳层默认 "+refs/heads/*:refs/heads/*");空值补默认。
- force 决定 PushOptions.Force(--force)。
- 凭证按 task.SourceRepoKey 查仓库走 executor.BuildRepoAuth(repo token 优先、 平台 token 回退);取不到仓库时退 AuthNone(匿名)。
返回成功的 git 输出摘要(推上的 ref 列表,可为空串);失败时错误自带 stderr (gitbackend GitError)。临时 remote 推送后清理。
func (*Service) RPOReport ¶ added in v0.6.0
RPOReport 按冷备目录聚合每个任务的备份新鲜度(RPO)与估算恢复时间(RTO)。 rpoMaxSeconds>0 时标记超标任务。
func (*Service) ReceiveWebhook ¶
func (*Service) RecordOperation ¶
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) RepoInventory ¶ added in v0.9.0
func (s *Service) RepoInventory(ctx context.Context) (*InventoryResult, error)
RepoInventory 消灭孤儿仓库:哪些仓库没同步任务、哪些一直失败、哪些很久没跑。
func (*Service) ResolvePlatformToken ¶ added in v0.6.0
ResolvePlatformToken Service 包装,便于壳层/业务调用。
func (*Service) RestoreBundle ¶ added in v0.5.1
RestoreBundle 从 bundle 恢复到 destDir。 支持 .bundle 与 .bundle.enc(需配置 backup_encrypt_key)。
func (*Service) RestoreMetadata ¶ added in v0.9.0
func (s *Service) RestoreMetadata(ctx context.Context, req RestoreRequest) (*RestoreResult, error)
RestoreMetadata 回灌快照到目标仓。校验顺序与历史壳层一致: backup_dir → 最新快照解析 → manifest 加载 → repo → 目标平台 → provider。 错误文案是对外契约:快照类经 ErrMetadataValidation 归 400, repo/平台缺失归 404,provider 类回落 500。
func (*Service) RotateHistoryTargetCredential ¶ added in v0.12.0
func (s *Service) RotateHistoryTargetCredential(ctx context.Context, id uint, in HistoryCredentialInput) (*HistoryTargetDTO, error)
RotateHistoryTargetCredential 轮换一个推送目标的凭据(只换密钥)。
func (*Service) RunDRDrill ¶ added in v0.6.0
RunDRDrill 对指定 bundle 做灾备演练,并写入哈希链历史。
func (*Service) RunTaskAsync ¶
RunTaskAsync 异步触发一次同步:校验与并发快速失败在调用方 goroutine 内完成, 实际执行纳入 WaitGroup + bgCtx(优雅关停时被等待/取消),适合 HTTP 手动触发路径, 避免 handler 被分钟级同步任务挂住。返回 nil 仅代表"已受理",结果见执行历史。
func (*Service) RunTaskWithTrigger ¶
func (*Service) SampleMetadataVerify ¶ added in v0.9.0
func (s *Service) SampleMetadataVerify(_ context.Context, repoKey string, n int) (VerifyReport, error)
SampleMetadataVerify 抽样比对元数据快照:清单存在、分片可解析、数量一致。 最多检查 n 个快照(n ≤ 0 → 5);repoKey 非空时按快照目录布局过滤 (metadata/<sanitized repoKey>/ 下的才算)。BackupDir 未配置时返回 Reason="backup_dir not configured"(壳层据此回 {ok,reason})。
func (*Service) SetDefaultPlatform ¶
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) SetHistoryOverride ¶ added in v0.12.0
func (s *Service) SetHistoryOverride(ctx context.Context, channelID uint, in HistoryOverrideInput) (*HistoryOverrideDTO, error)
SetHistoryOverride 写入(或覆盖)一条裁决。
func (*Service) SetTemplates ¶ added in v0.9.0
func (s *Service) SetTemplates(st TemplateStore)
SetTemplates 覆盖模板库(测试隔离 / 注入文件实现)。
func (*Service) SubscribeRuns ¶ added in v0.9.0
SubscribeRuns 注册运行完成回调,返回取消函数(幂等)。 回调在独立 goroutine 中执行并 recover panic;调用方需自行保证非阻塞语义 (要串行处理就自己起 worker)。Stop/进程退出不等待订阅者。
func (*Service) SyncPlatformRepos ¶
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) Templates ¶ added in v0.9.0
func (s *Service) Templates() TemplateStore
Templates 返回同步策略模板库(生产为表存储;cfg.Templates.Path 仅作旧 json 迁移源)。
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) UpdateHistoryChannel ¶ added in v0.12.0
func (s *Service) UpdateHistoryChannel(ctx context.Context, id uint, in HistoryChannelInput) (*HistoryChannelDTO, error)
UpdateHistoryChannel 更新历史同步通道。
func (*Service) UpdateHistoryTarget ¶ added in v0.12.0
func (s *Service) UpdateHistoryTarget(ctx context.Context, id uint, in HistoryTargetInput) (*HistoryTargetDTO, error)
UpdateHistoryTarget 更新推送目标。
func (*Service) UpdatePlatform ¶
UpdatePlatform 更新平台
func (*Service) UpdatePlatformStatus ¶
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 (*Service) UpdateTaskLastRun ¶
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
VerifyBundle 校验 bundle 完整性。 自动识别 .enc 加密冷备:先解密到临时目录再校验。
func (*Service) VerifyDrillChain ¶ added in v0.6.0
VerifyDrillChain 校验演练历史哈希链。
func (*Service) VerifyHistoryChannelChain ¶ added in v0.12.0
func (s *Service) VerifyHistoryChannelChain(ctx context.Context, channelID uint) (*HistoryChainResult, error)
VerifyHistoryChannelChain 校验通道内执行记录的哈希链。
type TargetImpact ¶ added in v0.12.0
type TargetImpact struct {
// Name 目标名。
Name string `json:"name"`
// RepoURL 目标地址。
RepoURL string `json:"repo_url"`
// RemoteHead 远端当前的 HEAD(空 = 空仓库)。
RemoteHead string `json:"remote_head"`
// BaseHead 本地基线 HEAD(移植前的目标树 HEAD)。
BaseHead string `json:"base_head"`
// NewHead 推送后远端将变成的 HEAD。
NewHead string `json:"new_head"`
// FastForward 推送是快进(不需要强推)。
FastForward bool `json:"fast_forward"`
// Diverged 远端与本地基线已分叉(需要强推,且要人工确认)。
Diverged bool `json:"diverged"`
// Unknown 远端不可达或状态未知。
Unknown bool `json:"unknown"`
// Note 说明。
Note string `json:"note"`
}
TargetImpact 是一个推送目标的影响面。
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 ¶
CleanupOldRunSteps removes sync run steps older than the specified duration.
func (*TaskService) CleanupOldRuns ¶
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 ¶
CompleteRunWithTaskUpdate 在同一事务中完成 run 更新 + task 状态更新,保证原子性。
task 状态**只更新 last_run_at / last_status 两列**:整行 Save 会把 执行开始时的旧快照写回,抹掉执行期间的并发修改(实测:一次 cron 执行 把刚改的 force_push_policy=allow 还原成 block)。
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) 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 ¶
func (ts *TaskService) PreviewSync(ctx context.Context, req *model.PreviewSyncRequest) (*model.PreviewSyncResult, error)
PreviewSync previews a sync operation.
func (*TaskService) RecentRuns ¶ added in v0.9.0
func (ts *TaskService) RecentRuns(offset, limit int) ([]*model.SyncRun, error)
RecentRuns 取全局最近的 run(不分任务),供趋势类聚合使用。
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 ¶
UpdateTaskLastRun updates the task's last run time and status.
只写这两列(不是整行 Save):执行期间的并发修改(策略/cron/开关)不能被 执行开始时的旧快照悄悄改回去。
type TemplateApplyResult ¶ added in v0.9.0
type TemplateApplyResult struct {
Template *tpl.Template
Effective tpl.Spec
ExtendsChain []string
Changed []TemplateChange
DryRun bool
}
TemplateApplyResult 批量套用结果。
type TemplateChange ¶ added in v0.9.0
type TemplateChange struct {
Key string `json:"key"`
Name string `json:"name"`
Before map[string]any `json:"before"`
After map[string]any `json:"after"`
}
TemplateChange 批量套用产生的单条变更(Before/After 为变更前后字段快照)。
type TemplateMatch ¶ added in v0.9.0
TemplateMatch 命中的任务摘要。
type TemplateStore ¶ added in v0.9.1
type TemplateStore interface {
List() []tpl.Template
ListByTag(tag string) []tpl.Template
Get(id string) (*tpl.Template, error)
Upsert(t *tpl.Template) (*tpl.Template, error)
Delete(id string) error
Resolve(id string) (tpl.Spec, []string, error)
}
TemplateStore 模板库访问接口。 生产用 DB 实现(dbTemplateStore);测试/过渡可注入文件实现(*tpl.Store), 两者共用 tpl 的类型与继承链解析(tpl.ResolveSelf)。
type TrendPoint ¶ added in v0.9.0
type TrendPoint struct {
Date string `json:"date"`
Total int `json:"total"`
Success int `json:"success"`
Failed int `json:"failed"`
AvgMs float64 `json:"avg_duration_ms"`
}
TrendPoint 单日同步成功率/耗时聚合(供前端小图)。 JSON 标签与壳层历史响应逐字一致。
type VerifyReport ¶ added in v0.9.0
type VerifyReport struct {
Checked int `json:"checked"`
OK bool `json:"ok"`
Warnings []string `json:"warnings"`
Reason string `json:"reason,omitempty"`
}
VerifyReport 元数据快照抽样校验报告。 Reason 非空表示 backup_dir 未配置:此时响应结构仅 {ok,reason}(与历史行为一致)。
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 ¶
func (ws *WebhookService) CreateRule(ctx context.Context, req *model.CreateRuleRequest) (*model.WebhookRule, error)
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 ¶
func (ws *WebhookService) UpdateRule(ctx context.Context, req *model.UpdateRuleRequest) (*model.WebhookRule, error)
UpdateRule updates an existing webhook rule.
Source Files
¶
- backup_push.go
- backup_service.go
- bootstrap.go
- cleanup.go
- concurrency.go
- constants.go
- cron.go
- dr_service.go
- errors.go
- events.go
- forcepush_store.go
- githubapp.go
- health_service.go
- history_channel_service.go
- history_preview.go
- history_service.go
- lifecycle_bg.go
- lifecycle_service.go
- metabackup.go
- metadata_restore.go
- metadata_service.go
- mirror_service.go
- mirror_versions.go
- operation_log_service.go
- ops_query.go
- options.go
- orgbulk_service.go
- orgmap.go
- platform_repo_plan.go
- platform_service.go
- provider_helper.go
- repo.go
- repo_service.go
- retry_policy.go
- service.go
- task.go
- task_service.go
- template_service.go
- template_store.go
- webhook.go
- webhook_register.go
- webhook_service.go