diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-09-08 12:51:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 04:51:15 +0000 |
commit | 4f32abaf941ba30ade1f96930a05d14f1c6a6782 (patch) | |
tree | 9351b7d654b20db032867041b0292924ec93bb3f /services/repository/create.go | |
parent | 3c0c27965836328abd2668dcd77710ee2460535e (diff) | |
download | gitea-4f32abaf941ba30ade1f96930a05d14f1c6a6782.tar.gz gitea-4f32abaf941ba30ade1f96930a05d14f1c6a6782.zip |
move repository deletion to service layer (#26948)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'services/repository/create.go')
-rw-r--r-- | services/repository/create.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/services/repository/create.go b/services/repository/create.go index a5d521e353..09956b74d4 100644 --- a/services/repository/create.go +++ b/services/repository/create.go @@ -12,7 +12,6 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" @@ -199,7 +198,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re } // CreateRepositoryDirectly creates a repository for the user/organization. -func CreateRepositoryDirectly(doer, u *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error) { +func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opts CreateRepoOptions) (*repo_model.Repository, error) { if !doer.IsAdmin && !u.CanCreateRepo() { return nil, repo_model.ErrReachLimitOfRepo{ Limit: u.MaxRepoCreation, @@ -239,7 +238,7 @@ func CreateRepositoryDirectly(doer, u *user_model.User, opts CreateRepoOptions) var rollbackRepo *repo_model.Repository - if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { + if err := db.WithTx(ctx, func(ctx context.Context) error { if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, false, false); err != nil { return err } @@ -303,7 +302,7 @@ func CreateRepositoryDirectly(doer, u *user_model.User, opts CreateRepoOptions) return nil }); err != nil { if rollbackRepo != nil { - if errDelete := models.DeleteRepository(doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil { + if errDelete := DeleteRepositoryDirectly(ctx, doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil { log.Error("Rollback deleteRepository: %v", errDelete) } } |