From 08feaf3deda4c82579375779cb27a403c4e1d79a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 13 Mar 2014 11:56:25 +0800 Subject: [PATCH] add repo router --- routers/repo/repo.go | 25 +++++++++++++++++++++---- serve.go | 2 +- templates/repo/repo.tmpl | 10 ++++++++++ web.go | 2 ++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 templates/repo/repo.tmpl diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 62352f76cf..6444034525 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -5,9 +5,9 @@ package repo import ( - "fmt" "net/http" + "github.com/codegangsta/martini" "github.com/martini-contrib/render" "github.com/martini-contrib/sessions" @@ -87,12 +87,29 @@ func Delete(req *http.Request, r render.Render, data base.TmplData, session sess } } -func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { - data["Title"] = "Repositories" +func Repo(params martini.Params, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { + data["Title"] = "Repository" + files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/") + if err != nil { + data["ErrorMsg"] = err + log.Error("repo.List: %v", err) + r.HTML(200, "base/error", data) + return + } + data["Files"] = files + r.HTML(200, "repo/repo", data) +} + +func List(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { u := auth.SignedInUser(session) + if u != nil { + r.Redirect("/") + return + } + + data["Title"] = "Repositories" repos, err := models.GetRepositories(u) - fmt.Println("repos", repos) if err != nil { data["ErrorMsg"] = err log.Error("repo.List: %v", err) diff --git a/serve.go b/serve.go index d4874b3ed6..56105f2f80 100644 --- a/serve.go +++ b/serve.go @@ -58,7 +58,7 @@ func runServ(*cli.Context) { cmd := os.Getenv("SSH_ORIGINAL_COMMAND") if cmd == "" { - printf("Hi %s! You've successfully authenticated, but Gogs does not provide shell access.\n", user.Name) + println("Hi ", user.Name, "! You've successfully authenticated, but Gogs does not provide shell access.") return } diff --git a/templates/repo/repo.tmpl b/templates/repo/repo.tmpl new file mode 100644 index 0000000000..5ae3f25c16 --- /dev/null +++ b/templates/repo/repo.tmpl @@ -0,0 +1,10 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
+ +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index c7c704c168..0b41a909d6 100644 --- a/web.go +++ b/web.go @@ -70,6 +70,8 @@ func runWeb(*cli.Context) { m.Get("/user/:username", auth.SignInRequire(false), user.Profile) + m.Get("/:username/:reponame", repo.Repo) + m.Any("/repo/create", auth.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) m.Any("/repo/delete", auth.SignInRequire(true), repo.Delete) m.Any("/repo/list", auth.SignInRequire(false), repo.List)