From a55941ff833155cba88dbcc957b15c0ddcf07cb4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 17:34:07 -0400 Subject: [PATCH 01/40] Add auto-detect home directory --- conf/app.ini | 2 +- modules/base/conf.go | 9 +++++++-- routers/repo/issue.go | 12 ++++++------ templates/install.tmpl | 2 +- templates/issue/view.tmpl | 18 ++++++++++-------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index a3c749be01..05c7745fc4 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -7,7 +7,7 @@ RUN_USER = git RUN_MODE = dev [repository] -ROOT = /Users/%(RUN_USER)s/git/gogs-repositories +ROOT = LANG_IGNS = Google Go|C|C++|Python|Ruby|C Sharp LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|BSD (3-Clause) License diff --git a/modules/base/conf.go b/modules/base/conf.go index b3a987e646..fd77cfd3ce 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -291,9 +291,14 @@ func NewConfigContext() { PictureService = Cfg.MustValue("picture", "SERVICE") // Determine and create root git reposiroty path. - RepoRootPath = Cfg.MustValue("repository", "ROOT") + homeDir, err := com.HomeDir() + if err != nil { + fmt.Printf("Fail to get home directory): %v\n", err) + os.Exit(2) + } + RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories")) if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { - fmt.Printf("models.init(fail to create RepoRootPath(%s)): %v\n", RepoRootPath, err) + fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err) os.Exit(2) } } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c3d1a0d960..6ac8a53579 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -231,6 +231,12 @@ func Comment(ctx *middleware.Context, params martini.Params) { return } + content := ctx.Query("content") + if len(content) == 0 { + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", ctx.User.Name, ctx.Repo.Repository.Name, index)) + return + } + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.Id, int64(index)) if err != nil { if err == models.ErrIssueNotExist { @@ -241,12 +247,6 @@ func Comment(ctx *middleware.Context, params martini.Params) { return } - content := ctx.Query("content") - if len(content) == 0 { - ctx.Handle(404, "issue.Comment", err) - return - } - switch params["action"] { case "new": if err = models.CreateComment(ctx.User.Id, issue.Id, 0, 0, content); err != nil { diff --git a/templates/install.tmpl b/templates/install.tmpl index be5a69186d..872982a0ad 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -133,7 +133,7 @@
- +    -    + {{if .Issue.IsClosed}} + + {{else}} + + {{end}}  
From 6e376bb85c7a154c7567fd4be8cabc9627c8c6e7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 18:40:31 -0400 Subject: [PATCH 02/40] Working on install page --- modules/auth/auth.go | 50 ++++++++++++++++++++++++++++++++++++++++++ routers/install.go | 3 ++- templates/install.tmpl | 8 +++---- web.go | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 2e0555f6df..ac03a8f126 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -161,3 +161,53 @@ func AssignForm(form interface{}, data base.TmplData) { data[fieldName] = val.Field(i).Interface() } } + +type InstallForm struct { + Database string `form:"database" binding:"Required"` + Host string `form:"host"` + User string `form:"user"` + Passwd string `form:"passwd"` + DatabaseName string `form:"database_name"` + SslMode string `form:"ssl_mode"` + DatabasePath string `form:"database_path"` + RepoRootPath string `form:"repo_path"` + RunUser string `form:"run_user"` + AppUrl string `form:"app_url"` + AdminName string `form:"admin_name" binding:"Required"` + AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(30)"` + AdminEmail string `form:"admin_email" binding:"Required;Email;MaxSize(50)"` + SmtpHost string `form:"smtp_host"` + SmtpEmail string `form:"mailer_user"` + SmtpPasswd string `form:"mailer_pwd"` + RegisterConfirm string `form:"register_confirm"` + MailNotify string `form:"mail_notify"` +} + +func (f *InstallForm) Name(field string) string { + names := map[string]string{ + "Database": "Database name", + "AdminName": "Admin user name", + "AdminPasswd": "Admin password", + "AdminEmail": "Admin e-maill address", + } + return names[field] +} + +func (f *InstallForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + if req.Method == "GET" || errors.Count() == 0 { + return + } + + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + data["HasError"] = true + AssignForm(f, data) + + if len(errors.Overall) > 0 { + for _, err := range errors.Overall { + log.Error("InstallForm.Validate: %v", err) + } + return + } + + validate(errors, data, f) +} diff --git a/routers/install.go b/routers/install.go index e0ac92f130..b5c3a9364b 100644 --- a/routers/install.go +++ b/routers/install.go @@ -8,11 +8,12 @@ import ( "errors" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) -func Install(ctx *middleware.Context) { +func Install(ctx *middleware.Context, form auth.InstallForm) { if base.InstallLock { ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) return diff --git a/templates/install.tmpl b/templates/install.tmpl index 872982a0ad..d8f05fcaa7 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -43,7 +43,7 @@
- +

Recommend use INNODB engine with utf8_general_ci charset.

@@ -64,7 +64,7 @@
- +

The file path of SQLite3 database.

@@ -78,7 +78,7 @@
- +

The git copy of each repository is saved in this directory.

@@ -88,7 +88,7 @@
- +

The user has access to visit and run Gogs.

diff --git a/web.go b/web.go index 4ed273ea99..35695f0bfb 100644 --- a/web.go +++ b/web.go @@ -90,7 +90,7 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", ignSignIn, routers.Home) - m.Get("/install", routers.Install) + m.Any("/install", routers.Install) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) From d01820c125669367b7a585d767d5f11e73a701c2 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 13:40:22 +0800 Subject: [PATCH 03/40] conf support mysql port --- conf/app.ini | 2 +- models/models.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 05c7745fc4..abc27c39c4 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -20,7 +20,7 @@ HTTP_PORT = 3000 [database] ; Either "mysql", "postgres" or "sqlite3"(binary release only), it's your choice DB_TYPE = mysql -HOST = +HOST = 127.0.0.1:3306 NAME = gogs USER = root PASSWD = diff --git a/models/models.go b/models/models.go index 04a361c595..bafa1747e8 100644 --- a/models/models.go +++ b/models/models.go @@ -38,7 +38,7 @@ func SetEngine() { var err error switch DbCfg.Type { case "mysql": - orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", + orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) case "postgres": orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", From e085d7738a683785a5d7d7e3a33a0437c87c340b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 14:35:27 +0800 Subject: [PATCH 04/40] add mysql create db sql file --- conf/mysql.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 conf/mysql.sql diff --git a/conf/mysql.sql b/conf/mysql.sql new file mode 100644 index 0000000000..6247d657bb --- /dev/null +++ b/conf/mysql.sql @@ -0,0 +1,2 @@ +DROP DATABASE gogs; +CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci; \ No newline at end of file From bf2e76fc7ef187ce3b3e1ed9172cedf55d8fd5cb Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 18:45:22 +0800 Subject: [PATCH 05/40] change issue reopen and close btn --- templates/issue/view.tmpl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 6f0a384800..516206da96 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -87,10 +87,8 @@
{{if .Issue.IsClosed}} - - {{else}} - - {{end}}   + {{else}} + {{end}}  
From beb1761d7c9c2bd85a9f67895836c77ec4bbb6bc Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 06:55:51 -0400 Subject: [PATCH 06/40] Mirror fix --- gogs.go | 2 +- routers/repo/issue.go | 1 + templates/user/dashboard.tmpl | 2 +- templates/user/profile.tmpl | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gogs.go b/gogs.go index f4b7c72feb..f1372f0cfc 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.9.0328 Alpha" +const APP_VER = "0.1.9.0329 Alpha" func init() { base.AppVer = APP_VER diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6ac8a53579..14876e1863 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -221,6 +221,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func Comment(ctx *middleware.Context, params martini.Params) { + fmt.Println(ctx.Query("change_status")) if !ctx.Repo.IsValid { ctx.Handle(404, "issue.Comment(invalid repo):", nil) } diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index bc0853fb0d..6064095b11 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -18,7 +18,7 @@ {{range .Feeds}}
  • -
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
    +
    {{TimeSince .Created}}
    {{ActionDesc . $.SignedUser.AvatarLink | str2html}}
  • {{else}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 3733736dde..5ac8121f8b 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -32,11 +32,10 @@ {{if eq .TabName "activity"}}
      - {{$avatarLink := .Owner.AvatarLink}} {{range .Feeds}}
    • -
      {{TimeSince .Created}}
      {{ActionDesc . $avatarLink | str2html}}
      +
      {{TimeSince .Created}}
      {{ActionDesc . $.Owner.AvatarLink | str2html}}
    • {{else}} From a726c125b572bc1ff0b445990821280e304db9ff Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 19:29:52 +0800 Subject: [PATCH 07/40] Add PushCommit --- modules/base/tool.go | 11 +++++++++-- routers/repo/repo.go | 8 +++----- update.go | 8 ++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/base/tool.go b/modules/base/tool.go index 9ddb90f721..d005ffe355 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -506,9 +506,16 @@ const (
      user-avatar %s
      ` ) +type PushCommit struct { + Sha1 string + Message string + AuthorEmail string + AuthorName string +} + type PushCommits struct { Len int - Commits [][]string + Commits []*PushCommit } // ActionDesc accepts int that represents action operation type @@ -529,7 +536,7 @@ func ActionDesc(act Actioner, avatarLink string) string { } buf := bytes.NewBuffer([]byte("\n")) for _, commit := range push.Commits { - buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit[0], commit[0][:7], commit[1]) + "\n") + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") } if push.Len > 3 { buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index e7107ad1cd..b9ac1f1c42 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -276,11 +276,9 @@ func Http(ctx *middleware.Context, params martini.Params) { } prefix := path.Join("/", username, params["reponame"]) - server := &webdav.Server{ - Fs: webdav.Dir(models.RepoPath(username, reponame)), - TrimPrefix: prefix, - Listings: true, - } + server := webdav.NewServer( + models.RepoPath(username, reponame), + prefix, true) server.ServeHTTP(ctx.ResponseWriter, ctx.Req) } diff --git a/update.go b/update.go index faec0029ac..9743dcc480 100644 --- a/update.go +++ b/update.go @@ -130,11 +130,15 @@ func runUpdate(c *cli.Context) { return } - commits := make([][]string, 0) + commits := make([]*base.PushCommit, 0) var maxCommits = 3 for e := l.Front(); e != nil; e = e.Next() { commit := e.Value.(*git.Commit) - commits = append(commits, []string{commit.Id().String(), commit.Message()}) + commits = append(commits, + &base.PushCommit{commit.Id().String(), + commit.Message(), + commit.Author.Email, + commit.Author.Name}) if len(commits) >= maxCommits { break } From 828282882066aa4e8bd8fb0c083c530607bc34bb Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 07:50:25 -0400 Subject: [PATCH 08/40] Fix action email bug --- models/action.go | 13 +++++++++---- modules/base/tool.go | 8 +++++--- routers/repo/issue.go | 2 +- routers/user/user.go | 2 +- templates/user/dashboard.tmpl | 2 +- templates/user/profile.tmpl | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/models/action.go b/models/action.go index 9d99df8546..894855784f 100644 --- a/models/action.go +++ b/models/action.go @@ -31,6 +31,7 @@ type Action struct { OpType int // Operations: CREATE DELETE STAR ... ActUserId int64 // Action user id. ActUserName string // Action user name. + ActEmail string RepoId int64 RepoName string RefName string @@ -46,6 +47,10 @@ func (a Action) GetActUserName() string { return a.ActUserName } +func (a Action) GetActEmail() string { + return a.ActEmail +} + func (a Action) GetRepoName() string { return a.RepoName } @@ -69,8 +74,8 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, OpType: OP_COMMIT_REPO, - Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: "", + OpType: OP_COMMIT_REPO, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } @@ -93,8 +98,8 @@ func CommitRepoAction(userId int64, userName string, // NewRepoAction adds new action for creating repository. func NewRepoAction(user *User, repo *Repository) (err error) { - if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, OpType: OP_CREATE_REPO, - RepoId: repo.Id, RepoName: repo.Name}); err != nil { + if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, ActEmail: user.Email, + OpType: OP_CREATE_REPO, RepoId: repo.Id, RepoName: repo.Name}); err != nil { log.Error("action.NewRepoAction(notify watchers): %d/%s", user.Id, repo.Name) return err } diff --git a/modules/base/tool.go b/modules/base/tool.go index d005ffe355..6876da7625 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -478,6 +478,7 @@ func (a argInt) Get(i int, args ...int) (r int) { type Actioner interface { GetOpType() int GetActUserName() string + GetActEmail() string GetRepoName() string GetBranch() string GetContent() string @@ -520,8 +521,9 @@ type PushCommits struct { // ActionDesc accepts int that represents action operation type // and returns the description. -func ActionDesc(act Actioner, avatarLink string) string { +func ActionDesc(act Actioner) string { actUserName := act.GetActUserName() + email := act.GetActEmail() repoName := act.GetRepoName() repoLink := actUserName + "/" + repoName branch := act.GetBranch() @@ -536,7 +538,7 @@ func ActionDesc(act Actioner, avatarLink string) string { } buf := bytes.NewBuffer([]byte("\n")) for _, commit := range push.Commits { - buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") } if push.Len > 3 { buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) @@ -546,7 +548,7 @@ func ActionDesc(act Actioner, avatarLink string) string { case 6: // Create issue. infos := strings.SplitN(content, "|", 2) return fmt.Sprintf(TPL_CREATE_Issue, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], - avatarLink, infos[1]) + AvatarLink(email), infos[1]) default: return "invalid type" } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 14876e1863..c89c8b5685 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -105,7 +105,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } // Notify watchers. - if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, + if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name, ActEmail: ctx.User.Email, OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil { ctx.Handle(200, "issue.CreateIssue", err) diff --git a/routers/user/user.go b/routers/user/user.go index b0fc583978..114169e606 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -279,7 +279,7 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { feeds := make([]string, len(actions)) for i := range actions { feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType), - base.TimeSince(actions[i].Created), base.ActionDesc(actions[i], ctx.User.AvatarLink())) + base.TimeSince(actions[i].Created), base.ActionDesc(actions[i])) } ctx.JSON(200, &feeds) } diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 6064095b11..bc0853fb0d 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -18,7 +18,7 @@ {{range .Feeds}}
    • -
      {{TimeSince .Created}}
      {{ActionDesc . $.SignedUser.AvatarLink | str2html}}
      +
      {{TimeSince .Created}}
      {{ActionDesc . | str2html}}
    • {{else}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 5ac8121f8b..97549d481c 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -35,7 +35,7 @@ {{range .Feeds}}
    • -
      {{TimeSince .Created}}
      {{ActionDesc . $.Owner.AvatarLink | str2html}}
      +
      {{TimeSince .Created}}
      {{ActionDesc . | str2html}}
    • {{else}} From ec1b801732b030648c060d26ce5a3ed8cf2e822c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 19:59:02 +0800 Subject: [PATCH 09/40] bug fixed --- models/action.go | 4 ++-- update.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/models/action.go b/models/action.go index 894855784f..1e55df85e9 100644 --- a/models/action.go +++ b/models/action.go @@ -64,7 +64,7 @@ func (a Action) GetContent() string { } // CommitRepoAction adds new action for committing repository. -func CommitRepoAction(userId int64, userName string, +func CommitRepoAction(userId int64, userName, actEmail string, repoId int64, repoName string, refName string, commit *base.PushCommits) error { log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) @@ -74,7 +74,7 @@ func CommitRepoAction(userId int64, userName string, return err } - if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: "", + if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, ActEmail: actEmail, OpType: OP_COMMIT_REPO, Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil { log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err diff --git a/update.go b/update.go index 9743dcc480..246c5d8f9d 100644 --- a/update.go +++ b/update.go @@ -132,8 +132,12 @@ func runUpdate(c *cli.Context) { commits := make([]*base.PushCommit, 0) var maxCommits = 3 + var actEmail string for e := l.Front(); e != nil; e = e.Next() { commit := e.Value.(*git.Commit) + if actEmail == "" { + actEmail = commit.Committer.Email + } commits = append(commits, &base.PushCommit{commit.Id().String(), commit.Message(), @@ -145,7 +149,7 @@ func runUpdate(c *cli.Context) { } //commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()}) - if err = models.CommitRepoAction(int64(sUserId), userName, + if err = models.CommitRepoAction(int64(sUserId), userName, actEmail, repos.Id, repoName, git.BranchName(refName), &base.PushCommits{l.Len(), commits}); err != nil { log.Error("runUpdate.models.CommitRepoAction: %v", err) } From f0d5c3992b03f4d6a82b272ac513d2989ffb8d81 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 20:46:36 +0800 Subject: [PATCH 10/40] issue ajax edit --- public/js/app.js | 55 ++++++++++++++++++++++++++++++++++++--- templates/issue/view.tmpl | 9 ++++--- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 9299a6b7aa..b03d9070a7 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -56,6 +56,43 @@ var Gogits = { }, toggleShow: function () { $(this).removeClass("hidden"); + }, + toggleAjax: function (successCallback) { + var url = $(this).data("ajax"); + var method = $(this).data('ajax-method') || 'get'; + var ajaxName = $(this).data('ajax-name'); + var data = {}; + $('[data-ajax-rel=' + ajaxName + ']').each(function () { + var field = $(this).data("ajax-field"); + var t = $(this).data("ajax-val"); + if (t == "val") { + data[field] = $(this).val(); + return true; + } + if (t == "txt") { + data[field] = $(this).text(); + return true; + } + if (t == "html") { + data[field] = $(this).html(); + return true; + } + if (t == "data") { + data[field] = $(this).data("ajax-data"); + return true; + } + return true; + }); + $.ajax({ + url: url, + method: method.toUpperCase(), + data: data, + success: function (d) { + if (successCallback) { + successCallback(d); + } + } + }) } }) }(jQuery)); @@ -386,11 +423,11 @@ function initIssue() { var $openBtn = $('#issue-open-btn'); $('#issue-reply-content').on("keyup", function () { if ($(this).val().length) { - $closeBtn.text($closeBtn.data("text")); - $openBtn.text($openBtn.data("text")); + $closeBtn.val($closeBtn.data("text")); + $openBtn.val($openBtn.data("text")); } else { - $closeBtn.text($closeBtn.data("origin")); - $openBtn.text($openBtn.data("origin")); + $closeBtn.val($closeBtn.data("origin")); + $openBtn.val($openBtn.data("origin")); } }); }()); @@ -406,6 +443,16 @@ function initIssue() { $('#issue-edit-title,#issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide(); }) }()); + + // issue ajax update + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function(json){ + if(json.ok){ + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); + }); } (function ($) { diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 516206da96..4266bcbf44 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -9,11 +9,12 @@
      #{{.Issue.Index}}

      {{.Issue.Name}}

      - + +

      - + Edit - + {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments @@ -25,7 +26,7 @@

      {{str2html .Issue.Content}}
      - +
    {{range .Comments}} From ecce694d77756264864b03e6b06077592ed1676a Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 21:16:06 +0800 Subject: [PATCH 11/40] issue content ajax preview --- public/js/app.js | 61 +++++++++++++++++++++++++------------ routers/preview.go | 17 +++++++++++ templates/issue/create.tmpl | 8 ++--- templates/issue/view.tmpl | 8 ++--- web.go | 1 + 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 routers/preview.go diff --git a/public/js/app.js b/public/js/app.js index b03d9070a7..58bda9895e 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -399,21 +399,24 @@ function initRepository() { function initInstall() { // database type change - $('#install-database').on("change", function () { - var val = $(this).val(); - if (val != "sqlite") { - $('.server-sql').show(); - $('.sqlite-setting').addClass("hide"); - if (val == "pgsql") { - $('.pgsql-setting').removeClass("hide"); + (function () { + $('#install-database').on("change", function () { + var val = $(this).val(); + if (val != "sqlite") { + $('.server-sql').show(); + $('.sqlite-setting').addClass("hide"); + if (val == "pgsql") { + $('.pgsql-setting').removeClass("hide"); + } else { + $('.pgsql-setting').addClass("hide"); + } } else { - $('.pgsql-setting').addClass("hide"); + $('.server-sql').hide(); + $('.sqlite-setting').removeClass("hide"); } - } else { - $('.server-sql').hide(); - $('.sqlite-setting').removeClass("hide"); - } - }); + }); + }()); + } function initIssue() { @@ -445,14 +448,32 @@ function initIssue() { }()); // issue ajax update - $('.issue-edit-save').on("click", function () { - $(this).toggleAjax(function(json){ - if(json.ok){ - $('.issue-head h1.title').text(json.title); - $('.issue-main > .issue-content .content').html(json.content); - } + (function () { + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function (json) { + if (json.ok) { + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); }); - }); + }()); + + // issue ajax preview + (function () { + $('[data-ajax-name=issue-preview]').on("click", function () { + var $this = $(this); + $this.toggleAjax(function (json) { + if (json.ok) { + $($this.data("preview")).html(json.content); + } + }) + }); + $('.issue-write a[data-toggle]').on("click", function () { + $('.issue-preview-content').html("loading..."); + }); + }()) + } (function ($) { diff --git a/routers/preview.go b/routers/preview.go new file mode 100644 index 0000000000..cc34c8fa02 --- /dev/null +++ b/routers/preview.go @@ -0,0 +1,17 @@ +// 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 routers + +import "github.com/gogits/gogs/modules/middleware" + +func Preview(ctx *middleware.Context) { + content := ctx.Query("content") + // todo : gfm render content + // content = Markdown(content) + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": "preview : " + content, + }) +} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index cbc21f6ce0..b8a533a198 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -18,16 +18,16 @@ Content with Markdown
    - +
    -
    preview
    +
    loading...
    diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 4266bcbf44..431b1d1042 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -72,17 +72,17 @@ Content with Markdown
    - +
    -
    preview
    +
    loading...
    diff --git a/web.go b/web.go index 35695f0bfb..451e52ff8c 100644 --- a/web.go +++ b/web.go @@ -95,6 +95,7 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) + m.Post("/preview", routers.Preview) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) From 2c073afbec4b9845e8ddd10a4d3f469874fdcd37 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 10:01:52 -0400 Subject: [PATCH 12/40] Mirror fix and update --- README.md | 2 ++ models/repo.go | 13 ++++++++++--- routers/{preview.go => api/v1/miscellaneous.go} | 13 +++++++------ templates/issue/create.tmpl | 4 ++-- templates/issue/view.tmpl | 4 ++-- templates/user/signin.tmpl | 2 +- web.go | 7 ++++++- 7 files changed, 30 insertions(+), 15 deletions(-) rename routers/{preview.go => api/v1/miscellaneous.go} (56%) diff --git a/README.md b/README.md index 7d688506d6..e88a247705 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ##### Current version: 0.1.9 Alpha +#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site. + #### Other language version - [简体中文](README_ZH.md) diff --git a/models/repo.go b/models/repo.go index 4be655d287..a848694da6 100644 --- a/models/repo.go +++ b/models/repo.go @@ -198,12 +198,19 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv c := exec.Command("git", "update-server-info") c.Dir = repoPath - err = c.Run() - if err != nil { + if err = c.Run(); err != nil { log.Error("repo.CreateRepository(exec update-server-info): %v", err) } - return repo, NewRepoAction(user, repo) + if err = NewRepoAction(user, repo); err != nil { + log.Error("repo.CreateRepository(NewRepoAction): %v", err) + } + + if err = WatchRepo(user.Id, repo.Id, true); err != nil { + log.Error("repo.CreateRepository(WatchRepo): %v", err) + } + + return repo, nil } // extractGitBareZip extracts git-bare.zip to repository path. diff --git a/routers/preview.go b/routers/api/v1/miscellaneous.go similarity index 56% rename from routers/preview.go rename to routers/api/v1/miscellaneous.go index cc34c8fa02..0ff1eb04a0 100644 --- a/routers/preview.go +++ b/routers/api/v1/miscellaneous.go @@ -2,16 +2,17 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package routers +package v1 -import "github.com/gogits/gogs/modules/middleware" +import ( + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) -func Preview(ctx *middleware.Context) { +func Markdown(ctx *middleware.Context) { content := ctx.Query("content") - // todo : gfm render content - // content = Markdown(content) ctx.Render.JSON(200, map[string]interface{}{ "ok": true, - "content": "preview : " + content, + "content": string(base.RenderMarkdown([]byte(content), "")), }) } diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index b8a533a198..f5cec0c05a 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -15,11 +15,11 @@
    - Content with Markdown + Content with Markdown
    diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 431b1d1042..c357f5354c 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -69,11 +69,11 @@
    - Content with Markdown + Content with Markdown
    diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 49a2262633..b6c39af1b8 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -44,7 +44,7 @@
    diff --git a/web.go b/web.go index 451e52ff8c..7725791e84 100644 --- a/web.go +++ b/web.go @@ -24,6 +24,7 @@ import ( "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" + "github.com/gogits/gogs/routers/api/v1" "github.com/gogits/gogs/routers/dev" "github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/user" @@ -72,6 +73,7 @@ func newMartini() *martini.ClassicMartini { } func runWeb(*cli.Context) { + fmt.Println("Server is running...") globalInit() base.NewServices() checkRunMode() @@ -95,7 +97,10 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) - m.Post("/preview", routers.Preview) + + m.Group("/api/v1", func(r martini.Router) { + r.Post("/markdown", v1.Markdown) + }) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) From ffa59739b609ce00ce21344531f27d4003dfc688 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 10:24:42 -0400 Subject: [PATCH 13/40] Add edit issue --- models/issue.go | 35 ++++++++++++++++++----------------- routers/repo/issue.go | 10 +++++++--- templates/issue/view.tmpl | 14 +++++++------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/models/issue.go b/models/issue.go index 39558ae225..9fd1b905a5 100644 --- a/models/issue.go +++ b/models/issue.go @@ -18,23 +18,24 @@ var ( // Issue represents an issue or pull request of repository. type Issue struct { - Id int64 - Index int64 // Index in one repository. - Name string - RepoId int64 `xorm:"index"` - Repo *Repository `xorm:"-"` - PosterId int64 - Poster *User `xorm:"-"` - MilestoneId int64 - AssigneeId int64 - IsPull bool // Indicates whether is a pull request or not. - IsClosed bool - Labels string `xorm:"TEXT"` - Mentions string `xorm:"TEXT"` - Content string `xorm:"TEXT"` - NumComments int - Created time.Time `xorm:"created"` - Updated time.Time `xorm:"updated"` + Id int64 + Index int64 // Index in one repository. + Name string + RepoId int64 `xorm:"index"` + Repo *Repository `xorm:"-"` + PosterId int64 + Poster *User `xorm:"-"` + MilestoneId int64 + AssigneeId int64 + IsPull bool // Indicates whether is a pull request or not. + IsClosed bool + Labels string `xorm:"TEXT"` + Mentions string `xorm:"TEXT"` + Content string `xorm:"TEXT"` + RenderedContent string `xorm:"-"` + NumComments int + Created time.Time `xorm:"created"` + Updated time.Time `xorm:"updated"` } // CreateIssue creates new issue for repository. diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c89c8b5685..b38967f717 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -152,7 +152,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { return } issue.Poster = u - issue.Content = string(base.RenderMarkdown([]byte(issue.Content), "")) + issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), "")) // Get comments. comments, err := models.GetIssueComments(issue.Id) @@ -216,8 +216,12 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } - ctx.Data["Title"] = issue.Name - ctx.Data["Issue"] = issue + ctx.JSON(200, map[string]interface{}{ + "ok": true, + "title": issue.Name, + "content": string(base.RenderMarkdown([]byte(issue.Content), "")), + "raw_content": issue.Content, + }) } func Comment(ctx *middleware.Context, params martini.Params) { diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index c357f5354c..c6f1444e46 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -4,17 +4,17 @@ {{template "repo/toolbar" .}}
    -
    +
    #{{.Issue.Index}}

    {{.Issue.Name}}

    - - + +

    Edit - + {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments @@ -24,13 +24,13 @@

    - {{str2html .Issue.Content}} + {{str2html .Issue.RenderedContent}}
    - +
    {{range .Comments}} -
    +
    From be45057c3aef74c4b8bdc28ebd84c7297d1a7b62 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 23:03:01 +0800 Subject: [PATCH 14/40] fix issue ajax update --- public/js/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/js/app.js b/public/js/app.js index 58bda9895e..5181933d24 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -454,6 +454,7 @@ function initIssue() { if (json.ok) { $('.issue-head h1.title').text(json.title); $('.issue-main > .issue-content .content').html(json.content); + $('.issue-edit-cancel').trigger("click"); } }); }); From 5ab3962b125a6759501507e3202515f807ea95ee Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 23:54:33 +0800 Subject: [PATCH 15/40] fix issue button text change --- templates/issue/view.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index c6f1444e46..042cbdaf45 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -79,7 +79,7 @@
    - +
    loading...
    From cad2ced3945401243d7b644cb613432e1712ab41 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 11:56:00 -0400 Subject: [PATCH 16/40] Bug fix --- routers/repo/issue.go | 8 ++++---- templates/install.tmpl | 2 +- templates/issue/view.tmpl | 8 ++++---- web.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index b38967f717..337bd4bf1c 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -175,6 +175,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.Data["Comments"] = comments + ctx.Data["IsIssueOwner"] = issue.PosterId == ctx.User.Id ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false ctx.HTML(200, "issue/view") @@ -217,10 +218,9 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } ctx.JSON(200, map[string]interface{}{ - "ok": true, - "title": issue.Name, - "content": string(base.RenderMarkdown([]byte(issue.Content), "")), - "raw_content": issue.Content, + "ok": true, + "title": issue.Name, + "content": string(base.RenderMarkdown([]byte(issue.Content), "")), }) } diff --git a/templates/install.tmpl b/templates/install.tmpl index d8f05fcaa7..a456ac5f2c 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -133,7 +133,7 @@
    - +
    -->
    -
    + {{if .SignedUser}}
    {{.CsrfTokenHtml}} @@ -95,7 +95,7 @@
    -
    +
    {{else}}
    Sign up for free to join this conversation. Already have an account? Sign in to comment
    {{end}}
    - +
    - +

    @@ -175,7 +180,7 @@
    @@ -186,7 +191,7 @@
    diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 0481a33b40..91e5250ca3 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -30,37 +30,37 @@
    {{range .Comments}} -
    - -
    -
    - {{.Poster.Name}} commented {{TimeSince .Created}} - - Owner -
    -
    - {{str2html .Content}} -
    -
    -
    + {{if eq .Type 0}} +
    + +
    +
    + {{.Poster.Name}} commented {{TimeSince .Created}} + + Owner +
    +
    + {{str2html .Content}} +
    +
    +
    + {{else if eq .Type 1}} +
    + +
    + {{.Poster.Name}} Reopened this issue {{TimeSince .Created}} +
    +
    + {{else if eq .Type 2}} +
    + +
    + {{.Poster.Name}} Closed this issue {{TimeSince .Created}} +
    +
    + {{end}} {{end}} -
    {{if .SignedUser}}
    @@ -68,8 +68,7 @@ {{.CsrfTokenHtml}}
    -
    - Content with Markdown +
    Content with Markdown
    -
    loading...
    +
    Loading...
    {{if .Issue.IsClosed}} - {{else}} + {{else}} {{end}}  
    diff --git a/web.go b/web.go index 7098717a05..6aabc0e909 100644 --- a/web.go +++ b/web.go @@ -8,19 +8,16 @@ import ( "fmt" "html/template" "net/http" - "strings" "github.com/codegangsta/cli" "github.com/codegangsta/martini" "github.com/gogits/binding" - "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" @@ -40,27 +37,6 @@ and it takes care of all the other things for you`, Flags: []cli.Flag{}, } -// globalInit is for global configuration reload-able. -func globalInit() { - base.NewConfigContext() - mailer.NewMailerContext() - models.LoadModelsConfig() - models.LoadRepoConfig() - models.NewRepoContext() - models.NewEngine() -} - -// Check run mode(Default of martini is Dev). -func checkRunMode() { - switch base.Cfg.MustValue("", "RUN_MODE") { - case "prod": - martini.Env = martini.Prod - case "test": - martini.Env = martini.Test - } - log.Info("Run Mode: %s", strings.Title(martini.Env)) -} - func newMartini() *martini.ClassicMartini { r := martini.NewRouter() m := martini.New() @@ -74,9 +50,7 @@ func newMartini() *martini.ClassicMartini { func runWeb(*cli.Context) { fmt.Println("Server is running...") - globalInit() - base.NewServices() - checkRunMode() + routers.GlobalInit() log.Info("%s %s", base.AppName, base.AppVer) m := newMartini() From 3f657607393e35c96a3519ac589778cb021b8b95 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:05:39 +0800 Subject: [PATCH 18/40] NewLogger set to display line number --- modules/log/log.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/log/log.go b/modules/log/log.go index e1bab8ae4a..f00675481d 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -15,13 +15,14 @@ var ( ) func init() { - logger = logs.NewLogger(10000) - logger.SetLogger("console", `{"level": 0}`) + NewLogger(10000, "console", `{"level": 0}`) } func NewLogger(bufLen int64, mode, config string) { Mode, Config = mode, config logger = logs.NewLogger(bufLen) + logger.EnableFuncCallDepth(true) + logger.SetLogFuncCallDepth(4) logger.SetLogger(mode, config) } From 66b697a51345bfed8cc472cb894a6edc7845397f Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:05:54 +0800 Subject: [PATCH 19/40] add ShortSha template func --- modules/base/template.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/base/template.go b/modules/base/template.go index dca76fafdc..dfcae93147 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -33,6 +33,13 @@ func List(l *list.List) chan interface{} { return c } +func ShortSha(sha1 string) string { + if len(sha1) == 40 { + return sha1[:10] + } + return sha1 +} + var mailDomains = map[string]string{ "gmail.com": "gmail.com", } @@ -72,4 +79,5 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ }, "DiffTypeToStr": DiffTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, + "ShortSha": ShortSha, } From e60676aec607471ebfff3a463a7cd7050d645672 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:06:53 +0800 Subject: [PATCH 20/40] remove repeat routers & change commitd to branchname --- web.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web.go b/web.go index 6aabc0e909..465d7da7aa 100644 --- a/web.go +++ b/web.go @@ -130,8 +130,8 @@ func runWeb(*cli.Context) { r.Post("/issues/:index", binding.BindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) r.Post("/comment/:action", repo.Comment) }, reqSignIn, middleware.RepoAssignment(true)) + m.Group("/:username/:reponame", func(r martini.Router) { - r.Get("/commits/:branchname", repo.Commits) r.Get("/issues", repo.Issues) r.Get("/issues/:index", repo.ViewIssue) r.Get("/pulls", repo.Pulls) @@ -140,11 +140,10 @@ func runWeb(*cli.Context) { r.Get("/src/:branchname/**", repo.Single) r.Get("/raw/:branchname/**", repo.SingleDownload) r.Get("/commits/:branchname", repo.Commits) - r.Get("/commits/:branchname", repo.Commits) }, ignSignIn, middleware.RepoAssignment(true)) - m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Diff) - m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Diff) + m.Get("/:username/:reponame/commit/:branchname/**", ignSignIn, middleware.RepoAssignment(true), repo.Diff) + m.Get("/:username/:reponame/commit/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Diff) m.Group("/:username", func(r martini.Router) { r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single) From 105f97e61ce3d9f2bc8ce178d0ffcbf531bd91b3 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:09:59 +0800 Subject: [PATCH 21/40] remove Context.IsValid & verify repo in middleware repo.go --- modules/middleware/context.go | 14 ++++++- modules/middleware/repo.go | 74 ++++++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/modules/middleware/context.go b/modules/middleware/context.go index d81ab999bf..a6aa58eebc 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -18,6 +18,7 @@ import ( "github.com/codegangsta/martini" "github.com/gogits/cache" + "github.com/gogits/git" "github.com/gogits/session" "github.com/gogits/gogs/models" @@ -41,11 +42,18 @@ type Context struct { csrfToken string Repo struct { - IsValid bool IsOwner bool IsWatching bool + IsBranch bool + IsTag bool + IsCommit bool Repository *models.Repository Owner *models.User + Commit *git.Commit + GitRepo *git.Repository + BranchName string + CommitId string + RepoLink string CloneLink struct { SSH string HTTPS string @@ -98,6 +106,10 @@ func (ctx *Context) Handle(status int, title string, err error) { ctx.HTML(status, fmt.Sprintf("status/%d", status)) } +func (ctx *Context) Debug(msg string, args ...interface{}) { + log.Debug(msg, args...) +} + func (ctx *Context) GetCookie(name string) string { cookie, err := ctx.Req.Cookie(name) if err != nil { diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 54b735af07..d1b68b052c 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -11,6 +11,8 @@ import ( "github.com/codegangsta/martini" + "github.com/gogits/git" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" ) @@ -25,8 +27,12 @@ func RepoAssignment(redirect bool) martini.Handler { err error ) + userName := params["username"] + repoName := params["reponame"] + branchName := params["branchname"] + // get repository owner - ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == strings.ToLower(params["username"]) + ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) if !ctx.Repo.IsOwner { user, err = models.GetUserByName(params["username"]) @@ -51,10 +57,8 @@ func RepoAssignment(redirect bool) martini.Handler { return } - ctx.Repo.Owner = user - // get repository - repo, err := models.GetRepositoryByName(user.Id, params["reponame"]) + repo, err := models.GetRepositoryByName(user.Id, repoName) if err != nil { if err == models.ErrRepoNotExist { ctx.Handle(404, "RepoAssignment", err) @@ -62,29 +66,69 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Redirect("/") return } - ctx.Handle(200, "RepoAssignment", err) + ctx.Handle(404, "RepoAssignment", err) return } + ctx.Repo.Repository = repo - ctx.Repo.IsValid = true - if ctx.User != nil { + gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) + if err != nil { + ctx.Handle(404, "RepoAssignment Invalid repo", err) + return + } + ctx.Repo.GitRepo = gitRepo + + detect: + if len(branchName) > 0 { + // TODO check tag + if models.IsBranchExist(user.Name, repoName, branchName) { + ctx.Repo.IsBranch = true + ctx.Repo.BranchName = branchName + + ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) + if err != nil { + ctx.Handle(404, "RepoAssignment invalid branch", nil) + return + } + + ctx.Repo.CommitId = ctx.Repo.Commit.Oid.String() + + } else if len(branchName) == 40 { + ctx.Repo.IsCommit = true + ctx.Repo.CommitId = branchName + ctx.Repo.BranchName = branchName + + ctx.Repo.Commit, err = gitRepo.GetCommit(branchName) + if err != nil { + ctx.Handle(404, "RepoAssignment invalid commit", nil) + return + } + } else { + ctx.Handle(404, "RepoAssignment invalid repo", nil) + return + } + + } else { + branchName = "master" + goto detect + } + + if ctx.IsSigned { ctx.Repo.IsWatching = models.IsWatching(ctx.User.Id, repo.Id) } - ctx.Repo.Repository = repo + + ctx.Repo.Owner = user ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) + ctx.Repo.RepoLink = "/" + user.Name + "/" + repo.Name - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - ctx.Data["Branchname"] = params["branchname"] - - ctx.Data["IsRepositoryValid"] = true + ctx.Data["BranchName"] = ctx.Repo.BranchName + ctx.Data["CommitId"] = ctx.Repo.CommitId ctx.Data["Repository"] = repo ctx.Data["Owner"] = user ctx.Data["Title"] = user.Name + "/" + repo.Name ctx.Data["CloneLink"] = ctx.Repo.CloneLink - ctx.Data["RepositoryLink"] = ctx.Data["Title"] + ctx.Data["RepoLink"] = ctx.Repo.RepoLink ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching } From 41ca0ed30212367389099cfefa41587ec80d85f5 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:12:42 +0800 Subject: [PATCH 22/40] remove ctx.Repo.IsValid --- routers/repo/issue.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 3506e90163..b2253e9f48 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -20,10 +20,6 @@ import ( ) func Issues(ctx *middleware.Context) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "issue.Issues(invalid repo):", nil) - } - ctx.Data["Title"] = "Issues" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true @@ -80,10 +76,6 @@ func Issues(ctx *middleware.Context) { } func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "issue.CreateIssue(invalid repo):", nil) - } - ctx.Data["Title"] = "Create issue" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false @@ -126,10 +118,6 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func ViewIssue(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "issue.ViewIssue(invalid repo):", nil) - } - index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.ViewIssue", err) @@ -183,10 +171,6 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { } func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "issue.UpdateIssue(invalid repo):", nil) - } - index, err := base.StrTo(params["index"]).Int() if err != nil { ctx.Handle(404, "issue.UpdateIssue", err) @@ -226,10 +210,6 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } func Comment(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "issue.Comment(invalid repo):", nil) - } - index, err := base.StrTo(ctx.Query("issueIndex")).Int64() if err != nil { ctx.Handle(404, "issue.Comment(get index)", err) From b27c34f39acee3bf7b6594a1f0db2183b343326c Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:13:02 +0800 Subject: [PATCH 23/40] update git api. fix link... and so on --- models/git.go | 26 ++++++++++++++----- models/repo.go | 2 +- routers/repo/branch.go | 10 ++------ routers/repo/commit.go | 18 +++++-------- routers/repo/repo.go | 51 +++++++++---------------------------- templates/issue/create.tmpl | 4 +-- templates/issue/list.tmpl | 12 ++++----- templates/issue/view.tmpl | 4 +-- templates/repo/diff.tmpl | 3 +-- templates/repo/single.tmpl | 4 +-- templates/repo/toolbar.tmpl | 20 +++++++-------- 11 files changed, 63 insertions(+), 91 deletions(-) diff --git a/models/git.go b/models/git.go index 34f0267f65..d3bad6e0ce 100644 --- a/models/git.go +++ b/models/git.go @@ -70,9 +70,12 @@ func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*Rep return nil, err } - commit, err := repo.GetCommit(branchName, commitId) + commit, err := repo.GetCommitOfBranch(branchName) if err != nil { - return nil, err + commit, err = repo.GetCommit(commitId) + if err != nil { + return nil, err + } } parts := strings.Split(path.Clean(rpath), "/") @@ -110,13 +113,22 @@ func GetTargetFile(userName, repoName, branchName, commitId, rpath string) (*Rep } // GetReposFiles returns a list of file object in given directory of repository. -func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*RepoFile, error) { +// func GetReposFilesOfBranch(userName, repoName, branchName, rpath string) ([]*RepoFile, error) { +// return getReposFiles(userName, repoName, commitId, rpath) +// } + +// GetReposFiles returns a list of file object in given directory of repository. +func GetReposFiles(userName, repoName, commitId, rpath string) ([]*RepoFile, error) { + return getReposFiles(userName, repoName, commitId, rpath) +} + +func getReposFiles(userName, repoName, commitId string, rpath string) ([]*RepoFile, error) { repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - commit, err := repo.GetCommit(branchName, commitId) + commit, err := repo.GetCommit(commitId) if err != nil { return nil, err } @@ -216,13 +228,13 @@ func GetReposFiles(userName, repoName, branchName, commitId, rpath string) ([]*R return append(repodirs, repofiles...), nil } -func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, error) { +func GetCommit(userName, repoName, commitId string) (*git.Commit, error) { repo, err := git.OpenRepository(RepoPath(userName, repoName)) if err != nil { return nil, err } - return repo.GetCommit(branchname, commitid) + return repo.GetCommit(commitId) } // GetCommitsByBranch returns all commits of given branch of repository. @@ -397,7 +409,7 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { return nil, err } - commit, err := repo.GetCommit("", commitid) + commit, err := repo.GetCommit(commitid) if err != nil { return nil, err } diff --git a/models/repo.go b/models/repo.go index 0b2bbe4862..4110548362 100644 --- a/models/repo.go +++ b/models/repo.go @@ -364,7 +364,7 @@ func GetRepos(num, offset int) ([]UserRepo, error) { } func RepoPath(userName, repoName string) string { - return filepath.Join(UserPath(userName), repoName+".git") + return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git") } func UpdateRepository(repo *Repository) error { diff --git a/routers/repo/branch.go b/routers/repo/branch.go index aed77cfaa5..c598db436c 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -11,21 +11,15 @@ import ( ) func Branches(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - return - } - - brs, err := models.GetBranches(params["username"], params["reponame"]) + brs, err := models.GetBranches(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) if err != nil { - ctx.Handle(200, "repo.Branches", err) + ctx.Handle(404, "repo.Branches", err) return } else if len(brs) == 0 { ctx.Handle(404, "repo.Branches", nil) return } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true diff --git a/routers/repo/commit.go b/routers/repo/commit.go index afc1ffda29..449f644391 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -50,16 +50,12 @@ func Commits(ctx *middleware.Context, params martini.Params) { } func Diff(ctx *middleware.Context, params martini.Params) { - userName := params["username"] - repoName := params["reponame"] - branchName := params["branchname"] - commitId := params["commitid"] + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name + branchName := ctx.Repo.BranchName + commitId := ctx.Repo.CommitId - commit, err := models.GetCommit(userName, repoName, branchName, commitId) - if err != nil { - ctx.Handle(404, "repo.Diff", err) - return - } + commit := ctx.Repo.Commit diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { @@ -85,11 +81,9 @@ func Diff(ctx *middleware.Context, params martini.Params) { return isImage } - shortSha := params["commitid"][:10] ctx.Data["IsImageFile"] = isImageFile - ctx.Data["Title"] = commit.Message() + " · " + shortSha + ctx.Data["Title"] = commit.Message() + " · " + base.ShortSha(commitId) ctx.Data["Commit"] = commit - ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index b9ac1f1c42..c9c9af1e41 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -53,20 +53,20 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) { } func Single(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - return - } + branchName := ctx.Repo.BranchName + commitId := ctx.Repo.CommitId + userName := ctx.Repo.Owner.Name + repoName := ctx.Repo.Repository.Name - branchName := params["branchname"] - userName := params["username"] - repoName := params["reponame"] + repoLink := ctx.Repo.RepoLink + branchLink := ctx.Repo.RepoLink + "/src/" + branchName + rawLink := ctx.Repo.RepoLink + "/raw/" + branchName // Get tree path treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { - ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + - ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1]) + ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1]) return } @@ -84,23 +84,17 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["Branches"] = brs - var commitId string - isViewBranch := models.IsBranchExist(userName, repoName, branchName) - if !isViewBranch { - commitId = branchName - } + isViewBranch := ctx.Repo.IsBranch ctx.Data["IsViewBranch"] = isViewBranch repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, treename) + if err != nil && err != models.ErrRepoFileNotExist { ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } - branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + branchName - rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + branchName - if len(treename) != 0 && repoFile == nil { ctx.Handle(404, "repo.Single", nil) return @@ -142,8 +136,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { // Directory and file list. - files, err := models.GetReposFiles(userName, repoName, - branchName, commitId, treename) + files, err := models.GetReposFiles(userName, repoName, ctx.Repo.CommitId, treename) if err != nil { ctx.Handle(404, "repo.Single(GetReposFiles)", err) return @@ -200,18 +193,7 @@ func Single(ctx *middleware.Context, params martini.Params) { } } - // Get latest commit according username and repo name. - commit, err := models.GetCommit(userName, repoName, - branchName, commitId) - if err != nil { - log.Error("repo.Single(GetCommit): %v", err) - ctx.Handle(404, "repo.Single(GetCommit)", err) - return - } - ctx.Data["LastCommit"] = commit - - ctx.Data["CommitId"] = commitId - + ctx.Data["LastCommit"] = ctx.Repo.Commit ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["BranchLink"] = branchLink @@ -219,11 +201,6 @@ func Single(ctx *middleware.Context, params martini.Params) { } func SingleDownload(ctx *middleware.Context, params martini.Params) { - if !ctx.Repo.IsValid { - ctx.Handle(404, "repo.SingleDownload", nil) - return - } - // Get tree path treename := params["_1"] @@ -263,10 +240,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { } func Http(ctx *middleware.Context, params martini.Params) { - /*if !ctx.Repo.IsValid { - return - }*/ - // TODO: access check username := params["username"] diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index f5cec0c05a..01784cd21e 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -4,7 +4,7 @@ {{template "repo/toolbar" .}}
    -
    + {{.CsrfTokenHtml}}
    @@ -40,4 +40,4 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 7622a4c172..de25b0e37f 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -6,24 +6,24 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 91e5250ca3..df8b660769 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -64,7 +64,7 @@
    {{if .SignedUser}}
    -
    + {{.CsrfTokenHtml}}
    @@ -102,4 +102,4 @@
    -{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index e58f2d664e..5c95ddefde 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -1,7 +1,6 @@ {{template "base/head" .}} {{template "base/navbar" .}} {{template "repo/nav" .}} -{{template "repo/toolbar" .}}
    @@ -11,7 +10,7 @@
    - commit {{.ShortSha}} + commit {{ShortSha .CommitId}}

    diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 4c9406762c..abaa4e8936 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -11,11 +11,11 @@ {{ $n := len .Treenames}} {{if not .IsFile}}{{end}}

    diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 75f1efdc8e..3c7c8a50e1 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -3,24 +3,24 @@
    From a6e12aaef6344fff43745baa755c6afa11935550 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 10:47:08 -0400 Subject: [PATCH 32/40] Fixing bug --- models/models.go | 25 ++++++++++++++++++++++++- modules/auth/user.go | 4 ++++ routers/install.go | 20 +++++++++++++++----- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/models/models.go b/models/models.go index 825730c5a8..06533e45f9 100644 --- a/models/models.go +++ b/models/models.go @@ -17,7 +17,8 @@ import ( ) var ( - orm *xorm.Engine + orm *xorm.Engine + HasEngine bool DbCfg struct { Type, Host, Name, User, Pwd, Path, SslMode string @@ -34,6 +35,28 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } +func NewTestEngine(x *xorm.Engine) (err error) { + switch DbCfg.Type { + case "mysql": + x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", + DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name)) + case "postgres": + x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", + DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode)) + case "sqlite3": + os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) + x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + default: + return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) + } + if err != nil { + return fmt.Errorf("models.init(fail to conntect database): %v\n", err) + } + + return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch), + new(Action), new(Access), new(Issue), new(Comment)) +} + func SetEngine() (err error) { switch DbCfg.Type { case "mysql": diff --git a/modules/auth/user.go b/modules/auth/user.go index cb8db1b29a..6242a11c18 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -21,6 +21,10 @@ import ( // SignedInId returns the id of signed in user. func SignedInId(session session.SessionStore) int64 { + if !models.HasEngine { + return 0 + } + userId := session.Get("userId") if userId == nil { return 0 diff --git a/routers/install.go b/routers/install.go index 36bba3d41a..20e4241954 100644 --- a/routers/install.go +++ b/routers/install.go @@ -11,6 +11,7 @@ import ( "github.com/Unknwon/goconfig" "github.com/codegangsta/martini" + // "github.com/lunny/xorm" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -38,9 +39,14 @@ func GlobalInit() { models.LoadModelsConfig() models.LoadRepoConfig() models.NewRepoContext() - if err := models.NewEngine(); err != nil && base.InstallLock { - log.Error("%v", err) - os.Exit(2) + + if base.InstallLock { + if err := models.NewEngine(); err != nil { + log.Error("%v", err) + os.Exit(2) + } + + models.HasEngine = true } base.NewServices() checkRunMode() @@ -107,7 +113,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { models.DbCfg.SslMode = form.SslMode models.DbCfg.Path = form.DatabasePath - if err := models.NewEngine(); err != nil { + // ctx.RenderWithErr("Database setting is not correct: ", "install", &form) + // return + log.Trace("00000000000000000000000000000000000000000000") + var x *xorm.Engine + if err := models.NewTestEngine(x); err != nil { if strings.Contains(err.Error(), `unknown driver "sqlite3"`) { ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+ "from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form) @@ -158,7 +168,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("security", "INSTALL_LOCK", "true") - if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { + if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil { ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) return } From 9f91dee53fc602a939abf1219ec6ddb128c2067c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 11:09:59 -0400 Subject: [PATCH 33/40] Bug fix #45 --- models/models.go | 6 +++--- modules/base/conf.go | 4 ++-- routers/install.go | 28 +++++++++++++--------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/models/models.go b/models/models.go index 06533e45f9..be176b5d39 100644 --- a/models/models.go +++ b/models/models.go @@ -43,9 +43,9 @@ func NewTestEngine(x *xorm.Engine) (err error) { case "postgres": x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode)) - case "sqlite3": - os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) - x, err = xorm.NewEngine("sqlite3", DbCfg.Path) + // case "sqlite3": + // os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm) + // x, err = xorm.NewEngine("sqlite3", DbCfg.Path) default: return fmt.Errorf("Unknown database type: %s\n", DbCfg.Type) } diff --git a/modules/base/conf.go b/modules/base/conf.go index f696d083f7..0233d00335 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -253,7 +253,7 @@ func NewConfigContext() { cfgPath := filepath.Join(workDir, "conf/app.ini") Cfg, err = goconfig.LoadConfigFile(cfgPath) if err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) + fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) os.Exit(2) } Cfg.BlockMode = false @@ -261,7 +261,7 @@ func NewConfigContext() { cfgPath = filepath.Join(workDir, "custom/conf/app.ini") if com.IsFile(cfgPath) { if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) + fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err) os.Exit(2) } } diff --git a/routers/install.go b/routers/install.go index 20e4241954..6f29badcfa 100644 --- a/routers/install.go +++ b/routers/install.go @@ -11,7 +11,7 @@ import ( "github.com/Unknwon/goconfig" "github.com/codegangsta/martini" - // "github.com/lunny/xorm" + "github.com/lunny/xorm" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -113,12 +113,10 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { models.DbCfg.SslMode = form.SslMode models.DbCfg.Path = form.DatabasePath - // ctx.RenderWithErr("Database setting is not correct: ", "install", &form) - // return - log.Trace("00000000000000000000000000000000000000000000") + // Set test engine. var x *xorm.Engine if err := models.NewTestEngine(x); err != nil { - if strings.Contains(err.Error(), `unknown driver "sqlite3"`) { + if strings.Contains(err.Error(), `Unknown database type: sqlite3`) { ctx.RenderWithErr("Your release version does not support SQLite3, please download the official binary version "+ "from https://github.com/gogits/gogs/wiki/Install-from-binary, NOT the gobuild version.", "install", &form) } else { @@ -133,15 +131,6 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { return } - // Create admin account. - if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, - IsAdmin: true, IsActive: true}); err != nil { - if err != models.ErrUserAlreadyExist { - ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) - return - } - } - // Save settings. base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type) base.Cfg.SetValue("database", "HOST", models.DbCfg.Host) @@ -168,13 +157,22 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("security", "INSTALL_LOCK", "true") - if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app1.ini"); err != nil { + if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) return } GlobalInit() + // Create admin account. + if _, err := models.RegisterUser(&models.User{Name: form.AdminName, Email: form.AdminEmail, Passwd: form.AdminPasswd, + IsAdmin: true, IsActive: true}); err != nil { + if err != models.ErrUserAlreadyExist { + ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) + return + } + } + log.Info("First-time run install finished!") ctx.Redirect("/user/login") } From 3698431fc11f740ecc043822fba8af895fc12423 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 11:58:21 -0400 Subject: [PATCH 34/40] Fix install bugs --- modules/middleware/auth.go | 5 +++++ routers/install.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index 64f75d75cf..f50fde99e5 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -21,6 +21,11 @@ type ToggleOptions struct { func Toggle(options *ToggleOptions) martini.Handler { return func(ctx *Context) { + if !base.InstallLock { + ctx.Redirect("/install") + return + } + if options.SignOutRequire && ctx.IsSigned && ctx.Req.RequestURI != "/" { ctx.Redirect("/") return diff --git a/routers/install.go b/routers/install.go index 6f29badcfa..cca652f9cf 100644 --- a/routers/install.go +++ b/routers/install.go @@ -131,6 +131,17 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { return } + // Check run user. + curUser := os.Getenv("USERNAME") + if len(curUser) == 0 { + curUser = os.Getenv("USER") + } + // Does not check run user when the install lock is off. + if form.RunUser != curUser { + ctx.RenderWithErr("Run user isn't the current user: "+form.RunUser+" -> "+curUser, "install", &form) + return + } + // Save settings. base.Cfg.SetValue("database", "DB_TYPE", models.DbCfg.Type) base.Cfg.SetValue("database", "HOST", models.DbCfg.Host) @@ -155,8 +166,11 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("service", "ENABLE_NOTIFY_MAIL", base.ToStr(form.MailNotify == "on")) } + base.Cfg.SetValue("", "RUN_MODE", "prod") + base.Cfg.SetValue("security", "INSTALL_LOCK", "true") + os.MkdirAll("custom/conf", os.ModePerm) if err := goconfig.SaveConfigFile(base.Cfg, "custom/conf/app.ini"); err != nil { ctx.RenderWithErr("Fail to save configuration: "+err.Error(), "install", &form) return From d0e6a4c25acc3414f6d0f93cc50e6dcb41111c19 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 12:11:28 -0400 Subject: [PATCH 35/40] Change new martini impot path --- modules/auth/admin.go | 2 +- modules/auth/auth.go | 2 +- modules/auth/issue.go | 2 +- modules/auth/repo.go | 2 +- modules/auth/setting.go | 2 +- modules/auth/user.go | 5 ++--- modules/middleware/auth.go | 2 +- modules/middleware/context.go | 2 +- modules/middleware/logger.go | 2 +- modules/middleware/render.go | 2 +- modules/middleware/repo.go | 2 +- routers/admin/admin.go | 2 +- routers/admin/user.go | 2 +- routers/dev/template.go | 2 +- routers/install.go | 2 +- routers/repo/branch.go | 3 ++- routers/repo/commit.go | 2 +- routers/repo/issue.go | 2 +- routers/repo/pull.go | 2 +- routers/repo/repo.go | 2 +- routers/user/user.go | 2 +- web.go | 2 +- 22 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/auth/admin.go b/modules/auth/admin.go index eccab00718..fe889c2385 100644 --- a/modules/auth/admin.go +++ b/modules/auth/admin.go @@ -8,7 +8,7 @@ import ( "net/http" "reflect" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 361f55b2d3..4561dd831d 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -9,7 +9,7 @@ import ( "reflect" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" diff --git a/modules/auth/issue.go b/modules/auth/issue.go index 8bf49684c6..36c8762791 100644 --- a/modules/auth/issue.go +++ b/modules/auth/issue.go @@ -8,7 +8,7 @@ import ( "net/http" "reflect" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" diff --git a/modules/auth/repo.go b/modules/auth/repo.go index 2cc93744ce..eddd647528 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -8,7 +8,7 @@ import ( "net/http" "reflect" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" diff --git a/modules/auth/setting.go b/modules/auth/setting.go index 0bc6afd4a6..cada7eea66 100644 --- a/modules/auth/setting.go +++ b/modules/auth/setting.go @@ -9,7 +9,7 @@ import ( "reflect" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" diff --git a/modules/auth/user.go b/modules/auth/user.go index 6242a11c18..2d3c29fde1 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -8,11 +8,10 @@ import ( "net/http" "reflect" - "github.com/codegangsta/martini" - - "github.com/gogits/session" + "github.com/go-martini/martini" "github.com/gogits/binding" + "github.com/gogits/session" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go index f50fde99e5..bde3be7269 100644 --- a/modules/middleware/auth.go +++ b/modules/middleware/auth.go @@ -7,7 +7,7 @@ package middleware import ( "net/url" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/modules/base" ) diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 5f1d42b1e4..d2b268cd87 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -15,7 +15,7 @@ import ( "strings" "time" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/cache" "github.com/gogits/git" diff --git a/modules/middleware/logger.go b/modules/middleware/logger.go index dcf8524608..fc8e1a8115 100644 --- a/modules/middleware/logger.go +++ b/modules/middleware/logger.go @@ -11,7 +11,7 @@ import ( "runtime" "time" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" ) var isWindows bool diff --git a/modules/middleware/render.go b/modules/middleware/render.go index 869ef9abaa..98d485afec 100644 --- a/modules/middleware/render.go +++ b/modules/middleware/render.go @@ -17,7 +17,7 @@ import ( "path/filepath" "time" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/modules/base" ) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 6912cd8380..f446d6a85b 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/git" diff --git a/routers/admin/admin.go b/routers/admin/admin.go index f303439fd1..18a43ff817 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" diff --git a/routers/admin/user.go b/routers/admin/user.go index 7f66c5528c..9f043507d1 100644 --- a/routers/admin/user.go +++ b/routers/admin/user.go @@ -7,7 +7,7 @@ package admin import ( "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" diff --git a/routers/dev/template.go b/routers/dev/template.go index d2f77ac4d5..63d5d9a5bb 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -5,7 +5,7 @@ package dev import ( - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" diff --git a/routers/install.go b/routers/install.go index cca652f9cf..2c993c559e 100644 --- a/routers/install.go +++ b/routers/install.go @@ -10,7 +10,7 @@ import ( "strings" "github.com/Unknwon/goconfig" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/lunny/xorm" "github.com/gogits/gogs/models" diff --git a/routers/repo/branch.go b/routers/repo/branch.go index c598db436c..ffd118ae14 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -5,7 +5,8 @@ package repo import ( - "github.com/codegangsta/martini" + "github.com/go-martini/martini" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" ) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 449f644391..d29c40e67e 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -8,7 +8,7 @@ import ( "container/list" "path" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" diff --git a/routers/repo/issue.go b/routers/repo/issue.go index b2253e9f48..f2d8959a04 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -9,7 +9,7 @@ import ( "net/url" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 93b6a9f7cc..430c6a815f 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -5,7 +5,7 @@ package repo import ( - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/modules/middleware" ) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 5b0a165d5c..1cd3dd86ba 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -9,7 +9,7 @@ import ( "path/filepath" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/webdav" diff --git a/routers/user/user.go b/routers/user/user.go index aeaf91c97d..08930e22df 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -9,7 +9,7 @@ import ( "net/url" "strings" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" diff --git a/web.go b/web.go index 6f25271977..412dcb622b 100644 --- a/web.go +++ b/web.go @@ -10,7 +10,7 @@ import ( "net/http" "github.com/codegangsta/cli" - "github.com/codegangsta/martini" + "github.com/go-martini/martini" "github.com/gogits/binding" From 2a0066420a9395e5fa5afcd9be4d094a48eee3fa Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 16:01:50 -0400 Subject: [PATCH 36/40] Fix bug work with sqlite3 --- models/access.go | 2 ++ models/models.go | 6 ++++++ models/repo.go | 2 +- models/user.go | 1 + modules/base/conf.go | 6 +++--- routers/install.go | 1 + serve.go | 19 +++++++++++-------- update.go | 6 ++++++ 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/models/access.go b/models/access.go index 84cad17a3f..42fccae055 100644 --- a/models/access.go +++ b/models/access.go @@ -26,6 +26,8 @@ type Access struct { // AddAccess adds new access record. func AddAccess(access *Access) error { + access.UserName = strings.ToLower(access.UserName) + access.RepoName = strings.ToLower(access.RepoName) _, err := orm.Insert(access) return err } diff --git a/models/models.go b/models/models.go index be176b5d39..a626b98f6e 100644 --- a/models/models.go +++ b/models/models.go @@ -12,6 +12,7 @@ import ( _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" "github.com/lunny/xorm" + // _ "github.com/mattn/go-sqlite3" "github.com/gogits/gogs/modules/base" ) @@ -23,10 +24,15 @@ var ( DbCfg struct { Type, Host, Name, User, Pwd, Path, SslMode string } + + UseSQLite3 bool ) func LoadModelsConfig() { DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") + if DbCfg.Type == "sqlite3" { + UseSQLite3 = true + } DbCfg.Host = base.Cfg.MustValue("database", "HOST") DbCfg.Name = base.Cfg.MustValue("database", "NAME") DbCfg.User = base.Cfg.MustValue("database", "USER") diff --git a/models/repo.go b/models/repo.go index 5ca98dec0c..0c808f1845 100644 --- a/models/repo.go +++ b/models/repo.go @@ -157,7 +157,7 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv } access := Access{ - UserName: user.Name, + UserName: user.LowerName, RepoName: strings.ToLower(path.Join(user.Name, repo.Name)), Mode: AU_WRITABLE, } diff --git a/models/user.go b/models/user.go index a392fa76ba..4908552f29 100644 --- a/models/user.go +++ b/models/user.go @@ -39,6 +39,7 @@ var ( ErrUserNotExist = errors.New("User does not exist") ErrEmailAlreadyUsed = errors.New("E-mail already used") ErrUserNameIllegal = errors.New("User name contains illegal characters") + ErrKeyNotExist = errors.New("Public key does not exist") ) // User represents the object of individual and member of organization. diff --git a/modules/base/conf.go b/modules/base/conf.go index 0233d00335..3ebc4ede18 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -212,9 +212,9 @@ func newMailService() { if Cfg.MustBool("mailer", "ENABLED") { MailService = &Mailer{ Name: Cfg.MustValue("mailer", "NAME", AppName), - Host: Cfg.MustValue("mailer", "HOST", "127.0.0.1:25"), - User: Cfg.MustValue("mailer", "USER", "example@example.com"), - Passwd: Cfg.MustValue("mailer", "PASSWD", "******"), + Host: Cfg.MustValue("mailer", "HOST"), + User: Cfg.MustValue("mailer", "USER"), + Passwd: Cfg.MustValue("mailer", "PASSWD"), } log.Info("Mail Service Enabled") } diff --git a/routers/install.go b/routers/install.go index 2c993c559e..e30c3cfd23 100644 --- a/routers/install.go +++ b/routers/install.go @@ -185,6 +185,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { ctx.RenderWithErr("Admin account setting is invalid: "+err.Error(), "install", &form) return } + log.Info("Admin account already exist") } log.Info("First-time run install finished!") diff --git a/serve.go b/serve.go index dcbddfe4a9..96cd7e73de 100644 --- a/serve.go +++ b/serve.go @@ -74,29 +74,33 @@ func In(b string, sl map[string]int) bool { func runServ(k *cli.Context) { execDir, _ := base.ExecDir() newLogger(execDir) - log.Trace("new serv request " + log.Mode + ":" + log.Config) base.NewConfigContext() models.LoadModelsConfig() + + if models.UseSQLite3 { + os.Chdir(execDir) + } + models.SetEngine() keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { - fmt.Println("auth file format error") + println("auth file format error") log.Error("auth file format error") return } keyId, err := strconv.ParseInt(keys[1], 10, 64) if err != nil { - fmt.Println("auth file format error") + println("auth file format error") log.Error("auth file format error", err) return } user, err := models.GetUserByKeyId(keyId) if err != nil { - fmt.Println("You have no right to access") - log.Error("SSH visit error", err) + println("You have no right to access") + log.Error("SSH visit error: %v", err) return } @@ -133,13 +137,12 @@ func runServ(k *cli.Context) { // access check switch { case isWrite: - has, err := models.HasAccess(user.Name, strings.ToLower(path.Join(repoUserName, repoName)), models.AU_WRITABLE) + has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) if err != nil { println("Inernel error:", err) log.Error(err.Error()) return - } - if !has { + } else if !has { println("You have no right to write this repository") log.Error("User %s has no right to write repository %s", user.Name, repoPath) return diff --git a/update.go b/update.go index 246c5d8f9d..e36dc22329 100644 --- a/update.go +++ b/update.go @@ -32,6 +32,12 @@ gogs serv provide access auth for repositories`, func runUpdate(c *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() + + if models.UseSQLite3 { + execDir, _ := base.ExecDir() + os.Chdir(execDir) + } + models.SetEngine() w, _ := os.Create("update.log") From e938863ae6887f7c3c24145ed3b64dc1d27ee675 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 16:34:23 -0400 Subject: [PATCH 37/40] Mirror fix on UI --- routers/install.go | 2 +- routers/repo/issue.go | 2 +- templates/issue/view.tmpl | 2 +- templates/repo/nav.tmpl | 14 ++++---------- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/routers/install.go b/routers/install.go index e30c3cfd23..28c2d87f71 100644 --- a/routers/install.go +++ b/routers/install.go @@ -156,7 +156,7 @@ func Install(ctx *middleware.Context, form auth.InstallForm) { base.Cfg.SetValue("server", "DOMAIN", form.Domain) base.Cfg.SetValue("server", "ROOT_URL", form.AppUrl) - if len(form.Host) > 0 { + if len(strings.TrimSpace(form.SmtpHost)) > 0 { base.Cfg.SetValue("mailer", "ENABLED", "true") base.Cfg.SetValue("mailer", "HOST", form.SmtpHost) base.Cfg.SetValue("mailer", "USER", form.SmtpEmail) diff --git a/routers/repo/issue.go b/routers/repo/issue.go index f2d8959a04..6cad2c25d2 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -164,7 +164,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.Data["Comments"] = comments - ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || issue.PosterId == ctx.User.Id + ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner || (ctx.IsSigned && issue.PosterId == ctx.User.Id) ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false ctx.HTML(200, "issue/view") diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index df8b660769..e619451cc1 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -14,7 +14,7 @@

    {{if .IsIssueOwner}}Edit - {{end}} + {{end}} {{if .Issue.IsClosed}}Closed{{else}}Open{{end}} {{.Issue.Poster.Name}} opened this issue {{TimeSince .Issue.Created}} · {{.Issue.NumComments}} comments diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index 02096c34c1..6156d5791e 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -7,12 +7,6 @@

    {{if not .IsBareRepo}} -

    Need help cloning? Visit Help!

    -
    +
    @@ -61,9 +55,9 @@
    --> {{end}} -
    +
    From 74ff217c7e8855c5ccf6dbc69cee0823cd65ee1b Mon Sep 17 00:00:00 2001 From: skyblue Date: Mon, 31 Mar 2014 13:30:32 +0800 Subject: [PATCH 38/40] add tests --- .gitignore | 13 ++++--------- tests/.travel.yml | 9 +++++++++ tests/README.md | 14 ++++++++++++++ tests/pyquick/test_index_rest.py | 13 +++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 tests/.travel.yml create mode 100644 tests/README.md create mode 100644 tests/pyquick/test_index_rest.py diff --git a/.gitignore b/.gitignore index cd9109b8db..158421d04a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -<<<<<<< HEAD - - -gogs -*.exe -*.exe~ .DS_Store *.db *.log @@ -14,8 +8,6 @@ data/ *.iml public/img/avatar/ -======= ->>>>>>> b4db9f67548a41922f1b337daf9c9d2b975b55c4 # Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a @@ -37,4 +29,7 @@ _cgo_export.* _testmain.go -*.exe \ No newline at end of file +*.exe +*.exe~ +gogs +__pycache__ diff --git a/tests/.travel.yml b/tests/.travel.yml new file mode 100644 index 0000000000..820621b283 --- /dev/null +++ b/tests/.travel.yml @@ -0,0 +1,9 @@ +command: python -m pytest {} +include: ^test_.*\.py$ +path: ./ +depth: 1 +verbose: true +timeout: 1m +reload: false +html: test.html +notify: [] diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000000..aba7d388e5 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,14 @@ +## gogs test + +this is for developers + +## prepare environment + # install python dependency + pip install pytest + # install basic test tool + go get -u github.com/shxsun/travelexec + # start gogs server + gogs web + +## start test + travelexec diff --git a/tests/pyquick/test_index_rest.py b/tests/pyquick/test_index_rest.py new file mode 100644 index 0000000000..be0bf18300 --- /dev/null +++ b/tests/pyquick/test_index_rest.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# coding: utf-8 +# +# + +import requests + +HOST = 'http://localhost:3000' + +def test_index_get(): + r = requests.get(HOST + '/') + assert r.status_code == 200 + From 587e6d80890f9e679b13a1511dab6635fd520775 Mon Sep 17 00:00:00 2001 From: skyblue Date: Mon, 31 Mar 2014 15:54:15 +0800 Subject: [PATCH 39/40] add start.sh+bat --- .gobuild.yml | 4 +++- start.bat | 2 ++ start.sh | 6 ++++++ web.go | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 start.bat create mode 100755 start.sh diff --git a/.gobuild.yml b/.gobuild.yml index 78a38f2d31..d5bc6606c1 100644 --- a/.gobuild.yml +++ b/.gobuild.yml @@ -5,4 +5,6 @@ filesets: - conf - LICENSE - README.md - - README_ZH.md \ No newline at end of file + - README_ZH.md + - start.bat + - start.sh diff --git a/start.bat b/start.bat new file mode 100644 index 0000000000..02972b92da --- /dev/null +++ b/start.bat @@ -0,0 +1,2 @@ +@echo off +gogs.exe web diff --git a/start.sh b/start.sh new file mode 100755 index 0000000000..331d340cda --- /dev/null +++ b/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash - +# +# start gogs web +# +cd "$(dirname $0)" +./gogs web diff --git a/web.go b/web.go index 412dcb622b..cdec9232a9 100644 --- a/web.go +++ b/web.go @@ -160,6 +160,7 @@ func runWeb(*cli.Context) { base.Cfg.MustValue("server", "HTTP_PORT", "3000")) log.Info("Listen: %s", listenAddr) if err := http.ListenAndServe(listenAddr, m); err != nil { - log.Critical(err.Error()) + fmt.Println(err.Error()) + //log.Critical(err.Error()) // not working now } } From 9acc1c33be76b05231ec3a5a222af02484689974 Mon Sep 17 00:00:00 2001 From: skyblue Date: Mon, 31 Mar 2014 16:24:58 +0800 Subject: [PATCH 40/40] add go functest --- tests/.travel.yml | 4 ++-- tests/README.md | 3 --- tests/default_test.go | 17 +++++++++++++++++ tests/pyquick/test_index_rest.py | 13 ------------- 4 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 tests/default_test.go delete mode 100644 tests/pyquick/test_index_rest.py diff --git a/tests/.travel.yml b/tests/.travel.yml index 820621b283..09a5752bfb 100644 --- a/tests/.travel.yml +++ b/tests/.travel.yml @@ -1,5 +1,5 @@ -command: python -m pytest {} -include: ^test_.*\.py$ +command: go test -v {} +include: ^.+_test\.go$ path: ./ depth: 1 verbose: true diff --git a/tests/README.md b/tests/README.md index aba7d388e5..98693257f2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,9 +3,6 @@ this is for developers ## prepare environment - # install python dependency - pip install pytest - # install basic test tool go get -u github.com/shxsun/travelexec # start gogs server gogs web diff --git a/tests/default_test.go b/tests/default_test.go new file mode 100644 index 0000000000..d6f3a03be6 --- /dev/null +++ b/tests/default_test.go @@ -0,0 +1,17 @@ +package test + +import ( + "net/http" + "testing" +) + +func TestMain(t *testing.T) { + r, err := http.Get("http://localhost:3000/") + if err != nil { + t.Fatal(err) + } + defer r.Body.Close() + if r.StatusCode != http.StatusOK { + t.Error(r.StatusCode) + } +} diff --git a/tests/pyquick/test_index_rest.py b/tests/pyquick/test_index_rest.py deleted file mode 100644 index be0bf18300..0000000000 --- a/tests/pyquick/test_index_rest.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 -# -# - -import requests - -HOST = 'http://localhost:3000' - -def test_index_get(): - r = requests.get(HOST + '/') - assert r.status_code == 200 -