diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/repository/generate.go | 2 | ||||
-rw-r--r-- | services/repository/repository.go | 29 |
2 files changed, 20 insertions, 11 deletions
diff --git a/services/repository/generate.go b/services/repository/generate.go index 95e5cdc6c2..067f8f61d0 100644 --- a/services/repository/generate.go +++ b/services/repository/generate.go @@ -64,7 +64,7 @@ func GenerateRepository(doer, owner *models.User, templateRepo *models.Repositor return nil }); err != nil { - if generateRepo != nil { + if generateRepo != nil && generateRepo.ID > 0 { if errDelete := models.DeleteRepository(doer, owner.ID, generateRepo.ID); errDelete != nil { log.Error("Rollback deleteRepository: %v", errDelete) } diff --git a/services/repository/repository.go b/services/repository/repository.go index 77c8728d94..c6768f3f00 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -18,11 +18,7 @@ import ( func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (*models.Repository, error) { repo, err := repo_module.CreateRepository(doer, owner, opts) if err != nil { - if repo != nil { - if errDelete := models.DeleteRepository(doer, owner.ID, repo.ID); errDelete != nil { - log.Error("Rollback deleteRepository: %v", errDelete) - } - } + // No need to rollback here we should do this in CreateRepository... return nil, err } @@ -31,15 +27,28 @@ func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) ( return repo, nil } +// AdoptRepository adopts pre-existing repository files for the user/organization. +func AdoptRepository(doer, owner *models.User, opts models.CreateRepoOptions) (*models.Repository, error) { + repo, err := repo_module.AdoptRepository(doer, owner, opts) + if err != nil { + // No need to rollback here we should do this in AdoptRepository... + return nil, err + } + + notification.NotifyCreateRepository(doer, owner, repo) + + return repo, nil +} + +// DeleteUnadoptedRepository adopts pre-existing repository files for the user/organization. +func DeleteUnadoptedRepository(doer, owner *models.User, name string) error { + return repo_module.DeleteUnadoptedRepository(doer, owner, name) +} + // ForkRepository forks a repository func ForkRepository(doer, u *models.User, oldRepo *models.Repository, name, desc string) (*models.Repository, error) { repo, err := repo_module.ForkRepository(doer, u, oldRepo, name, desc) if err != nil { - if repo != nil { - if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil { - log.Error("Rollback deleteRepository: %v", errDelete) - } - } return nil, err } |