1
0

repos.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2014 The Gogs 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 admin
  5. import (
  6. "github.com/unknwon/paginater"
  7. log "unknwon.dev/clog/v2"
  8. "gogs.io/gogs/internal/conf"
  9. "gogs.io/gogs/internal/context"
  10. "gogs.io/gogs/internal/database"
  11. )
  12. const (
  13. REPOS = "admin/repo/list"
  14. )
  15. func Repos(c *context.Context) {
  16. c.Data["Title"] = c.Tr("admin.repositories")
  17. c.Data["PageIsAdmin"] = true
  18. c.Data["PageIsAdminRepositories"] = true
  19. page := c.QueryInt("page")
  20. if page <= 0 {
  21. page = 1
  22. }
  23. var (
  24. repos []*database.Repository
  25. count int64
  26. err error
  27. )
  28. keyword := c.Query("q")
  29. if keyword == "" {
  30. repos, err = database.Repositories(page, conf.UI.Admin.RepoPagingNum)
  31. if err != nil {
  32. c.Error(err, "list repositories")
  33. return
  34. }
  35. count = database.CountRepositories(true)
  36. } else {
  37. repos, count, err = database.SearchRepositoryByName(&database.SearchRepoOptions{
  38. Keyword: keyword,
  39. OrderBy: "id ASC",
  40. Private: true,
  41. Page: page,
  42. PageSize: conf.UI.Admin.RepoPagingNum,
  43. })
  44. if err != nil {
  45. c.Error(err, "search repository by name")
  46. return
  47. }
  48. }
  49. c.Data["Keyword"] = keyword
  50. c.Data["Total"] = count
  51. c.Data["Page"] = paginater.New(int(count), conf.UI.Admin.RepoPagingNum, page, 5)
  52. if err = database.RepositoryList(repos).LoadAttributes(); err != nil {
  53. c.Error(err, "load attributes")
  54. return
  55. }
  56. c.Data["Repos"] = repos
  57. c.Success(REPOS)
  58. }
  59. func DeleteRepo(c *context.Context) {
  60. repo, err := database.GetRepositoryByID(c.QueryInt64("id"))
  61. if err != nil {
  62. c.Error(err, "get repository by ID")
  63. return
  64. }
  65. if err := database.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
  66. c.Error(err, "delete repository")
  67. return
  68. }
  69. log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
  70. c.Flash.Success(c.Tr("repo.settings.deletion_success"))
  71. c.JSONSuccess(map[string]any{
  72. "redirect": conf.Server.Subpath + "/admin/repos?page=" + c.Query("page"),
  73. })
  74. }