// Copyright 2025 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package sourcegraph import ( "context" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" notify_service "code.gitea.io/gitea/services/notify" ) type sourcegraphNotifier struct { notify_service.NullNotifier } var _ notify_service.Notifier = &sourcegraphNotifier{} // NewNotifier creates a new Sourcegraph notifier func NewNotifier() notify_service.Notifier { return &sourcegraphNotifier{} } func (n *sourcegraphNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if !setting.Sourcegraph.Enabled || !setting.Sourcegraph.SyncOnPush { return } client := GetClient() if client == nil { return } // Trigger Sourcegraph to re-sync the repository if err := client.SyncRepository(ctx, repo.FullName()); err != nil { log.Warn("Sourcegraph sync failed for %s: %v", repo.FullName(), err) } } func (n *sourcegraphNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { // Also sync on mirror push n.PushCommits(ctx, pusher, repo, opts, commits) }