mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
clean repo.go
This commit is contained in:
parent
f174633b36
commit
27a9e18e48
1 changed files with 29 additions and 36 deletions
|
@ -5,29 +5,23 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/martini-contrib/render"
|
|
||||||
"github.com/martini-contrib/sessions"
|
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
"github.com/gogits/gogs/modules/base"
|
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
|
||||||
data["Title"] = "Create repository"
|
ctx.Data["Title"] = "Create repository"
|
||||||
|
|
||||||
if req.Method == "GET" {
|
if ctx.Req.Method == "GET" {
|
||||||
data["LanguageIgns"] = models.LanguageIgns
|
ctx.Data["LanguageIgns"] = models.LanguageIgns
|
||||||
data["Licenses"] = models.Licenses
|
ctx.Data["Licenses"] = models.Licenses
|
||||||
r.HTML(200, "repo/create", data)
|
ctx.Render.HTML(200, "repo/create", ctx.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasErr, ok := data["HasError"]; ok && hasErr.(bool) {
|
if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) {
|
||||||
r.HTML(200, "repo/create", data)
|
ctx.Render.HTML(200, "repo/create", ctx.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +30,10 @@ func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request
|
||||||
user, err := models.GetUserById(form.UserId)
|
user, err := models.GetUserById(form.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == models.ErrUserNotExist.Error() {
|
if err.Error() == models.ErrUserNotExist.Error() {
|
||||||
data["HasError"] = true
|
ctx.Data["HasError"] = true
|
||||||
data["ErrorMsg"] = "User does not exist"
|
ctx.Data["ErrorMsg"] = "User does not exist"
|
||||||
auth.AssignForm(form, data)
|
auth.AssignForm(form, ctx.Data)
|
||||||
r.HTML(200, "repo/create", data)
|
ctx.Render.HTML(200, "repo/create", ctx.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,27 +42,27 @@ func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request
|
||||||
if _, err = models.CreateRepository(user,
|
if _, err = models.CreateRepository(user,
|
||||||
form.RepoName, form.Description, form.Language, form.License,
|
form.RepoName, form.Description, form.Language, form.License,
|
||||||
form.Visibility == "private", form.InitReadme == "on"); err == nil {
|
form.Visibility == "private", form.InitReadme == "on"); err == nil {
|
||||||
r.Redirect("/"+user.Name+"/"+form.RepoName, 302)
|
ctx.Render.Redirect("/"+user.Name+"/"+form.RepoName, 302)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Error() == models.ErrRepoAlreadyExist.Error() {
|
if err.Error() == models.ErrRepoAlreadyExist.Error() {
|
||||||
data["HasError"] = true
|
ctx.Data["HasError"] = true
|
||||||
data["ErrorMsg"] = "Repository name has already been used"
|
ctx.Data["ErrorMsg"] = "Repository name has already been used"
|
||||||
auth.AssignForm(form, data)
|
auth.AssignForm(form, ctx.Data)
|
||||||
r.HTML(200, "repo/create", data)
|
ctx.Render.HTML(200, "repo/create", ctx.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Handle(200, "repo.Create", err)
|
ctx.Handle(200, "repo.Create", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(form auth.DeleteRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func Delete(ctx *middleware.Context, form auth.DeleteRepoForm) {
|
||||||
data["Title"] = "Delete repository"
|
ctx.Data["Title"] = "Delete repository"
|
||||||
|
|
||||||
if req.Method == "GET" {
|
if ctx.Req.Method == "GET" {
|
||||||
r.HTML(200, "repo/delete", data)
|
ctx.Render.HTML(200, "repo/delete", ctx.Data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,23 +71,22 @@ func Delete(form auth.DeleteRepoForm, ctx *middleware.Context, req *http.Request
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Redirect("/", 302)
|
ctx.Render.Redirect("/", 302)
|
||||||
}
|
}
|
||||||
|
|
||||||
func List(ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func List(ctx *middleware.Context) {
|
||||||
u := auth.SignedInUser(session)
|
if ctx.User != nil {
|
||||||
if u != nil {
|
ctx.Render.Redirect("/")
|
||||||
r.Redirect("/")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["Title"] = "Repositories"
|
ctx.Data["Title"] = "Repositories"
|
||||||
repos, err := models.GetRepositories(u)
|
repos, err := models.GetRepositories(ctx.User)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(200, "repo.List", err)
|
ctx.Handle(200, "repo.List", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["Repos"] = repos
|
ctx.Data["Repos"] = repos
|
||||||
r.HTML(200, "repo/list", data)
|
ctx.Render.HTML(200, "repo/list", ctx.Data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue