1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-28 13:49:13 -05:00
forgejo/services/repository/transfer.go
Lunny Xiao 21ae9838e0
Move transfer repository and rename repository on a service package and start action notification (#8573)
* move transfer repository and rename repository on a service package and start action notification

* remove unused codes

* fix lint

* fix bugs

* fix test

* fix test

* fix test

* fix lint

* update go mod and sum
2019-11-15 16:06:11 +08:00

54 lines
1.4 KiB
Go

// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package repository
import (
"fmt"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/notification"
)
// TransferOwnership transfers all corresponding setting from old user to new one.
func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error {
if err := repo.GetOwner(); err != nil {
return err
}
oldOwner := repo.Owner
if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil {
return err
}
if err := models.NewRepoRedirect(oldOwner.ID, repo.ID, repo.Name, repo.Name); err != nil {
return fmt.Errorf("NewRepoRedirect: %v", err)
}
notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
return nil
}
// ChangeRepositoryName changes all corresponding setting from old repository name to new one.
func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
oldRepoName := repo.Name
if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
return err
}
if err := repo.GetOwner(); err != nil {
return err
}
if err := models.NewRepoRedirect(repo.Owner.ID, repo.ID, oldRepoName, newRepoName); err != nil {
return err
}
notification.NotifyRenameRepository(doer, repo, oldRepoName)
return nil
}