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

mail_repo.go 1.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2021 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 mailer
  5. import (
  6. "bytes"
  7. "fmt"
  8. "code.gitea.io/gitea/models"
  9. )
  10. // SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
  11. func SendRepoTransferNotifyMail(doer, newOwner *models.User, repo *models.Repository) error {
  12. var (
  13. emails []string
  14. destination string
  15. content bytes.Buffer
  16. )
  17. if newOwner.IsOrganization() {
  18. users, err := models.GetUsersWhoCanCreateOrgRepo(newOwner.ID)
  19. if err != nil {
  20. return err
  21. }
  22. for i := range users {
  23. emails = append(emails, users[i].Email)
  24. }
  25. destination = newOwner.DisplayName()
  26. } else {
  27. emails = []string{newOwner.Email}
  28. destination = "you"
  29. }
  30. subject := fmt.Sprintf("%s would like to transfer \"%s\" to %s", doer.DisplayName(), repo.FullName(), destination)
  31. data := map[string]interface{}{
  32. "Doer": doer,
  33. "User": repo.Owner,
  34. "Repo": repo.FullName(),
  35. "Link": repo.HTMLURL(),
  36. "Subject": subject,
  37. "Destination": destination,
  38. }
  39. if err := bodyTemplates.ExecuteTemplate(&content, string(mailRepoTransferNotify), data); err != nil {
  40. return err
  41. }
  42. msg := NewMessage(emails, subject, content.String())
  43. msg.Info = fmt.Sprintf("UID: %d, repository pending transfer notification", newOwner.ID)
  44. SendAsync(msg)
  45. return nil
  46. }