loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Adopt repository event and handler (#25497)

Fix #14304

---------

Co-authored-by: delvh <dev.lh@web.de>

authored by

Lunny Xiao
delvh
and committed by
GitHub
d44a415b 48e5a74f

+29 -11
+1
modules/notification/base/notifier.go
··· 17 17 // Notifier defines an interface to notify receiver 18 18 type Notifier interface { 19 19 Run() 20 + NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) 20 21 NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) 21 22 NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) 22 23 NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository)
+4
modules/notification/base/null.go
··· 145 145 func (*NullNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { 146 146 } 147 147 148 + // NotifyAdoptRepository places a place holder function 149 + func (*NullNotifier) NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { 150 + } 151 + 148 152 // NotifyDeleteRepository places a place holder function 149 153 func (*NullNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) { 150 154 }
+4
modules/notification/indexer/indexer.go
··· 29 29 return &indexerNotifier{} 30 30 } 31 31 32 + func (r *indexerNotifier) NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { 33 + r.NotifyMigrateRepository(ctx, doer, u, repo) 34 + } 35 + 32 36 func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, 33 37 issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, 34 38 ) {
+7
modules/notification/notification.go
··· 274 274 } 275 275 } 276 276 277 + // NotifyAdoptRepository notifies the adoption of a repository to notifiers 278 + func NotifyAdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { 279 + for _, notifier := range notifiers { 280 + notifier.NotifyAdoptRepository(ctx, doer, u, repo) 281 + } 282 + } 283 + 277 284 // NotifyMigrateRepository notifies create repository to notifiers 278 285 func NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) { 279 286 for _, notifier := range notifiers {
+13 -11
services/repository/adopt.go
··· 70 70 if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false); err != nil { 71 71 return err 72 72 } 73 - if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil { 73 + 74 + // Re-fetch the repository from database before updating it (else it would 75 + // override changes that were done earlier with sql) 76 + if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil { 77 + return fmt.Errorf("getRepositoryByID: %w", err) 78 + } 79 + 80 + if err := adoptRepository(ctx, repoPath, doer, repo, opts.DefaultBranch); err != nil { 74 81 return fmt.Errorf("createDelegateHooks: %w", err) 75 82 } 83 + 76 84 if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil { 77 85 return fmt.Errorf("checkDaemonExportOK: %w", err) 78 86 } ··· 95 103 return nil, err 96 104 } 97 105 98 - notification.NotifyCreateRepository(ctx, doer, u, repo) 106 + notification.NotifyAdoptRepository(ctx, doer, u, repo) 99 107 100 108 return repo, nil 101 109 } 102 110 103 - func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts repo_module.CreateRepoOptions) (err error) { 111 + func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, defaultBranch string) (err error) { 104 112 isExist, err := util.IsExist(repoPath) 105 113 if err != nil { 106 114 log.Error("Unable to check if %s exists. Error: %v", repoPath, err) ··· 114 122 return fmt.Errorf("createDelegateHooks: %w", err) 115 123 } 116 124 117 - // Re-fetch the repository from database before updating it (else it would 118 - // override changes that were done earlier with sql) 119 - if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil { 120 - return fmt.Errorf("getRepositoryByID: %w", err) 121 - } 122 - 123 125 repo.IsEmpty = false 124 126 125 127 // Don't bother looking this repo in the context it won't be there ··· 129 131 } 130 132 defer gitRepo.Close() 131 133 132 - if len(opts.DefaultBranch) > 0 { 133 - repo.DefaultBranch = opts.DefaultBranch 134 + if len(defaultBranch) > 0 { 135 + repo.DefaultBranch = defaultBranch 134 136 135 137 if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { 136 138 return fmt.Errorf("setDefaultBranch: %w", err)