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.

fixture_generation.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 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 models
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. // GetYamlFixturesAccess returns a string containing the contents
  10. // for the access table, as recalculated using repo.RecalculateAccesses()
  11. func GetYamlFixturesAccess() (string, error) {
  12. repos := make([]*Repository, 0, 50)
  13. if err := x.Find(&repos); err != nil {
  14. return "", err
  15. }
  16. for _, repo := range repos {
  17. repo.MustOwner()
  18. if err := repo.RecalculateAccesses(); err != nil {
  19. return "", err
  20. }
  21. }
  22. var b strings.Builder
  23. accesses := make([]*Access, 0, 200)
  24. if err := x.OrderBy("user_id, repo_id").Find(&accesses); err != nil {
  25. return "", err
  26. }
  27. for i, a := range accesses {
  28. fmt.Fprintf(&b, "-\n")
  29. fmt.Fprintf(&b, " id: %d\n", i+1)
  30. fmt.Fprintf(&b, " user_id: %d\n", a.UserID)
  31. fmt.Fprintf(&b, " repo_id: %d\n", a.RepoID)
  32. fmt.Fprintf(&b, " mode: %d\n", a.Mode)
  33. fmt.Fprintf(&b, "\n")
  34. }
  35. return b.String(), nil
  36. }