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

model

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusRunning = "running"
	StatusSuccess = "success"
	StatusFailed  = "failed"
)

Run status constants

View Source
const (
	StatusReceived   = "received"
	StatusProcessing = "processing"
	StatusProcessed  = "processed"
)

Webhook event status constants

View Source
const (
	TriggerManual  = "manual"
	TriggerCron    = "cron"
	TriggerWebhook = "webhook"
)

Trigger source constants

View Source
const (
	DriverMySQL  = "mysql"
	DriverSQLite = "sqlite"
)

Database driver constants

View Source
const (
	DefaultHost          = "0.0.0.0"
	DefaultPort          = 8890
	DefaultMaxIdleConns  = 10
	DefaultMaxOpenConns  = 100
	DefaultMaxConcurrent = 5
	DefaultTimeout       = 300
	DefaultRetryCount    = 3
	DefaultTempDir       = "/tmp/git-sync"

	DefaultConnMaxLifeSec    = 300 // 5 分钟
	DefaultConnMaxIdleSec    = 120 // 2 分钟
	DefaultWebhookRateLimit  = 10
	DefaultMaxBodySize       = 10 << 20 // 10MB
	DefaultRedisDialTimeout  = 5
	DefaultRedisReadTimeout  = 3
	DefaultRedisWriteTimeout = 3

	// 上限值
	MaxConcurrent       = 100
	MaxDBOpenConns      = 200
	MaxWebhookBodySize  = 100 << 20 // 100MB
	MaxWebhookRateLimit = 10000

	// Push retry 退避因子
	RetryBackoffMs = 500
)

Default configuration values

View Source
const (
	StepClone        = "clone"
	StepFetch        = "fetch"
	StepCheckout     = "checkout"
	StepEnsureRemote = "ensure_remote"
	StepPush         = "push"
	StepLFS          = "lfs"
	StepWiki         = "wiki"
	StepDivergeCheck = "diverge_check"
)

Step name constants

View Source
const (
	ErrorAuth      = "auth"
	ErrorDivergent = "divergent"
	ErrorConflict  = "conflict"
	ErrorNetwork   = "network"
	ErrorConfig    = "config"
	ErrorGit       = "git"
	ErrorUnknown   = "unknown"
)

Error type constants

View Source
const (
	TableRepos            = "repos"
	TableSyncTasks        = "sync_tasks"
	TableSyncRuns         = "sync_runs"
	TableSyncRunSteps     = "sync_run_steps"
	TableWebhookRules     = "webhook_rules"
	TableWebhookRuleTasks = "webhook_rule_tasks"
	TableWebhookEvents    = "webhook_events"
	TableOperationLogs    = "operation_logs"
)

Table name constants

View Source
const (
	DefaultBranch    = "main"
	DefaultPlatform  = "unknown"
	DefaultSyncMode  = "single"
	DefaultEventType = "push"
	DefaultAction    = "sync"
)

Model default value constants

View Source
const (
	MirrorModePublish = "publish" // 开源公开发布:身份改写 + 门禁 + 快照推送
	MirrorModeBackup  = "backup"  // 仓库备份:原样 ref 推送(P1)
)

镜像通道模式

View Source
const (
	MirrorRunPending   = "pending"
	MirrorRunRunning   = "running"
	MirrorRunSuccess   = "success"
	MirrorRunFailed    = "failed"
	MirrorRunDivergent = "divergent" // 远端同名 tag 内容不一致,默认拒绝覆盖
)

镜像执行状态

View Source
const (
	MirrorKindPublish = "publish"
	MirrorKindVerify  = "verify"
)

镜像执行类别

View Source
const (
	MirrorCredNone   = "none"
	MirrorCredToken  = "token"
	MirrorCredSSHKey = "ssh_key"
)

凭据类型

View Source
const (
	PlatformTypeGitHub      = string(provider.PlatformGitHub)      // "github"
	PlatformTypeGitLab      = string(provider.PlatformGitLab)      // "gitlab"
	PlatformTypeGitea       = string(provider.PlatformGitea)       // "gitea"
	PlatformTypeGitee       = string(provider.PlatformGitee)       // "gitee"
	PlatformTypeGitCode     = string(provider.PlatformGitCode)     // "gitcode"
	PlatformTypeTencentCode = string(provider.PlatformTencentCode) // "tencent_code"
	// SDK 未注册的扩展类型
	PlatformTypeAtomGit = "atomgit"
	PlatformTypeCustom  = "custom"
)

平台类型常量:SDK 已注册平台直接复用 provider.Platform 常量(字符串值相同); SDK 未注册的扩展类型保留本地定义。

View Source
const (
	PlatformStatusActive = "active"
	PlatformStatusError  = "error"
)

PlatformStatus 平台状态常量

