diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-26 14:38:14 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-26 14:38:14 +0800 |
commit | 9dbc808c7b71fc97015346704bb3d3db4918aba0 (patch) | |
tree | f0d76b189a0137bcb455e548e52805787d680fa7 /modules | |
parent | f9024b3f43c700ae997c284458fcc1d0dfc2e9a7 (diff) | |
parent | 06cf878471af02376dfcd02b9781982a89c27a2a (diff) |
Merge branch 'master' of github.com:gogits/gogs
Conflicts:
models/repo.go
modules/base/tool.go
serve.go
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/issue.go | 9 | ||||
-rw-r--r-- | modules/avatar/avatar.go | 7 | ||||
-rw-r--r-- | modules/base/conf.go | 28 | ||||
-rw-r--r-- | modules/base/tool.go | 26 | ||||
-rw-r--r-- | modules/log/log.go | 6 | ||||
-rw-r--r-- | modules/mailer/mail.go | 40 | ||||
-rw-r--r-- | modules/mailer/mailer.go | 2 | ||||
-rw-r--r-- | modules/middleware/repo.go | 7 |
8 files changed, 92 insertions, 33 deletions
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 0ba20294..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 ( @@ -251,8 +252,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") diff --git a/modules/base/conf.go b/modules/base/conf.go index 90b35476..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) @@ -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,16 @@ 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 len(curUser) == 0 { + curUser = os.Getenv("USER") + } + 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/modules/base/tool.go b/modules/base/tool.go index 4a8a124d..8f38d492 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 @@ -483,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 = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>` - TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/%s/src/%s">%s</a> at <a href="/%s/%s">%s/%s</a>%s` - TPL_COMMIT_REPO_LI = `<div><img id="gogs-user-avatar-commit" src="%s?s=16" alt="user-avatar" title="username"/> <a href="/%s/%s/commit/%s">%s</a> %s</div>` + TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s">%s</a>` + TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>%s` + TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s">%s</a> %s</div>` + TPL_CREATE_Issue = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a> +<div><img src="%s?s=16" alt="user-avatar"/> %s</div>` ) type PushCommits struct { @@ -504,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 { @@ -516,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(`<div><a href="/%s/%s/commits/%s">%d other commits >></a></div>`, 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/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/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/modules/middleware/repo.go b/modules/middleware/repo.go index eea2570c..bc90c05c 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -73,9 +73,14 @@ 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) + 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 |