diff options
author | Meaglith Ma <genedna@gmail.com> | 2014-03-31 17:23:37 +0800 |
---|---|---|
committer | Meaglith Ma <genedna@gmail.com> | 2014-03-31 17:23:37 +0800 |
commit | 1a247340dbea3404431f60a24bb8f8d06d94b1e9 (patch) | |
tree | 80d3ecab43506e03405c742a84dcc61f474e2212 /modules/base | |
parent | 9047cadcd33f95eebafa2f794b895c8406eb80c5 (diff) | |
parent | dd9fb807a46db120ef800d7465f50a73a86df288 (diff) |
Merge pull request #1 from gogits/master
Sync to lastest
Diffstat (limited to 'modules/base')
-rw-r--r-- | modules/base/conf.go | 26 | ||||
-rw-r--r-- | modules/base/template.go | 8 | ||||
-rw-r--r-- | modules/base/tool.go | 17 |
3 files changed, 37 insertions, 14 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go index b3a987e6..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") } @@ -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) } } @@ -272,18 +272,19 @@ func NewConfigContext() { Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") + InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) + RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") if len(curUser) == 0 { curUser = os.Getenv("USER") } - if RunUser != curUser { + // Does not check run user when the install lock is off. + if InstallLock && RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) os.Exit(2) } - InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) - LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME") CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME") @@ -291,9 +292,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/modules/base/template.go b/modules/base/template.go index dca76faf..dfcae931 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, } diff --git a/modules/base/tool.go b/modules/base/tool.go index 9ddb90f7..6876da76 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 @@ -506,15 +507,23 @@ const ( <div><img src="%s?s=16" alt="user-avatar"/> %s</div>` ) +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 // 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() @@ -529,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[0], commit[0][:7], commit[1]) + "\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(`<div><a href="/%s/%s/commits/%s">%d other commits >></a></div>`, actUserName, repoName, branch, push.Len)) @@ -539,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" } |