View Source
const (
	ActionSync = "sync"
)

Webhook rule action constants

View Source
const (
	RepoStatusActive = "active"
)

Repository status constants

Variables

View Source
var PlatformAPIPaths = map[string]string{
	PlatformTypeGitHub:      "/api/v3",
	PlatformTypeGitLab:      "/api/v4",
	PlatformTypeGitea:       "/api/v1",
	PlatformTypeGitee:       "/api/v5",
	PlatformTypeGitCode:     "/api/v5",
	PlatformTypeAtomGit:     "/api/v1",
	PlatformTypeTencentCode: "/api/v3",
}

PlatformAPIPaths 各平台的 API 路径(壳层 GetAPIURL 用)。 SDK 已注册平台的值作为已知默认;扩展平台是唯一数据源。

View Source
var PlatformDefaultInstances = map[string]string{
	PlatformTypeGitHub:      "github.com",
	PlatformTypeGitLab:      "gitlab.com",
	PlatformTypeGitea:       "gitea.com",
	PlatformTypeGitee:       "gitee.com",
	PlatformTypeGitCode:     "gitcode.com",
	PlatformTypeAtomGit:     "atomgit.com",
	PlatformTypeTencentCode: "git.code.tencent.com",
}

PlatformDefaultInstances 各平台的默认实例地址。

Functions

func ComputeEntryHash added in v0.6.0

func ComputeEntryHash(prev string, e *OperationLog) string

ComputeEntryHash 计算审计条目哈希(prev 可为空)。

func GetAPIURL

func GetAPIURL(platformType, instanceURL string) string

GetAPIURL 根据实例地址生成 API URL。 自建实例(非默认域名)的 URL 由壳层传入 instanceURL 覆盖; SDK 的 provider.NewProvider 也能推导已知平台的 URL,但 DB 字段 NOT NULL 要求壳层在创建时就提供非空值,因此保留此辅助函数。

func InitDB

func InitDB(driver, dsn string) (*gorm.DB, error)

func NormalizeAuditHashInput added in v0.6.0

func NormalizeAuditHashInput(s string) string

NormalizeAuditHashInput 归一化字符串用于稳定哈希(去首尾空白)。

func ValidPlatformType

func ValidPlatformType(t string) bool

ValidPlatformType 检查平台类型是否合法:SDK 已注册平台 + 扩展白名单。 替代旧的 ValidPlatformTypes 静态 map,与 SDK 注册表自动同步。

Types

type BackupDestinationConfig added in v0.6.0

type BackupDestinationConfig struct {
	Type string `yaml:"type" json:"type"` // s3 | webdav | azure | local
	Name string `yaml:"name" json:"name"`
	// S3/OSS/MinIO
	Endpoint  string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
	Region    string `yaml:"region,omitempty" json:"region,omitempty"`
	Bucket    string `yaml:"bucket,omitempty" json:"bucket,omitempty"`
	Prefix    string `yaml:"prefix,omitempty" json:"prefix,omitempty"`
	AccessKey string `yaml:"access_key,omitempty" json:"access_key,omitempty"`
	SecretKey string `yaml:"secret_key,omitempty" json:"secret_key,omitempty"`
	PathStyle bool   `yaml:"path_style,omitempty" json:"path_style,omitempty"`
	// WebDAV / local dir(用 url 字段)
	URL      string `yaml:"url,omitempty" json:"url,omitempty"`
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Password string `yaml:"password,omitempty" json:"password,omitempty"`
	// Azure Blob
	AccountName string `yaml:"account_name,omitempty" json:"account_name,omitempty"`
	AccountKey  string `yaml:"account_key,omitempty" json:"account_key,omitempty"`
	Container   string `yaml:"container,omitempty" json:"container,omitempty"`
	Enabled     *bool  `yaml:"enabled,omitempty" json:"enabled,omitempty"`
}

BackupDestinationConfig 冷备多目的地之一(s3/webdav/azure/local)。

type Config

