From a726c125b572bc1ff0b445990821280e304db9ff Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 19:29:52 +0800 Subject: Add PushCommit --- update.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'update.go') diff --git a/update.go b/update.go index faec0029..9743dcc4 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 } -- cgit v1.2.3 From ec1b801732b030648c060d26ce5a3ed8cf2e822c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 29 Mar 2014 19:59:02 +0800 Subject: bug fixed --- models/action.go | 4 ++-- update.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'update.go') diff --git a/models/action.go b/models/action.go index 89485578..1e55df85 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 9743dcc4..246c5d8f 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) } -- cgit v1.2.3 From 2a0066420a9395e5fa5afcd9be4d094a48eee3fa Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 30 Mar 2014 16:01:50 -0400 Subject: 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(-) (limited to 'update.go') diff --git a/models/access.go b/models/access.go index 84cad17a..42fccae0 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 be176b5d..a626b98f 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 5ca98dec..0c808f18 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 a392fa76..4908552f 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 0233d003..3ebc4ede 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 2c993c55..e30c3cfd 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 dcbddfe4..96cd7e73 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 246c5d8f..e36dc223 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") -- cgit v1.2.3