Browse Source

Clean code

for-closed-social
Unknown 10 years ago
parent
commit
828c89de99
7 changed files with 19 additions and 26 deletions
  1. +1
    -0
      README.md
  2. +10
    -12
      gogs.go
  3. +1
    -1
      models/repo.go
  4. +5
    -9
      modules/middleware/repo.go
  5. +1
    -1
      serve.go
  6. +1
    -1
      templates/repo/create.tmpl
  7. +0
    -2
      web.go

+ 1
- 0
README.md View File

@ -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.

+ 10
- 12
gogs.go View File

@ -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)
}

+ 1
- 1
models/repo.go View File

@ -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
}

+ 5
- 9
modules/middleware/repo.go View File

@ -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
}

+ 1
- 1
serve.go View File

@ -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
}

+ 1
- 1
templates/repo/create.tmpl View File

@ -59,7 +59,7 @@
<div class="col-md-8 col-md-offset-2">
<div class="checkbox">
<label>
<input type="checkbox" name="initReadme">
<input type="checkbox" name="initReadme" {{if .initReadme}}checked{{end}}>
<strong>Initialize this repository with a README</strong>
</label>
</div>

+ 0
- 2
web.go View File

@ -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"))

Loading…
Cancel
Save