type Config struct {
	Server   ServerConfig   `yaml:"server"`
	Database DatabaseConfig `yaml:"database"`
	Redis    RedisConfig    `yaml:"redis"`
	Git      GitConfig      `yaml:"git"`
	Sync     SyncConfig     `yaml:"sync"`
	Webhook  WebhookConfig  `yaml:"webhook"`
	Log      LogConfig      `yaml:"log"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig 从指定路径加载配置文件。 path 参数由调用方控制(通常是启动参数或环境变量),不存在用户注入风险。 环境变量会覆盖 YAML 文件中的同名配置(env 优先级更高)。

func (*Config) Validate

func (c *Config) Validate() error

Validate 校验配置并填充默认值。 注意:环境变量覆盖发生在 Validate 之前,因此此处的默认值逻辑仅在 YAML 和环境变量均未提供对应字段时才生效。

type CreateRepoRequest

type CreateRepoRequest struct {
	Name        string `json:"name"`
	RemoteURL   string `json:"remoteUrl"`
	AccessToken string `json:"accessToken"`
	PlatformID  uint   `json:"platformId"`
}

type CreateRuleRequest

type CreateRuleRequest struct {
	Name          string   `json:"name"`
	RepoKey       string   `json:"repoKey"`
	EventType     string   `json:"eventType"`
	BranchPattern string   `json:"branchPattern"`
	Action        string   `json:"action"`
	TaskKeys      []string `json:"taskKeys"`
	MinInterval   int      `json:"minInterval"`
	Enabled       bool     `json:"enabled"`
	Description   string   `json:"description"`
}

type CreateTaskRequest

type CreateTaskRequest struct {
	Name          string `json:"name"`
	SourceRepoKey string `json:"source_repo_key"`
	SourceBranch  string `json:"source_branch"`
	TargetRepoKey string `json:"target_repo_key"`
	TargetBranch  string `json:"target_branch"`
	SyncMode      string `json:"sync_mode"`
	Cron          string `json:"cron"`
	GitTags       bool   `json:"git_tags"`
	GitForce      bool   `json:"git_force"`
	GitPrune      bool   `json:"git_prune"`
	GitLFS        bool   `json:"git_lfs"`
	SyncWiki      bool   `json:"sync_wiki"`
	GitBundle     bool   `json:"git_bundle"`
	Submodules    bool   `json:"submodules"`
	GitPushPrune  bool   `json:"git_push_prune"`
	// KeepDivergent nil/缺省=true(安全);显式 false 才允许覆盖分歧
	KeepDivergent *bool `json:"keep_divergent"`
	// ForcePushPolicy allow|block|backup_on_demand;空=按 KeepDivergent 映射
	ForcePushPolicy string `json:"force_push_policy"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Driver         string `yaml:"driver" env:"GIT_SYNC_DB_DRIVER"`
	DSN            string `yaml:"dsn" env:"GIT_SYNC_DB_DSN"`
	MaxIdleConns   int    `yaml:"max_idle_conns" env:"GIT_SYNC_DB_MAX_IDLE_CONNS"`
	MaxOpenConns   int    `yaml:"max_open_conns" env:"GIT_SYNC_DB_MAX_OPEN_CONNS"`
	ConnMaxLifeSec int    `yaml:"conn_max_life_sec" env:"GIT_SYNC_DB_CONN_MAX_LIFE_SEC"` // 连接最大存活秒数,0 用默认 5 分钟
	ConnMaxIdleSec int    `yaml:"conn_max_idle_sec" env:"GIT_SYNC_DB_CONN_MAX_IDLE_SEC"` // 空闲连接最大存活秒数,0 用默认 2 分钟
}

type GitConfig

type GitConfig struct {
	Backend string `yaml:"backend" env:"GIT_SYNC_GIT_BACKEND"`
	TempDir string `yaml:"temp_dir" env:"GIT_SYNC_GIT_TEMP_DIR"`
}

type LogConfig

type LogConfig struct {
	Level  string `yaml:"level" env:"GIT_SYNC_LOG_LEVEL"`
	Format string `yaml:"format" env:"GIT_SYNC_LOG_FORMAT"`
}

type MirrorChannel

type MirrorChannel struct {
	ID      uint   `gorm:"primaryKey" json:"id"`
	Name    string `gorm:"size:128;not null" json:"name"`
	Mode    string `gorm:"size:16;not null;default:publish" json:"mode"`
	RepoKey string `gorm:"size:128;not null;index" json:"repoKey"`
	// Module 是源 module 身份(publish 模式,创建时从 go.mod 读出)。
	Module string `gorm:"size:255" json:"module"`

	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
	// Targets 响应投影(GetMirrorChannel 组装)。
	Targets []*MirrorTarget `gorm:"-" json:"targets,omitempty"`
}

MirrorChannel 镜像通道:源仓库 → N 个远端目标的配置。

type MirrorRun

