From 828c89de996c328bb3759d90be8a8a35b4d9cdc0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 16 Mar 2014 02:28:24 -0400 Subject: [PATCH] Clean code --- README.md | 1 + gogs.go | 22 ++++++++++------------ models/repo.go | 2 +- modules/middleware/repo.go | 14 +++++--------- serve.go | 2 +- templates/repo/create.tmpl | 2 +- web.go | 2 -- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 526cc501b2..0fb646e5e0 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, devel ## Features +- Activity timeline - SSH protocal support. - Register/delete account. - Create/delete public repository. diff --git a/gogs.go b/gogs.go index e826ab9f36..08421f0055 100644 --- a/gogs.go +++ b/gogs.go @@ -7,7 +7,7 @@ package main import ( "os" - "os/user" + // "os/user" "runtime" "github.com/codegangsta/cli" @@ -27,14 +27,14 @@ func init() { runtime.GOMAXPROCS(runtime.NumCPU()) } -func checkRunUser() bool { - u, err := user.Current() - if err != nil { - // TODO: log - return false - } - return u.Username == base.Cfg.MustValue("", "RUN_USER") -} +// func checkRunUser() bool { +// u, err := user.Current() +// if err != nil { +// // TODO: log +// return false +// } +// return u.Username == base.Cfg.MustValue("", "RUN_USER") +// } func main() { /*if !checkRunUser() { @@ -50,8 +50,6 @@ func main() { CmdWeb, CmdServ, } - app.Flags = append(app.Flags, []cli.Flag{ - cli.BoolFlag{"noterm", "disable color output"}, - }...) + app.Flags = append(app.Flags, []cli.Flag{}...) app.Run(os.Args) } diff --git a/models/repo.go b/models/repo.go index 125abfc342..56e286ec4a 100644 --- a/models/repo.go +++ b/models/repo.go @@ -253,7 +253,7 @@ func GetRepositoryById(id int64) (repo *Repository, err error) { // GetRepositories returns the list of repositories of given user. func GetRepositories(user *User) ([]Repository, error) { repos := make([]Repository, 0, 10) - err := orm.Find(&repos, &Repository{OwnerId: user.Id}) + err := orm.Desc("updated").Find(&repos, &Repository{OwnerId: user.Id}) return repos, err } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 948713efe8..8cdc6df718 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -5,6 +5,8 @@ package middleware import ( + "errors" + "github.com/codegangsta/martini" "github.com/gogits/gogs/models" @@ -31,9 +33,7 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Render.Redirect("/") return } - //data["ErrorMsg"] = err - //log.Error("repo.Single: %v", err) - //r.HTML(200, "base/error", data) + ctx.Handle(200, "RepoAssignment", err) return } } else { @@ -45,9 +45,7 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Render.Redirect("/") return } - //data["ErrorMsg"] = "invliad user account for single repository" - //log.Error("repo.Single: %v", err) - //r.HTML(200, "base/error", data) + ctx.Handle(200, "RepoAssignment", errors.New("invliad user account for single repository")) return } @@ -60,9 +58,7 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Render.Redirect("/") return } - //data["ErrorMsg"] = err - //log.Error("repo.Single: %v", err) - //r.HTML(200, "base/error", data) + ctx.Handle(200, "RepoAssignment", err) return } diff --git a/serve.go b/serve.go index 56105f2f80..68455de3d3 100644 --- a/serve.go +++ b/serve.go @@ -58,7 +58,7 @@ func runServ(*cli.Context) { cmd := os.Getenv("SSH_ORIGINAL_COMMAND") if cmd == "" { - println("Hi ", user.Name, "! You've successfully authenticated, but Gogs does not provide shell access.") + println("Hi", user.Name, "! You've successfully authenticated, but Gogs does not provide shell access.") return } diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 93d33c8744..2de92f515f 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -59,7 +59,7 @@
diff --git a/web.go b/web.go index 3f0e0ef7e2..b7138120a3 100644 --- a/web.go +++ b/web.go @@ -74,8 +74,6 @@ func runWeb(*cli.Context) { middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) m.Get("/:username/:reponame", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) - //m.Get("/:username/:reponame", repo.Repo) - listenAddr := fmt.Sprintf("%s:%s", base.Cfg.MustValue("server", "HTTP_ADDR"), base.Cfg.MustValue("server", "HTTP_PORT", "3000"))