service

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

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

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

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

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

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

Functions

This section is empty.

Types

type Config

type Config = model.Config

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,由调用方决定如何处理错误)。

func (*OperationLogService) Stats

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

Stats 返回今日、近 7 天(本周)、总操作数。

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) CreatePlatform

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

CreatePlatform 创建平台

func (*PlatformService) DeletePlatform

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

DeletePlatform 删除平台

func (*PlatformService) GetPlatform

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

GetPlatform 获取平台

func (*PlatformService) GetPlatformByID

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

GetPlatformByID 根据 ID 获取平台

func (*PlatformService) ListPlatformRepos

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

ListPlatformRepos 列出平台上的仓库

func (*PlatformService) ListPlatforms

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

ListPlatforms 列出所有平台

func (*PlatformService) ListReposByPlatform

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

ListReposByPlatform 列出平台下的仓库

func (*PlatformService) SetDefaultPlatform

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

SetDefaultPlatform 设置默认平台

func (*PlatformService) SyncPlatformRepos

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

SyncPlatformRepos 同步平台仓库到本地

func (*PlatformService) TestPlatformConnection

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

TestPlatformConnection 测试平台连接

func (*PlatformService) UpdatePlatform

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

UpdatePlatform 更新平台

func (*PlatformService) UpdatePlatformStatus

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

UpdatePlatformStatus 更新平台状态

type 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 added in v1.5.5

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

CountRepos returns the total repo count via COUNT aggregate.

func (*RepoService) CreateRepo

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

CreateRepo creates a new repository.

func (*RepoService) DeleteRepo

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

DeleteRepo deletes a repository by key.

func (*RepoService) GetRepo

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

GetRepo returns a repository by key.

func (*RepoService) GetRepoByKey

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

GetRepoByKey returns a repository by key.

func (*RepoService) ListBranches

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

ListBranches returns a list of branches for a repository.

func (*RepoService) ListRepos

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

ListRepos returns a paginated list of repositories.

func (*RepoService) ListReposWithFilter

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

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

func (*RepoService) SetWebhookSecret added in v1.6.0

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

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

func (*RepoService) TestConnection

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

TestConnection tests the connection to a repository.

func (*RepoService) UpdateRepo

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

UpdateRepo updates an existing repository.

type Service

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

func NewService

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

func (*Service) CleanupOldData

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

func (*Service) CompleteRun

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

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

func (*Service) CountRepos added in v1.5.5

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

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

func (*Service) CountTasksByStatus added in v1.5.5

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

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

func (*Service) CreatePlatform

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

CreatePlatform 创建平台

func (*Service) CreateRepo

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

CreateRepo creates a new repository.

func (*Service) CreateRule

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

CreateRule creates a new webhook rule.

func (*Service) CreateRun

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

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

func (*Service) CreateRunStep

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

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

func (*Service) CreateTask

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

func (*Service) DeleteHistory

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

DeleteHistory deletes a sync run by ID.

func (*Service) DeletePlatform

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

DeletePlatform 删除平台

func (*Service) DeletePlatformWebhook added in v1.6.0

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

DeletePlatformWebhook 删除平台侧的 Webhook。

func (*Service) DeleteRepo

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

DeleteRepo deletes a repository by key.

func (*Service) DeleteRule

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

DeleteRule deletes a webhook rule by ID.

func (*Service) DeleteTask

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

func (*Service) GetAPIKey

func (s *Service) GetAPIKey() string

func (*Service) GetConfig

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

func (*Service) GetPlatform

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

GetPlatform 获取平台

func (*Service) GetPlatformByID

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

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

func (*Service) GetRepo

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

GetRepo returns a repository by key.

func (*Service) GetRepoByKey

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

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

func (*Service) GetRule

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

GetRule returns a webhook rule by ID.

func (*Service) GetTask

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

GetTask returns a sync task by key.

func (*Service) GetTempDir

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

func (*Service) HealthCheck

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

HealthCheck checks the health of all dependencies. Returns a map of component name to "ok" or error message.

func (*Service) ListBranches

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

ListBranches returns a list of branches for a repository.

func (*Service) ListEvents

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

ListEvents returns webhook events for a repository.

func (*Service) ListHistory

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

ListHistory returns a paginated list of sync run history.

func (*Service) ListOperations

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

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

func (*Service) ListPlatformRepos

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

ListPlatformRepos 列出平台上的仓库

func (*Service) ListPlatformWebhooks added in v1.6.0

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

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

func (*Service) ListPlatforms

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

ListPlatforms 列出所有平台

