From 7048ea45279cd96f88845d83fe7cef6fbb545fcf Mon Sep 17 00:00:00 2001 From: skyblue Date: Tue, 25 Mar 2014 18:34:57 +0800 Subject: update avatar, remove gzip request header --- modules/avatar/avatar.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 0ba20294..3b423a6d 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -251,8 +251,8 @@ var client = &http.Client{} func (this *thunderTask) fetch() error { req, _ := http.NewRequest("GET", this.Url, nil) - req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") - req.Header.Set("Accept-Encoding", "gzip,deflate,sdch") + req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jpeg,image/png,*/*;q=0.8") + req.Header.Set("Accept-Encoding", "deflate,sdch") req.Header.Set("Accept-Language", "zh-CN,zh;q=0.8") req.Header.Set("Cache-Control", "no-cache") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36") -- cgit v1.2.3 From eeb793524f2da4afdca017b585d9cfb6e9628e85 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 06:52:56 -0400 Subject: Check run user --- conf/app.ini | 4 ++-- gogs.go | 15 --------------- modules/base/conf.go | 21 +++++++++++---------- templates/user/delete.tmpl | 4 ++-- 4 files changed, 15 insertions(+), 29 deletions(-) (limited to 'modules') diff --git a/conf/app.ini b/conf/app.ini index 809ea61c..4c2398dd 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,8 +1,8 @@ ; App name that shows on every page title APP_NAME = Gogs: Go Git Service APP_LOGO = img/favicon.png -; !!MUST CHANGE TO YOUR USER NAME!! -RUN_USER = lunny +; Check it if you run locally +RUN_USER = git ; Either "dev", "prod" or "test", default is "dev" RUN_MODE = dev diff --git a/gogs.go b/gogs.go index 93b7231b..7ac699cc 100644 --- a/gogs.go +++ b/gogs.go @@ -7,7 +7,6 @@ package main import ( "os" - // "os/user" "runtime" "github.com/codegangsta/cli" @@ -27,21 +26,7 @@ func init() { runtime.GOMAXPROCS(runtime.NumCPU()) } -// func checkRunUser() bool { -// u, err := user.Current() -// if err != nil { -// // TODO: log -// return false -// } -// return u.Username == base.Cfg.MustValue("", "RUN_USER") -// } - func main() { - /*if !checkRunUser() { - println("The command should be run as", base.Cfg.MustValue("", "RUN_USER")) - return - }*/ - app := cli.NewApp() app.Name = "Gogs" app.Usage = "Go Git Service" diff --git a/modules/base/conf.go b/modules/base/conf.go index d3122a53..c692ddc2 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -259,16 +259,11 @@ func NewConfigContext() { Cfg.BlockMode = false cfgPath = filepath.Join(workDir, "custom/conf/app.ini") - if !com.IsFile(cfgPath) { - fmt.Println("Custom configuration not found(custom/conf/app.ini)\n" + - "Please create it and make your own configuration!") - os.Exit(2) - - } - - if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) - os.Exit(2) + if com.IsFile(cfgPath) { + if err = Cfg.AppendFiles(cfgPath); err != nil { + fmt.Printf("Cannot load config file '%s'\n", cfgPath) + os.Exit(2) + } } AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service") @@ -276,7 +271,13 @@ func NewConfigContext() { AppUrl = Cfg.MustValue("server", "ROOT_URL") Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") + RunUser = Cfg.MustValue("", "RUN_USER") + curUser := os.Getenv("USERNAME") + if RunUser != curUser { + fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) + os.Exit(2) + } EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) diff --git a/templates/user/delete.tmpl b/templates/user/delete.tmpl index 46376672..04c713eb 100644 --- a/templates/user/delete.tmpl +++ b/templates/user/delete.tmpl @@ -6,9 +6,9 @@ -- cgit v1.2.3 From be69e74bc05b62deb6a5f9ae360af220cd5d5226 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:06:56 -0400 Subject: Mirror fix --- modules/base/conf.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules') diff --git a/modules/base/conf.go b/modules/base/conf.go index d0f8ae2c..3eb01bdd 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -274,6 +274,9 @@ func NewConfigContext() { RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") + if len(curUser) == 0 { + curUser = os.Getenv("whoami") + } if RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) os.Exit(2) -- cgit v1.2.3 From 7aa0a97d10a6810ab0b6fb482c7f8f179431104f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:10:23 -0400 Subject: Mirror fix --- modules/base/conf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/base/conf.go b/modules/base/conf.go index 3eb01bdd..1661681e 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -275,7 +275,7 @@ func NewConfigContext() { RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") if len(curUser) == 0 { - curUser = os.Getenv("whoami") + curUser = os.Getenv("USER") } if RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) -- cgit v1.2.3 From 4f6889bef2bea9992330860e8605d5d0d06df23f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:47:04 -0400 Subject: Add more log to locate issue --- modules/log/log.go | 6 +++++- serve.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/log/log.go b/modules/log/log.go index 0c07c7c6..e1bab8ae 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -9,7 +9,10 @@ import ( "github.com/gogits/logs" ) -var logger *logs.BeeLogger +var ( + logger *logs.BeeLogger + Mode, Config string +) func init() { logger = logs.NewLogger(10000) @@ -17,6 +20,7 @@ func init() { } func NewLogger(bufLen int64, mode, config string) { + Mode, Config = mode, config logger = logs.NewLogger(bufLen) logger.SetLogger(mode, config) } diff --git a/serve.go b/serve.go index a4d5a727..35adcaca 100644 --- a/serve.go +++ b/serve.go @@ -73,6 +73,7 @@ func In(b string, sl map[string]int) bool { } func runServ(k *cli.Context) { + fmt.Println("new serv request", log.Mode, log.Config) log.Trace("new serv request") base.NewConfigContext() -- cgit v1.2.3 From 197c4d4a5ba8a9540c49879324194f5f6be4689c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 08:53:11 -0400 Subject: Fix wrong serve command log location and commit repo action --- models/action.go | 6 ++++-- modules/base/conf.go | 4 ++-- modules/middleware/repo.go | 2 +- serve.go | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/models/action.go b/models/action.go index 44d7aea8..dffc0e53 100644 --- a/models/action.go +++ b/models/action.go @@ -59,7 +59,7 @@ func (a Action) GetContent() string { // CommitRepoAction records action for commit repository. func CommitRepoAction(userId int64, userName string, repoId int64, repoName string, refName string, commits *base.PushCommits) error { - log.Trace("action.CommitRepoAction: %d/%s", userId, repoName) + log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) bs, err := json.Marshal(commits) if err != nil { @@ -92,8 +92,8 @@ func CommitRepoAction(userId int64, userName string, }) if err != nil { log.Error("action.CommitRepoAction(notify watches): %d/%s", userId, repoName) + return err } - return err } // Update repository last update time. @@ -107,6 +107,8 @@ func CommitRepoAction(userId int64, userName string, log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName) return err } + + log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName) return nil } diff --git a/modules/base/conf.go b/modules/base/conf.go index 1661681e..0fb1ccdc 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -71,7 +71,7 @@ var Service struct { ResetPwdCodeLives int } -func exeDir() (string, error) { +func ExecDir() (string, error) { file, err := exec.LookPath(os.Args[0]) if err != nil { return "", err @@ -244,7 +244,7 @@ func newNotifyMailService() { func NewConfigContext() { //var err error - workDir, err := exeDir() + workDir, err := ExecDir() if err != nil { fmt.Printf("Fail to get work directory: %s\n", err) os.Exit(2) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index eea2570c..b23bccb1 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -73,7 +73,7 @@ func RepoAssignment(redirect bool) martini.Handler { if base.EnableHttpsClone { scheme = "https" } - ctx.Repo.CloneLink.SSH = fmt.Sprintf("git@%s:%s/%s.git", base.Domain, user.LowerName, repo.LowerName) + 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/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) ctx.Data["IsRepositoryValid"] = true diff --git a/serve.go b/serve.go index 89ef0d84..7e21fcae 100644 --- a/serve.go +++ b/serve.go @@ -45,10 +45,10 @@ gogs serv provide access auth for repositories`, Flags: []cli.Flag{}, } -func init() { +func newLogger(execDir string) { level := "0" os.MkdirAll("log", os.ModePerm) - log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log")) + log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, execDir+"/log/serv.log")) log.Trace("start logging...") } @@ -73,6 +73,8 @@ 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() -- cgit v1.2.3 From 2fa8d0c8dd43f95e1659a266e84c7713cc8f2fcf Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 12:12:27 -0400 Subject: Added create issue --- gogs.go | 2 +- modules/auth/issue.go | 9 +++---- modules/avatar/avatar.go | 3 ++- modules/base/tool.go | 5 +++- modules/middleware/repo.go | 5 ++++ routers/repo/branch.go | 5 ---- routers/repo/issue.go | 11 +++----- routers/repo/pull.go | 5 ---- routers/repo/repo.go | 14 ----------- serve.go | 5 ++-- templates/issue/create.tmpl | 9 ++++--- templates/issue/list.tmpl | 61 +++++++++++++++++++++++++++++++++++++++++++++ templates/issue/repo.tmpl | 56 ----------------------------------------- templates/repo/nav.tmpl | 2 +- web.go | 6 ++--- 15 files changed, 90 insertions(+), 108 deletions(-) create mode 100644 templates/issue/list.tmpl delete mode 100644 templates/issue/repo.tmpl (limited to 'modules') diff --git a/gogs.go b/gogs.go index 7ac699cc..b62580f8 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.7.0324" +const APP_VER = "0.1.7.0325" func init() { base.AppVer = APP_VER diff --git a/modules/auth/issue.go b/modules/auth/issue.go index e2b1f9f2..8bf49684 100644 --- a/modules/auth/issue.go +++ b/modules/auth/issue.go @@ -17,9 +17,8 @@ import ( ) type CreateIssueForm struct { - IssueName string `form:"name" binding:"Required;MaxSize(50)"` - RepoId int64 `form:"repoid" binding:"Required"` - MilestoneId int64 `form:"milestoneid" binding:"Required"` + IssueName string `form:"title" binding:"Required;MaxSize(50)"` + MilestoneId int64 `form:"milestoneid"` AssigneeId int64 `form:"assigneeid"` Labels string `form:"labels"` Content string `form:"content"` @@ -27,9 +26,7 @@ type CreateIssueForm struct { func (f *CreateIssueForm) Name(field string) string { names := map[string]string{ - "IssueName": "Issue name", - "RepoId": "Repository ID", - "MilestoneId": "Milestone ID", + "IssueName": "Issue name", } return names[field] } diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 3b423a6d..449c9656 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -30,8 +30,9 @@ import ( "sync" "time" - "github.com/gogits/gogs/modules/log" "github.com/nfnt/resize" + + "github.com/gogits/gogs/modules/log" ) var ( diff --git a/modules/base/tool.go b/modules/base/tool.go index 0dec7aa8..c23f5de6 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -102,7 +102,10 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string // AvatarLink returns avatar link by given e-mail. func AvatarLink(email string) string { - return "/avatar/" + EncodeMd5(email) + if Service.EnableCacheAvatar { + return "/avatar/" + EncodeMd5(email) + } + return "http://1.gravatar.com/avatar/" + EncodeMd5(email) } // Seconds-based time units diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index b23bccb1..bc90c05c 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -76,6 +76,11 @@ func RepoAssignment(redirect bool) martini.Handler { 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/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) + if len(params["branchname"]) == 0 { + params["branchname"] = "master" + } + ctx.Data["Branchname"] = params["branchname"] + ctx.Data["IsRepositoryValid"] = true ctx.Data["Repository"] = repo ctx.Data["Owner"] = user diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 8c953f2e..aed77cfa 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -26,11 +26,6 @@ func Branches(ctx *middleware.Context, params martini.Params) { ctx.Data["Username"] = params["username"] ctx.Data["Reponame"] = params["reponame"] - - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - ctx.Data["Branchname"] = params["branchname"] ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true diff --git a/routers/repo/issue.go b/routers/repo/issue.go index ab070d72..4e832460 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -30,12 +30,7 @@ func Issues(ctx *middleware.Context, params martini.Params) { ctx.Handle(200, "issue.Issues: %v", err) return } - - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - ctx.Data["Branchname"] = params["branchname"] - ctx.HTML(200, "issue/repo") + ctx.HTML(200, "issue/list") } func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { @@ -57,10 +52,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } - issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId, + issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId, form.IssueName, form.Labels, form.Content, false) if err == nil { - log.Trace("%s Issue created: %d", form.RepoId, issue.Id) + log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) return } diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 16c60389..93b6a9f7 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -12,10 +12,5 @@ import ( func Pulls(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarPulls"] = true - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - - ctx.Data["Branchname"] = params["branchname"] ctx.HTML(200, "repo/pulls") } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index cd28d52c..acf025a2 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -57,10 +57,6 @@ func Single(ctx *middleware.Context, params martini.Params) { return } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - // Get tree path treename := params["_1"] @@ -177,7 +173,6 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Username"] = params["username"] ctx.Data["Reponame"] = params["reponame"] - ctx.Data["Branchname"] = params["branchname"] var treenames []string Paths := make([]string, 0) @@ -216,10 +211,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { return } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - // Get tree path treename := params["_1"] @@ -290,11 +281,6 @@ func Setting(ctx *middleware.Context, params martini.Params) { title = t } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - - ctx.Data["Branchname"] = params["branchname"] ctx.Data["Title"] = title + " - settings" ctx.HTML(200, "repo/setting") } diff --git a/serve.go b/serve.go index bfd2663f..25a34efb 100644 --- a/serve.go +++ b/serve.go @@ -249,8 +249,8 @@ func runServ(k *cli.Context) { } } if refname == "" { - println("No find any reference name:", b.String()) - log.Error("No find any reference name: " + b.String()) + println("Not found any reference name:", b.String()) + log.Error("Not found any reference name: " + b.String()) return } @@ -267,7 +267,6 @@ func runServ(k *cli.Context) { return } if ref, ok = refs[refname]; !ok { - log.Error("unknow reference name -", refname, "-", b.String()) log.Error("unknow reference name -", refname, "-", b.String()) return } diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index 34c7f40a..cbc21f6c 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -4,13 +4,14 @@ {{template "repo/toolbar" .}}
-
+ + {{.CsrfTokenHtml}}
- +
- +
@@ -23,7 +24,7 @@
- +
preview
diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl new file mode 100644 index 00000000..685eaeeb --- /dev/null +++ b/templates/issue/list.tmpl @@ -0,0 +1,61 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
+
+ +
+
+ +
+
+ {{range .Issues}} +
+ {{end}} +
+ +
+
+
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/issue/repo.tmpl b/templates/issue/repo.tmpl deleted file mode 100644 index c348f27f..00000000 --- a/templates/issue/repo.tmpl +++ /dev/null @@ -1,56 +0,0 @@ -{{template "base/head" .}} -{{template "base/navbar" .}} -{{template "repo/nav" .}} -{{template "repo/toolbar" .}} - -{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl index e1b22b1c..02096c34 100644 --- a/templates/repo/nav.tmpl +++ b/templates/repo/nav.tmpl @@ -2,7 +2,7 @@
-

{{.Owner.Name}} / {{.Repository.Name}}

+

{{.Owner.Name}} / {{.Repository.Name}}

{{.Repository.Description}}{{if .Repository.Website}} {{.Repository.Website}}{{end}}

diff --git a/web.go b/web.go index 6538c61f..9b7b2163 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.Get("/install", routers.Install) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) @@ -142,13 +142,13 @@ func runWeb(*cli.Context) { r.Post("/settings", repo.SettingPost) r.Get("/settings", repo.Setting) r.Get("/action/:action", repo.Action) + r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue) + r.Post("/issues/:index", binding.BindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) }, reqSignIn, middleware.RepoAssignment(true)) m.Group("/:username/:reponame", func(r martini.Router) { r.Get("/commits/:branchname", repo.Commits) r.Get("/issues", repo.Issues) - r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue) r.Get("/issues/:index", repo.ViewIssue) - r.Post("/issues/:index", binding.BindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) r.Get("/pulls", repo.Pulls) r.Get("/branches", repo.Branches) r.Get("/src/:branchname", repo.Single) -- cgit v1.2.3 From d3b8e9daa1a22501c03564f2739f9fa8198fbdf1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 14:04:57 -0400 Subject: Add notify watcher action --- README.md | 2 +- README_ZH.md | 2 +- models/action.go | 29 ++----------------- models/issue.go | 1 + models/repo.go | 71 ++++++++++++++++++++++++++++++++++------------- modules/base/tool.go | 21 ++++++++++---- routers/repo/issue.go | 40 ++++++++++++++++++++++---- templates/issue/list.tmpl | 46 ++++++++---------------------- 8 files changed, 118 insertions(+), 94 deletions(-) (limited to 'modules') diff --git a/README.md b/README.md index a39a92a3..d99031c6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o - Create/delete/watch public repository. - User profile page. - Repository viewer. -- Gravatar support. +- Gravatar and cache support. - Mail service(register). - Administration panel. - Supports MySQL, PostgreSQL and SQLite3(binary release only). diff --git a/README_ZH.md b/README_ZH.md index 440f952f..0a4d3bdc 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -28,7 +28,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 - 创建/删除/关注公开仓库 - 用户个人信息页面 - 仓库浏览器 -- Gravatar 支持 +- Gravatar 以及缓存支持 - 邮件服务(注册) - 管理员面板 - 支持 MySQL、PostgreSQL 以及 SQLite3(仅限二进制版本) diff --git a/models/action.go b/models/action.go index dffc0e53..edf1bf58 100644 --- a/models/action.go +++ b/models/action.go @@ -19,6 +19,7 @@ const ( OP_STAR_REPO OP_FOLLOW_REPO OP_COMMIT_REPO + OP_CREATE_ISSUE OP_PULL_REQUEST ) @@ -67,34 +68,10 @@ func CommitRepoAction(userId int64, userName string, return err } - // Add feeds for user self and all watchers. - watches, err := GetWatches(repoId) - if err != nil { - log.Error("action.CommitRepoAction(get watches): %d/%s", userId, repoName) + if err = NotifyWatchers(userId, repoId, OP_COMMIT_REPO, userName, repoName, refName, string(bs)); err != nil { + log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } - watches = append(watches, Watch{UserId: userId}) - - for i := range watches { - if userId == watches[i].UserId && i > 0 { - continue // Do not add twice in case author watches his/her repository. - } - - _, err = orm.InsertOne(&Action{ - UserId: watches[i].UserId, - ActUserId: userId, - ActUserName: userName, - OpType: OP_COMMIT_REPO, - Content: string(bs), - RepoId: repoId, - RepoName: repoName, - RefName: refName, - }) - if err != nil { - log.Error("action.CommitRepoAction(notify watches): %d/%s", userId, repoName) - return err - } - } // Update repository last update time. repo, err := GetRepositoryByName(userId, repoName) diff --git a/models/issue.go b/models/issue.go index fe43a94b..2bdd083d 100644 --- a/models/issue.go +++ b/models/issue.go @@ -23,6 +23,7 @@ type Issue struct { Name string RepoId int64 `xorm:"index"` PosterId int64 + Poster *User `xorm:"-"` MilestoneId int64 AssigneeId int64 IsPull bool // Indicates whether is a pull request or not. diff --git a/models/repo.go b/models/repo.go index d5f9be72..824d5ba0 100644 --- a/models/repo.go +++ b/models/repo.go @@ -262,27 +262,27 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } /* - // hook/post-update - pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu.Close() - // TODO: Windows .bat - if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update\n", appPath)); err != nil { - return err - } + // hook/post-update + pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu.Close() + // TODO: Windows .bat + if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update\n", appPath)); err != nil { + return err + } - // hook/post-update - pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu2.Close() - // TODO: Windows .bat - if _, err = pu2.WriteString("#!/usr/bin/env bash\ngit update-server-info\n"); err != nil { - return err - } + // hook/post-update + pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu2.Close() + // TODO: Windows .bat + if _, err = pu2.WriteString("#!/usr/bin/env bash\ngit update-server-info\n"); err != nil { + return err + } */ // Initialize repository according to user's choice. @@ -506,6 +506,37 @@ func GetWatches(repoId int64) ([]Watch, error) { return watches, err } +// NotifyWatchers creates batch of actions for every watcher. +func NotifyWatchers(userId, repoId int64, opType int, userName, repoName, refName, content string) error { + // Add feeds for user self and all watchers. + watches, err := GetWatches(repoId) + if err != nil { + return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) + } + watches = append(watches, Watch{UserId: userId}) + + for i := range watches { + if userId == watches[i].UserId && i > 0 { + continue // Do not add twice in case author watches his/her repository. + } + + _, err = orm.InsertOne(&Action{ + UserId: watches[i].UserId, + ActUserId: userId, + ActUserName: userName, + OpType: opType, + Content: content, + RepoId: repoId, + RepoName: repoName, + RefName: refName, + }) + if err != nil { + return errors.New("repo.NotifyWatchers(create action): " + err.Error()) + } + } + return nil +} + // IsWatching checks if user has watched given repository. func IsWatching(userId, repoId int64) bool { has, _ := orm.Get(&Watch{0, repoId, userId}) diff --git a/modules/base/tool.go b/modules/base/tool.go index c23f5de6..8f38d492 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -486,15 +486,19 @@ func ActionIcon(opType int) string { return "plus-circle" case 5: // Commit repository. return "arrow-circle-o-right" + case 6: // Create issue. + return "exclamation-circle" default: return "invalid type" } } const ( - TPL_CREATE_REPO = `%s created repository %s` - TPL_COMMIT_REPO = `%s pushed to %s at %s/%s%s` - TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s%s` + TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` + TPL_CREATE_Issue = `%s opened issue %s#%s +
user-avatar %s
` ) type PushCommits struct { @@ -507,11 +511,12 @@ type PushCommits struct { func ActionDesc(act Actioner, avatarLink string) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() + repoLink := actUserName + "/" + repoName branch := act.GetBranch() content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName) case 5: // Commit repository. var push *PushCommits if err := json.Unmarshal([]byte(content), &push); err != nil { @@ -519,13 +524,17 @@ 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, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit[0], commit[0][:7], commit[1]) + "\n") } if push.Len > 3 { buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len)) } - return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, branch, branch, actUserName, repoName, actUserName, repoName, + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, buf.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]) default: return "invalid type" } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 4e832460..fc5bb986 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -23,13 +23,33 @@ func Issues(ctx *middleware.Context, params martini.Params) { milestoneId, _ := base.StrTo(params["milestone"]).Int() page, _ := base.StrTo(params["page"]).Int() - var err error - ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0, + // Get issues. + issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0, int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"]) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return } + + var closedCount int + // Get posters. + for i := range issues { + u, err := models.GetUserById(issues[i].PosterId) + if err != nil { + ctx.Handle(200, "issue.Issues(get poster): %v", err) + return + } + + if issues[i].IsClosed { + closedCount++ + } + issues[i].Poster = u + } + + ctx.Data["Issues"] = issues + ctx.Data["IssueCount"] = len(issues) + ctx.Data["OpenCount"] = len(issues) - closedCount + ctx.Data["ClosedCount"] = closedCount ctx.HTML(200, "issue/list") } @@ -54,12 +74,20 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId, form.IssueName, form.Labels, form.Content, false) - if err == nil { - log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) - ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) + if err != nil { + ctx.Handle(200, "issue.CreateIssue", err) return } - ctx.Handle(200, "issue.CreateIssue", err) + + // Notify watchers. + if err = models.NotifyWatchers(ctx.User.Id, ctx.Repo.Repository.Id, models.OP_CREATE_ISSUE, + ctx.User.Name, ctx.Repo.Repository.Name, "", fmt.Sprintf("%d|%s", issue.Index, issue.Name)); err != nil { + ctx.Handle(200, "issue.CreateIssue", err) + return + } + + log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) } func ViewIssue(ctx *middleware.Context, params martini.Params) { diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl index 685eaeeb..0df68838 100644 --- a/templates/issue/list.tmpl +++ b/templates/issue/list.tmpl @@ -6,7 +6,7 @@
@@ -14,46 +14,24 @@
{{range .Issues}} -
- {{end}} -
-
- -
- #123 -
Bug: When running tests after generating a beego app, templates do not load.
+
+ #{{.Index}} +
{{.Name}}

- - Obama - 3 days ago - 3 -

-
-
- #123 -
Bug: When running tests after generating a beego app, templates do not load.
-

- - Obama - 3 days ago - 3 + + {{.Poster.Name}} + {{TimeSince .Created}} + {{.NumComments}}

+ {{end}} +
-- cgit v1.2.3 From c1a3d4fefbbbf332cd1cedda66e93bf40cc9713d Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 21:37:18 -0400 Subject: Add mail notify for creating issue --- gogs.go | 2 +- models/issue.go | 1 - modules/mailer/mail.go | 40 ++++++++++++++++++++++++++++++++++++++-- modules/mailer/mailer.go | 2 +- routers/repo/issue.go | 9 +++++++++ 5 files changed, 49 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/gogs.go b/gogs.go index b62580f8..f5a328ad 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.7.0325" +const APP_VER = "0.1.8.0325" func init() { base.AppVer = APP_VER diff --git a/models/issue.go b/models/issue.go index 2bdd083d..2de65685 100644 --- a/models/issue.go +++ b/models/issue.go @@ -59,7 +59,6 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co Content: content, } _, err = orm.Insert(issue) - // TODO: newIssueAction return issue, err } diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index 92acd20e..d0decbe0 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -6,6 +6,7 @@ package mailer import ( "encoding/hex" + "errors" "fmt" "github.com/gogits/gogs/models" @@ -15,12 +16,17 @@ import ( ) // Create New mail message use MailFrom and MailUser -func NewMailMessage(To []string, subject, body string) Message { - msg := NewHtmlMessage(To, base.MailService.User, subject, body) +func NewMailMessageFrom(To []string, from, subject, body string) Message { + msg := NewHtmlMessage(To, from, subject, body) msg.User = base.MailService.User return msg } +// Create New mail message use MailFrom and MailUser +func NewMailMessage(To []string, subject, body string) Message { + return NewMailMessageFrom(To, base.MailService.User, subject, body) +} + func GetMailTmplData(user *models.User) map[interface{}]interface{} { data := make(map[interface{}]interface{}, 10) data["AppName"] = base.AppName @@ -84,3 +90,33 @@ func SendActiveMail(r *middleware.Render, user *models.User) { SendAsync(&msg) } + +// SendNotifyMail sends mail notification of all watchers. +func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { + watches, err := models.GetWatches(repoId) + if err != nil { + return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) + } + + tos := make([]string, 0, len(watches)) + for i := range watches { + uid := watches[i].UserId + if userId == uid { + continue + } + u, err := models.GetUserById(uid) + if err != nil { + return errors.New("mail.NotifyWatchers(get user): " + err.Error()) + } + tos = append(tos, u.Email) + } + + if len(tos) == 0 { + return nil + } + + msg := NewMailMessageFrom(tos, userName, subject, content) + msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) + SendAsync(&msg) + return nil +} diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index da63e01d..63861d87 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -33,7 +33,7 @@ func (m Message) Content() string { } // create mail content - content := "From: " + m.User + "<" + m.From + + content := "From: " + m.From + "<" + m.User + ">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body return content } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index fc5bb986..242593ff 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -13,6 +13,7 @@ import ( "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" ) @@ -86,6 +87,14 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } + // Mail watchers. + if base.Service.NotifyMail { + if err = mailer.SendNotifyMail(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.Name, ctx.Repo.Repository.Name, issue.Name, issue.Content); err != nil { + ctx.Handle(200, "issue.CreateIssue", err) + return + } + } + log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) } -- cgit v1.2.3