You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repository
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/notification"
  9. )
  10. // TransferOwnership transfers all corresponding setting from old user to new one.
  11. func TransferOwnership(doer *models.User, newOwnerName string, repo *models.Repository) error {
  12. if err := repo.GetOwner(); err != nil {
  13. return err
  14. }
  15. oldOwner := repo.Owner
  16. if err := models.TransferOwnership(doer, newOwnerName, repo); err != nil {
  17. return err
  18. }
  19. if err := models.NewRepoRedirect(oldOwner.ID, repo.ID, repo.Name, repo.Name); err != nil {
  20. return fmt.Errorf("NewRepoRedirect: %v", err)
  21. }
  22. notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
  23. return nil
  24. }
  25. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  26. func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoName string) error {
  27. oldRepoName := repo.Name
  28. if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
  29. return err
  30. }
  31. if err := repo.GetOwner(); err != nil {
  32. return err
  33. }
  34. if err := models.NewRepoRedirect(repo.Owner.ID, repo.ID, oldRepoName, newRepoName); err != nil {
  35. return err
  36. }
  37. notification.NotifyRenameRepository(doer, repo, oldRepoName)
  38. return nil
  39. }