func (*Service) ListRepos

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

ListRepos returns a paginated list of repositories.

func (*Service) ListReposByPlatform

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

ListReposByPlatform 列出平台下的仓库

func (*Service) ListReposWithFilter

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

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

func (*Service) ListRules

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

ListRules returns webhook rules for a repository.

func (*Service) ListTasks

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

ListTasks returns a paginated list of sync tasks.

func (*Service) OperationStats

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

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

func (*Service) PreviewSync

PreviewSync previews a sync operation.

func (*Service) ReceiveWebhook

func (s *Service) ReceiveWebhook(ctx context.Context, repoKey string, req *http.Request) error

func (*Service) RecordOperation

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

RecordOperation 记录一条审计日志。

func (*Service) RegisterPlatformWebhook added in v1.6.0

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) RetryEvent

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

func (*Service) RunTask

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

func (*Service) RunTaskWithTrigger

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

func (*Service) SetDefaultPlatform

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

SetDefaultPlatform 设置默认平台

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop()

func (*Service) SyncPlatformRepos

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

SyncPlatformRepos 同步平台仓库到本地

func (*Service) TestConnection

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

TestConnection tests the connection to a repository.

func (*Service) TestPlatformConnection

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

TestPlatformConnection 测试平台连接

func (*Service) UpdatePlatform

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

UpdatePlatform 更新平台

func (*Service) UpdatePlatformStatus

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

UpdatePlatformStatus 更新平台状态

func (*Service) UpdateRepo

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

UpdateRepo updates an existing repository.

func (*Service) UpdateRule

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

UpdateRule updates an existing webhook rule.

func (*Service) UpdateRunStep

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

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

func (*Service) UpdateTask

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

func (*Service) UpdateTaskLastRun

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

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

type TaskService

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

TaskService handles sync task-related operations.

func NewTaskService

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

NewTaskService creates a new TaskService instance.

func (*TaskService) CleanupOldRunSteps

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

CleanupOldRunSteps removes sync run steps older than the specified duration.

func (*TaskService) CleanupOldRuns

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

CleanupOldRuns removes sync runs older than the specified duration.

func (*TaskService) CompleteRun

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

CompleteRun updates a sync run with final status and details.

func (*TaskService) CountTasksByStatus added in v1.5.5

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

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

func (*TaskService) CreateRun

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

CreateRun creates a new sync run record for a task.

func (*TaskService) CreateRunStep

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

CreateRunStep creates a new sync run step record.

func (*TaskService) CreateTask

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

CreateTask creates a new sync task.

func (*TaskService) DeleteHistory

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

DeleteHistory deletes a sync run by ID.

func (*TaskService) DeleteTask

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

DeleteTask deletes a sync task by key.

func (*TaskService) FindAllEnabledTasks

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

FindAllEnabledTasks returns all enabled sync tasks.

func (*TaskService) FindTaskByKey

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

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

func (*TaskService) GetTask

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

GetTask returns a sync task by key.

func (*TaskService) ListHistory

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

ListHistory returns a paginated list of sync run history.

func (*TaskService) ListTasks

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

ListTasks returns a paginated list of sync tasks.

func (*TaskService) PreviewSync

PreviewSync previews a sync operation.

func (*TaskService) UpdateRunStep

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

UpdateRunStep updates an existing sync run step record.

func (*TaskService) UpdateTask

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

UpdateTask updates an existing sync task.

func (*TaskService) UpdateTaskLastRun

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

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

type 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(maxAge time.Duration) (int64, error)

CleanupOldEvents removes webhook events older than the specified duration.

func (*WebhookService) CreateRule

CreateRule creates a new webhook rule.

func (*WebhookService) CreateWebhookEvent

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

CreateWebhookEvent creates a new webhook event.

func (*WebhookService) DeleteRule

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

DeleteRule deletes a webhook rule by ID.

func (*WebhookService) FindEventByEventID

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

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

func (*WebhookService) FindEventByID

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

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

func (*WebhookService) GetRule

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

GetRule returns a webhook rule by ID.

func (*WebhookService) ListEvents

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

ListEvents returns webhook events for a repository.

func (*WebhookService) ListRules

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

ListRules returns webhook rules for a repository.

func (*WebhookService) MarkEventProcessed added in v1.5.5

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

MarkEventProcessed 标记事件为 processed(处理完成后调用)。

func (*WebhookService) MarkEventProcessing added in v1.5.5

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

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

func (*WebhookService) UpdateRule

UpdateRule updates an existing webhook rule.

Jump to

Keyboard shortcuts

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