mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
171 lines
6.3 KiB
Go
171 lines
6.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package indexer
|
|
|
|
import (
|
|
"context"
|
|
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
code_indexer "github.com/hanzoai/git/modules/indexer/code"
|
|
issue_indexer "github.com/hanzoai/git/modules/indexer/issues"
|
|
stats_indexer "github.com/hanzoai/git/modules/indexer/stats"
|
|
"github.com/hanzoai/git/modules/log"
|
|
"github.com/hanzoai/git/modules/repository"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
notify_service "github.com/hanzoai/git/services/notify"
|
|
)
|
|
|
|
type indexerNotifier struct {
|
|
notify_service.NullNotifier
|
|
}
|
|
|
|
var _ notify_service.Notifier = &indexerNotifier{}
|
|
|
|
// NewNotifier create a new indexerNotifier notifier
|
|
func NewNotifier() notify_service.Notifier {
|
|
return &indexerNotifier{}
|
|
}
|
|
|
|
func (r *indexerNotifier) AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
|
r.MigrateRepository(ctx, doer, u, repo)
|
|
}
|
|
|
|
func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
|
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
|
) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
issue_indexer.UpdateIssueIndexer(ctx, pr.Issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
|
if err := c.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
issue_indexer.UpdateIssueIndexer(ctx, c.Issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
|
if err := comment.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
issue_indexer.UpdateIssueIndexer(ctx, comment.Issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
|
issue_indexer.DeleteRepoIssueIndexer(ctx, repo.ID)
|
|
if setting.Indexer.RepoIndexerEnabled {
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
}
|
|
}
|
|
|
|
func (r *indexerNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
|
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
|
|
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
}
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
}
|
|
}
|
|
|
|
func (r *indexerNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
|
if !opts.RefFullName.IsBranch() {
|
|
return
|
|
}
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
}
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
}
|
|
}
|
|
|
|
func (r *indexerNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
|
if !opts.RefFullName.IsBranch() {
|
|
return
|
|
}
|
|
|
|
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
}
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
}
|
|
}
|
|
|
|
func (r *indexerNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
|
|
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
|
code_indexer.UpdateRepoIndexer(repo)
|
|
}
|
|
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
|
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
|
}
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
|
addedLabels, removedLabels []*issues_model.Label,
|
|
) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
|
issue_indexer.UpdateIssueIndexer(ctx, issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
issue_indexer.UpdateIssueIndexer(ctx, pr.Issue.ID)
|
|
}
|
|
|
|
func (r *indexerNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
log.Error("LoadIssue: %v", err)
|
|
return
|
|
}
|
|
issue_indexer.UpdateIssueIndexer(ctx, pr.Issue.ID)
|
|
}
|