-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
repos.go
87 lines (74 loc) · 2.02 KB
/
repos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2014 The Gogs 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 admin
import (
"github.com/Unknwon/paginater"
log "gopkg.in/clog.v1"
"github.com/gogs/gogs/models"
"github.com/gogs/gogs/pkg/context"
"github.com/gogs/gogs/pkg/setting"
)
const (
REPOS = "admin/repo/list"
)
func Repos(c *context.Context) {
c.Data["Title"] = c.Tr("admin.repositories")
c.Data["PageIsAdmin"] = true
c.Data["PageIsAdminRepositories"] = true
page := c.QueryInt("page")
if page <= 0 {
page = 1
}
var (
repos []*models.Repository
count int64
err error
)
keyword := c.Query("q")
if len(keyword) == 0 {
repos, err = models.Repositories(page, setting.UI.Admin.RepoPagingNum)
if err != nil {
c.Handle(500, "Repositories", err)
return
}
count = models.CountRepositories(true)
} else {
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
Keyword: keyword,
OrderBy: "id ASC",
Private: true,
Page: page,
PageSize: setting.UI.Admin.RepoPagingNum,
})
if err != nil {
c.Handle(500, "SearchRepositoryByName", err)
return
}
}
c.Data["Keyword"] = keyword
c.Data["Total"] = count
c.Data["Page"] = paginater.New(int(count), setting.UI.Admin.RepoPagingNum, page, 5)
if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
c.Handle(500, "LoadAttributes", err)
return
}
c.Data["Repos"] = repos
c.HTML(200, REPOS)
}
func DeleteRepo(c *context.Context) {
repo, err := models.GetRepositoryByID(c.QueryInt64("id"))
if err != nil {
c.Handle(500, "GetRepositoryByID", err)
return
}
if err := models.DeleteRepository(repo.MustOwner().ID, repo.ID); err != nil {
c.Handle(500, "DeleteRepository", err)
return
}
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
c.Flash.Success(c.Tr("repo.settings.deletion_success"))
c.JSON(200, map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/repos?page=" + c.Query("page"),
})
}