type MirrorRun struct {
	ID        uint   `gorm:"primaryKey" json:"id"`
	ChannelID uint   `gorm:"index:idx_mirror_channel;not null" json:"channelId"`
	TargetID  uint   `gorm:"index" json:"targetId"`
	Kind      string `gorm:"size:16;not null;default:publish" json:"kind"`
	// Tags 逗号分隔的本批 tag。
	Tags string `gorm:"size:1024" json:"tags"`
	// Status 整批状态:pending|running|success|failed|divergent。
	Status string `json:"status"`
	// TagStatuses 行级结果 JSON:{tag: {status, detail, commit, tree}}。
	TagStatuses string `gorm:"type:text" json:"tagStatuses"`
	// Steps 步骤时间线 JSON。
	Steps string `gorm:"type:text" json:"steps"`
	// Report 最后一次 core 报告 JSON(参考 mirror.TagReport)。
	Report string `gorm:"type:text" json:"report"`
	Error  string `gorm:"type:text" json:"error"`

	AllowOverwrite bool       `json:"allowOverwrite"`
	StartedAt      *time.Time `json:"startedAt"`
	FinishedAt     *time.Time `json:"finishedAt"`
	DurationMs     int64      `json:"durationMs"`

	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

MirrorRun 执行记录:一次发布/备份/验证动作。

type MirrorStep

type MirrorStep struct {
	Name   string `json:"name"`
	Status string `json:"status"` // running|success|failed|skipped
	Detail string `json:"detail,omitempty"`
}

MirrorStep 执行步骤(JSON 存储)。

type MirrorTarget

type MirrorTarget struct {
	ID        uint `gorm:"primaryKey" json:"id"`
	ChannelID uint `gorm:"index;not null" json:"channelId"`
	// Remote 是目标仓库在本地克隆里配置的远端名(如 github)。
	Remote string `gorm:"size:64;not null" json:"remote"`
	// RepoURL 是目标仓库的 git 地址(https/ssh)。
	RepoURL string `gorm:"size:512;not null" json:"repoUrl"`
	// TargetModule 是目标 module 身份(publish 模式)。
	TargetModule string `gorm:"size:255" json:"targetModule"`

	// 凭据:Credential 整体加密存储,响应只回 HasCredential。
	CredType      string `gorm:"size:16;not null;default:none" json:"credType"`
	Credential    string `gorm:"size:2048" json:"-"`
	Username      string `gorm:"size:128" json:"username"`
	HasCredential bool   `gorm:"-" json:"hasCredential"`

	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

MirrorTarget 通道目标:publish 模式为身份映射,backup 模式为备份远端。

type OperationLog

type OperationLog struct {
	ID           uint   `json:"id" gorm:"primaryKey"`
	Action       string `json:"action" gorm:"size:32;not null;index"`  // create/update/delete/run/retry/sync
	ResourceType string `json:"resource_type" gorm:"size:32;not null"` // repo/task/rule/platform/event
	ResourceKey  string `json:"resource_key" gorm:"size:255;index"`    // 资源标识(key/name/id)
	Resource     string `json:"resource" gorm:"size:500"`              // 中文摘要,如 "创建仓库 repo-main"
	Actor        string `json:"actor" gorm:"size:128;index"`           // 操作者
	IP           string `json:"ip" gorm:"size:64"`
	Status       string `json:"status" gorm:"size:16;default:success"` // success/failed
	Detail       string `json:"detail" gorm:"type:text"`
	// PrevHash 上一条审计的 EntryHash(首条为空)
	PrevHash string `json:"prev_hash" gorm:"size:64;index"`
	// EntryHash 本条哈希链值
	EntryHash string    `json:"entry_hash" gorm:"size:64;index"`
	CreatedAt time.Time `json:"created_at" gorm:"index"`
}

OperationLog 记录用户对系统发起的写操作(审计日志)。 哈希链:EntryHash = SHA256(PrevHash || payload);篡改任意条目可被 VerifyAuditChain 检出。

func (OperationLog) TableName

func (OperationLog) TableName() string

type Platform

type Platform struct {
	ID          uint   `json:"id" gorm:"primaryKey"`
	Key         string `json:"key" gorm:"uniqueIndex;size:255;not null"`
	Name        string `json:"name" gorm:"size:100;not null"`
	Type        string `json:"type" gorm:"size:50;not null"`     // github, gitlab, gitea, gitee, gitcode, atomgit, tencent_code, custom
	InstanceURL string `json:"instance_url" gorm:"size:255"`     // 实例地址,如 github.com, gitlab.company.com
	APIURL      string `json:"api_url" gorm:"size:255;not null"` // API 地址,如 https://api.github.com
	AccessToken string `json:"-" gorm:"type:text"`               // 访问令牌(加密存储)
	// GitHub App 认证(优先于 PAT):安装级、可轮换、细粒度(借鉴 gickup/ghorg)
	GitHubAppID          int64  `json:"github_app_id" gorm:"default:0"`
	GitHubInstallationID int64  `json:"github_installation_id" gorm:"default:0"`
	GitHubPrivateKey     string `json:"-" gorm:"type:text"`                   // PEM 私钥(加密存储)
	SkipTLSVerify        bool   `json:"skip_tls_verify" gorm:"default:false"` // 跳过 TLS 证书验证
	CACertPath           string `json:"ca_cert_path" gorm:"size:500"`         // 自定义 CA 证书路径
	ProxyURL             string `json:"proxy_url" gorm:"size:255"`            // HTTP 代理地址
	// SSHHostKeyFingerprint SSH 主机公钥指纹钉扎("SHA256:xxx");设置后优先于 known_hosts
	SSHHostKeyFingerprint string `json:"ssh_host_key_fingerprint" gorm:"size:128"`
	// SSHKnownHostsPath 平台级 known_hosts 路径(空=用 ~/.ssh/known_hosts)
	SSHKnownHostsPath string         `json:"ssh_known_hosts_path" gorm:"size:500"`
	IsDefault         bool           `json:"is_default" gorm:"default:false"`      // 是否为默认平台
	Status            string         `json:"status" gorm:"size:20;default:active"` // 状态: active, error
	LastTestAt        *time.Time     `json:"last_test_at"`                         // 最后测试时间
	LastTestResult    string         `json:"last_test_result" gorm:"size:500"`     // 最后测试结果
	RepoCount         int            `json:"repo_count" gorm:"default:0"`          // 关联的仓库数量
	CreatedAt         time.Time      `json:"created_at"`
	UpdatedAt         time.Time      `json:"updated_at"`
	DeletedAt         gorm.DeletedAt `json:"-" gorm:"index"`
}

Platform 存储 Git 平台配置

func (Platform) TableName

func (Platform) TableName() string

type PreviewSyncRequest

type PreviewSyncRequest struct {
	SourceRepoKey string `json:"sourceRepoKey"`
	SourceBranch  string `json:"sourceBranch"`
	TargetRepoKey string `json:"targetRepoKey"`
	TargetBranch  string `json:"targetBranch"`
}

type PreviewSyncResult

type PreviewSyncResult struct {
	CanSync      bool   `json:"canSync"`
	SourceExists bool   `json:"sourceExists"`
	TargetExists bool   `json:"targetExists"`
	Message      string `json:"message"`
}

type RedisConfig

type RedisConfig struct {
	Addr            string `yaml:"addr" env:"GIT_SYNC_REDIS_ADDR"`
	Password        string `yaml:"password" env:"GIT_SYNC_REDIS_PASSWORD"`
	DB              int    `yaml:"db" env:"GIT_SYNC_REDIS_DB"`
	PoolSize        int    `yaml:"pool_size" env:"GIT_SYNC_REDIS_POOL_SIZE"`                 // 连接池大小,0 用 go-redis 默认(10*GOMAXPROCS)
	MinIdleConns    int    `yaml:"min_idle_conns" env:"GIT_SYNC_REDIS_MIN_IDLE_CONNS"`       // 最小空闲连接数,0 不预热
	DialTimeoutSec  int    `yaml:"dial_timeout_sec" env:"GIT_SYNC_REDIS_DIAL_TIMEOUT_SEC"`   // 建连超时秒数,0 不设超时
	ReadTimeoutSec  int    `yaml:"read_timeout_sec" env:"GIT_SYNC_REDIS_READ_TIMEOUT_SEC"`   // 读超时秒数,0 不设超时
	WriteTimeoutSec int    `yaml:"write_timeout_sec" env:"GIT_SYNC_REDIS_WRITE_TIMEOUT_SEC"` // 写超时秒数,0 不设超时
}

type Repo

type Repo struct {
	ID            uint           `json:"id" gorm:"primaryKey"`
	Key           string         `json:"key" gorm:"uniqueIndex;size:255;not null"`
	Name          string         `json:"name" gorm:"size:255;not null"`
	PlatformID    uint           `json:"platform_id" gorm:"index"` // 关联平台 ID
	Platform      string         `json:"platform" gorm:"size:50;not null;default:'unknown'"`
	PlatformOwner string         `json:"platform_owner" gorm:"size:200;not null;default:''"`
	PlatformRepo  string         `json:"platform_repo" gorm:"size:200;not null;default:''"`
	CloneURL      string         `json:"clone_url" gorm:"size:500"`
	SSHURL        string         `json:"ssh_url" gorm:"size:500"`
	DefaultBranch string         `json:"default_branch" gorm:"size:100;default:main"`
	AccessToken   string         `json:"-" gorm:"type:text"` // 保留用于兼容,优先使用 Platform 的 Token
	WebhookSecret string         `json:"-" gorm:"size:255"`
	WebhookID     int64          `json:"webhook_id"`
	Status        string         `json:"status" gorm:"size:20;default:active"`
	CreatedAt     time.Time      `json:"created_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	DeletedAt     gorm.DeletedAt `json:"-" gorm:"index"`
}

func (Repo) TableName

func (Repo) TableName() string

type ServerConfig

type ServerConfig struct {
	Host string `yaml:"host" env:"GIT_SYNC_SERVER_HOST"`
	Port int    `yaml:"port" env:"GIT_SYNC_SERVER_PORT"`
	Mode string `yaml:"mode" env:"GIT_SYNC_SERVER_MODE"`
}

ServerConfig 壳层 HTTP 监听相关配置。 用户登录 / API Key / SSO 等鉴权不属于本库;由 git-sync-service / git-sync-intranet 自行持有。 core 库本身不监听端口、不做用户鉴权。

type SyncConfig

type SyncConfig struct {
	// BackupDir git bundle 冷备输出目录(空=禁用)
	BackupDir string `yaml:"backup_dir" env:"GIT_SYNC_BACKUP_DIR"`
	// BackupKeep 每任务保留最近 N 份 bundle(0=不轮转,全部保留)
	BackupKeep int `yaml:"backup_keep" env:"GIT_SYNC_BACKUP_KEEP"`
	// BackupS3 bundle 异地冷备(S3 兼容);空配置=只存本地
	BackupS3 struct {
		Endpoint  string `yaml:"endpoint"`
		Region    string `yaml:"region"`
		Bucket    string `yaml:"bucket"`
		Prefix    string `yaml:"prefix"`
		AccessKey string `yaml:"access_key"`
		SecretKey string `yaml:"secret_key"`
		PathStyle bool   `yaml:"path_style"`
	} `yaml:"backup_s3"`
	// BackupDestinations 多目的地扇出(s3/webdav/azure/local),与 BackupS3 并存;
	// 两者都配置时全部尝试,逐目的地独立成功/失败。
	BackupDestinations []BackupDestinationConfig `yaml:"backup_destinations"`
	// BackupEncryptKey 冷备加密密钥(base64 32 字节 AES-256-GCM);空=不加密。
	// 加密文件后缀 .bundle.enc,恢复时需同一密钥。
	BackupEncryptKey string `yaml:"backup_encrypt_key" env:"GIT_SYNC_BACKUP_ENCRYPT_KEY"`
	// BackupRetentionDays 冷备保留天数(0=不按天清理);与 BackupKeep 取更严者。
	BackupRetentionDays int `yaml:"backup_retention_days" env:"GIT_SYNC_BACKUP_RETENTION_DAYS"`
	// LegalHold 冻结清理(合规保留),true 时禁止自动轮转/过期删除。
	LegalHold bool `yaml:"legal_hold" env:"GIT_SYNC_LEGAL_HOLD"`
	// AutoDiscoverIntervalMinutes 平台自动发现周期(分钟);0=关闭。
	AutoDiscoverIntervalMinutes int `yaml:"auto_discover_interval_minutes" env:"GIT_SYNC_AUTO_DISCOVER_INTERVAL"`
	// AutoDiscoverImport 发现到新仓库时是否自动导入(否则仅报告)。
	AutoDiscoverImport bool `yaml:"auto_discover_import" env:"GIT_SYNC_AUTO_DISCOVER_IMPORT"`
	// PartialClone 部分克隆 filter(blob:none / tree:0),空=全量
	PartialClone   string `yaml:"partial_clone" env:"GIT_SYNC_PARTIAL_CLONE"`
	MaxConcurrent  int    `yaml:"max_concurrent" env:"GIT_SYNC_MAX_CONCURRENT"`
	DefaultTimeout int    `yaml:"default_timeout" env:"GIT_SYNC_DEFAULT_TIMEOUT"`
	RetryCount     int    `yaml:"retry_count" env:"GIT_SYNC_RETRY_COUNT"`
}

type SyncRun

type SyncRun struct {
	ID             uint          `json:"id" gorm:"primaryKey"`
	TaskKey        string        `json:"taskKey" gorm:"size:36;not null;index:idx_sync_runs_task_key_created,priority:1"`
	TriggerSource  string        `json:"triggerSource" gorm:"size:20;not null"`
	Status         string        `json:"status" gorm:"size:20;not null;index"`
	StartTime      time.Time     `json:"startTime"`
	EndTime        *time.Time    `json:"endTime"`
	CommitRange    string        `json:"commitRange" gorm:"size:255"`
	Details        string        `json:"details" gorm:"type:text"`
	ErrorMessage   string        `json:"errorMessage" gorm:"type:text"`
	WebhookEventID *uint         `json:"webhookEventId" gorm:"index"`
	DurationMs     int64         `json:"durationMs"`
	ErrorType      string        `json:"errorType" gorm:"size:30"`
	RetryTotal     int           `json:"retryTotal"`
	Steps          []SyncRunStep `json:"steps" gorm:"foreignKey:RunID"`
	CreatedAt      time.Time     `json:"createdAt" gorm:"index:idx_sync_runs_created_at;index:idx_sync_runs_task_key_created,priority:2"`
}

func (SyncRun) TableName

func (SyncRun) TableName() string

type SyncRunStep

type SyncRunStep struct {
	ID         uint       `json:"id" gorm:"primaryKey"`
	RunID      uint       `json:"runId" gorm:"not null;index"`
	StepName   string     `json:"stepName" gorm:"size:50;not null"`
	Status     string     `json:"status" gorm:"size:20;not null"`
	StartTime  time.Time  `json:"startTime"`
	EndTime    *time.Time `json:"endTime"`
	DurationMs int64      `json:"durationMs"`
	ErrorMsg   string     `json:"errorMsg" gorm:"type:text"`
	ErrorType  string     `json:"errorType" gorm:"size:30"`
	Output     string     `json:"output" gorm:"type:text"`
	RetryCount int        `json:"retryCount"`
	CreatedAt  time.Time  `json:"createdAt" gorm:"index"`
}

SyncRunStep records a single step within a sync run.

func (SyncRunStep) TableName

func (SyncRunStep) TableName() string

type SyncTask

type SyncTask struct {
	ID            uint   `json:"id" gorm:"primaryKey"`
	Key           string `json:"key" gorm:"uniqueIndex;size:36;not null;default:''"`
	Name          string `json:"name" gorm:"size:100;not null;default:''"`
	SourceRepoKey string `json:"source_repo_key" gorm:"size:255;not null;index;default:''"`
	SourceBranch  string `json:"source_branch" gorm:"size:255;not null;default:''"`
	TargetRepoKey string `json:"target_repo_key" gorm:"size:255;not null;index;default:''"`
	TargetBranch  string `json:"target_branch" gorm:"size:255;not null;default:''"`
	SyncMode      string `json:"sync_mode" gorm:"size:20;default:single"`
	Cron          string `json:"cron" gorm:"size:100"`
	WebhookToken  string `json:"webhook_token" gorm:"uniqueIndex;size:36"`
	Enabled       bool   `json:"enabled" gorm:"default:true;index"`
	GitTags       bool   `json:"git_tags" gorm:"default:false"`
	GitForce      bool   `json:"git_force" gorm:"default:false"`
	GitPrune      bool   `json:"git_prune" gorm:"default:false"`
	// GitLFS 同步 Git LFS 对象(需要环境安装 git-lfs)
	GitLFS bool `json:"git_lfs" gorm:"default:false"`
	// SyncWiki 同步 wiki 仓库(源/目标 URL 按 .wiki.git 规则推导)
	SyncWiki bool `json:"sync_wiki" gorm:"default:false"`
	// GitBundle 同步成功后生成 git bundle 冷备(需配置 Sync.BackupDir)
	GitBundle bool `json:"git_bundle" gorm:"default:false"`
	// Submodules 递归同步 git 子模块
	Submodules bool `json:"submodules" gorm:"default:false"`
	// GitPushPrune 推送后删除目标上源已不存在的同名分支(refspec prune)
	GitPushPrune bool `json:"git_push_prune" gorm:"default:false"`
	// KeepDivergent true=目标分支有源没有的提交时拒绝 force 覆盖(防丢代码);
	// false=允许强制覆盖分歧分支。默认 true(安全)。
	KeepDivergent bool `json:"keep_divergent" gorm:"default:true"`
	// ForcePushPolicy 强制推送保护策略:allow | block | backup_on_demand。
	// 空值按 KeepDivergent 兼容映射(keep_divergent=true → block)。
	ForcePushPolicy string         `json:"force_push_policy" gorm:"size:32"`
	LastRunAt       *time.Time     `json:"last_run_at"`
	LastStatus      string         `json:"last_status" gorm:"size:20"`
	CreatedAt       time.Time      `json:"created_at"`
	UpdatedAt       time.Time      `json:"updated_at"`
	DeletedAt       gorm.DeletedAt `json:"-" gorm:"index"`
}

func (SyncTask) TableName

func (SyncTask) TableName() string

type TagStatus

type TagStatus struct {
	Tag    string `json:"tag"`
	Status string `json:"status"` // success|failed|divergent
	Detail string `json:"detail,omitempty"`
	Commit string `json:"commit,omitempty"`
	Tree   string `json:"tree,omitempty"`
}

TagStatus 行级发布结果(MirrorRun.TagStatuses 的元素)。

type TestConnectionResult

type TestConnectionResult struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

type UpdateRepoRequest

type UpdateRepoRequest struct {
	Key         string `json:"key"`
	Name        string `json:"name"`
	AccessToken string `json:"accessToken"`
}

type UpdateRuleRequest

type UpdateRuleRequest struct {
	ID            uint     `json:"id"`
	Name          string   `json:"name"`
	EventType     string   `json:"eventType"`
	BranchPattern string   `json:"branchPattern"`
	Action        string   `json:"action"`
	TaskKeys      []string `json:"taskKeys"`
	MinInterval   int      `json:"minInterval"`
	Enabled       bool     `json:"enabled"`
	Description   string   `json:"description"`
}

type UpdateTaskRequest

type UpdateTaskRequest struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// SourceBranch/TargetBranch/SyncMode/Cron:空字符串=不修改
	SourceBranch string `json:"source_branch"`
	TargetBranch string `json:"target_branch"`
	SyncMode     string `json:"sync_mode"`
	Cron         string `json:"cron"`
	// bool 字段用指针:nil=不修改,false=显式关闭。
	// 替代旧 bool 零值语义——此前客户端只改 name 也会把任务静默禁用。
	Enabled       *bool `json:"enabled"`
	GitTags       *bool `json:"git_tags"`
	GitForce      *bool `json:"git_force"`
	GitPrune      *bool `json:"git_prune"`
	GitLFS        *bool `json:"git_lfs"`
	SyncWiki      *bool `json:"sync_wiki"`
	GitBundle     *bool `json:"git_bundle"`
	Submodules    *bool `json:"submodules"`
	GitPushPrune  *bool `json:"git_push_prune"`
	KeepDivergent *bool `json:"keep_divergent"`
	// ForcePushPolicy 空=不修改
	ForcePushPolicy string `json:"force_push_policy"`
}

type WebhookConfig

type WebhookConfig struct {
	RateLimit   int `yaml:"rate_limit" env:"GIT_SYNC_WEBHOOK_RATE_LIMIT"`
	MaxBodySize int `yaml:"max_body_size" env:"GIT_SYNC_WEBHOOK_MAX_BODY_SIZE"`
}

type WebhookEvent

type WebhookEvent struct {
	ID           uint       `json:"id" gorm:"primaryKey"`
	EventID      string     `json:"eventId" gorm:"uniqueIndex;size:100;not null"`
	RepoKey      string     `json:"repoKey" gorm:"size:255;index:idx_webhook_events_repo_key_created,priority:1"`
	EventType    string     `json:"eventType" gorm:"size:50;not null"`
	Source       string     `json:"source" gorm:"size:20;not null"`
	ActorName    string     `json:"actorName" gorm:"size:200"`
	Branch       string     `json:"branch" gorm:"size:255"`
	CommitSHA    string     `json:"commitSha" gorm:"size:40"`
	Payload      []byte     `json:"payload" gorm:"type:json"`
	Status       string     `json:"status" gorm:"size:20;default:received;index"`
	ErrorMessage string     `json:"errorMessage" gorm:"type:text"`
	ProcessedAt  *time.Time `json:"processedAt"`
	CreatedAt    time.Time  `json:"createdAt" gorm:"index:idx_webhook_events_created_at;index:idx_webhook_events_repo_key_created,priority:2"`
}

func (WebhookEvent) TableName

func (WebhookEvent) TableName() string

type WebhookRule

type WebhookRule struct {
	ID            uint              `json:"id" gorm:"primaryKey"`
	Name          string            `json:"name" gorm:"size:100;not null"`
	RepoKey       string            `json:"repoKey" gorm:"size:255;not null;index"`
	EventType     string            `json:"eventType" gorm:"size:100;default:push"`
	BranchPattern string            `json:"branchPattern" gorm:"size:255"`
	Action        string            `json:"action" gorm:"size:50;default:sync"`
	MinInterval   int               `json:"minInterval" gorm:"default:60"`
	Enabled       bool              `json:"enabled" gorm:"default:true;index"`
	Description   string            `json:"description" gorm:"type:text"`
	Tasks         []WebhookRuleTask `json:"tasks,omitempty" gorm:"foreignKey:RuleID"`
	CreatedAt     time.Time         `json:"createdAt"`
	UpdatedAt     time.Time         `json:"updatedAt"`
	DeletedAt     gorm.DeletedAt    `json:"-" gorm:"index"`
}

func (*WebhookRule) GetTaskKeys

func (r *WebhookRule) GetTaskKeys() []string

GetTaskKeys returns the task keys from the Tasks relationship

func (*WebhookRule) SetTaskKeys

func (r *WebhookRule) SetTaskKeys(keys []string)

SetTaskKeys updates the Tasks relationship

func (WebhookRule) TableName

func (WebhookRule) TableName() string

type WebhookRuleTask

type WebhookRuleTask struct {
	ID        uint      `json:"id" gorm:"primaryKey"`
	RuleID    uint      `json:"ruleId" gorm:"not null;index;uniqueIndex:idx_rule_task"`
	TaskKey   string    `json:"taskKey" gorm:"size:36;not null;uniqueIndex:idx_rule_task"`
	CreatedAt time.Time `json:"createdAt"`
}

func (WebhookRuleTask) TableName

func (WebhookRuleTask) TableName() string

Jump to

Keyboard shortcuts

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