diff options
author | Unknwon <u@gogs.io> | 2015-10-29 20:40:57 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-29 20:40:57 -0400 |
commit | 706b0f72e2e4bc91bdbed38fee609cabe9f44e43 (patch) | |
tree | 9b84a4556d0fef0c4e453b13daaab93e3b7b2591 /routers/repo/issue.go | |
parent | 1f4beb530cea9c098c79d3cd4d84671265dff0e0 (diff) | |
download | gitea-706b0f72e2e4bc91bdbed38fee609cabe9f44e43.tar.gz gitea-706b0f72e2e4bc91bdbed38fee609cabe9f44e43.zip |
fix issue comment mention and autofix count when start
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r-- | routers/repo/issue.go | 125 |
1 files changed, 52 insertions, 73 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 30dcf92578..58382d18cc 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -324,6 +324,47 @@ func ValidateRepoMetas(ctx *middleware.Context, form auth.CreateIssueForm) ([]in return labelIDs, milestoneID, assigneeID } +func checkMentions(ctx *middleware.Context, issue *models.Issue) { + // Update mentions. + mentions := base.MentionPattern.FindAllString(issue.Content, -1) + if len(mentions) > 0 { + for i := range mentions { + mentions[i] = strings.TrimSpace(mentions[i])[1:] + } + + if err := models.UpdateMentions(mentions, issue.ID); err != nil { + ctx.Handle(500, "UpdateMentions", err) + return + } + } + + repo := ctx.Repo.Repository + + // Mail watchers and mentions. + if setting.Service.EnableNotifyMail { + tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, repo, issue) + if err != nil { + ctx.Handle(500, "SendIssueNotifyMail", err) + return + } + + tos = append(tos, ctx.User.LowerName) + newTos := make([]string, 0, len(mentions)) + for _, m := range mentions { + if com.IsSliceContainsStr(tos, m) { + continue + } + + newTos = append(newTos, m) + } + if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner, + repo, issue, models.GetUserEmailsByNames(newTos)); err != nil { + ctx.Handle(500, "SendIssueMentionMail", err) + return + } + } +} + func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true @@ -363,41 +404,9 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) { return } - // Update mentions. - mentions := base.MentionPattern.FindAllString(issue.Content, -1) - if len(mentions) > 0 { - for i := range mentions { - mentions[i] = strings.TrimSpace(mentions[i])[1:] - } - - if err := models.UpdateMentions(mentions, issue.ID); err != nil { - ctx.Handle(500, "UpdateMentions", err) - return - } - } - - // Mail watchers and mentions. - if setting.Service.EnableNotifyMail { - tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, repo, issue) - if err != nil { - ctx.Handle(500, "SendIssueNotifyMail", err) - return - } - - tos = append(tos, ctx.User.LowerName) - newTos := make([]string, 0, len(mentions)) - for _, m := range mentions { - if com.IsSliceContainsStr(tos, m) { - continue - } - - newTos = append(newTos, m) - } - if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner, - repo, issue, models.GetUserEmailsByNames(newTos)); err != nil { - ctx.Handle(500, "SendIssueMentionMail", err) - return - } + checkMentions(ctx, issue) + if ctx.Written() { + return } log.Trace("Issue created: %d/%d", repo.ID, issue.ID) @@ -836,46 +845,16 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { return } - // Update mentions. - mentions := base.MentionPattern.FindAllString(comment.Content, -1) - if len(mentions) > 0 { - for i := range mentions { - mentions[i] = mentions[i][1:] - } - - if err := models.UpdateMentions(mentions, issue.ID); err != nil { - ctx.Handle(500, "UpdateMentions", err) - return - } + checkMentions(ctx, &models.Issue{ + ID: issue.ID, + Index: issue.Index, + Name: issue.Name, + Content: form.Content, + }) + if ctx.Written() { + return } - // Mail watchers and mentions. - if setting.Service.EnableNotifyMail { - tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, &models.Issue{ - Index: issue.Index, - Name: issue.Name, - Content: form.Content, - }) - if err != nil { - ctx.Handle(500, "SendIssueNotifyMail", err) - return - } - - tos = append(tos, ctx.User.LowerName) - newTos := make([]string, 0, len(mentions)) - for _, m := range mentions { - if com.IsSliceContainsStr(tos, m) { - continue - } - - newTos = append(newTos, m) - } - if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner, - ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil { - ctx.Handle(500, "SendIssueMentionMail", err) - return - } - } log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID) } |