mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use templates for issue e-mail subject and body (#8329)
* Add template capability for issue mail subject * Remove test string * Fix trim subject length * Add comment to template and run make fmt * Add information for the template * Rename defaultMailSubject() to fallbackMailSubject() * General rewrite of the mail template code * Fix .Doer name * Use text/template for subject instead of html * Fix subject Re: prefix * Fix mail tests * Fix static templates * [skip ci] Updated translations via Crowdin * Expose db.SetMaxOpenConns and allow non MySQL dbs to set conn pool params (#8528) * Expose db.SetMaxOpenConns and allow other dbs to set their connection params * Add note about port exhaustion Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Prevent .code-view from overriding font on icon fonts (#8614) * Correct some outdated statements in the contributing guidelines (#8612) * More information for drone-cli in CONTRIBUTING.md * Increases the version of drone-cli to 1.2.0 * Adds a note for the Docker Toolbox on Windows Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * Fix the url for the blog repository (now on gitea.com) Signed-off-by: LukBukkit <luk.bukkit@gmail.com> * Remove TrN due to lack of lang context * Redo templates to match previous code * Fix extra character in template * Unify PR & Issue tempaltes, fix format * Remove default subject * Add template tests * Fix template * Remove replaced function * Provide User as models.User for better consistency * Add docs * Fix doc inaccuracies, improve examples * Change mail footer to math AppName * Add test for mail subject/body template separation * Add support for code review comments * Update docs/content/doc/advanced/mail-templates-us.md Co-Authored-By: 6543 <24977596+6543@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/unknwon/com"
|
||||
)
|
||||
|
||||
func mailSubject(issue *models.Issue) string {
|
||||
func fallbackMailSubject(issue *models.Issue) string {
|
||||
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, issue.Index)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func mailSubject(issue *models.Issue) string {
|
||||
// This function sends two list of emails:
|
||||
// 1. Repository watchers and users who are participated in comments.
|
||||
// 2. Users who are not in 1. but get mentioned in current issue/comment.
|
||||
func mailIssueCommentToParticipants(issue *models.Issue, doer *models.User, content string, comment *models.Comment, mentions []string) error {
|
||||
func mailIssueCommentToParticipants(issue *models.Issue, doer *models.User, actionType models.ActionType, content string, comment *models.Comment, mentions []string) error {
|
||||
|
||||
watchers, err := models.GetWatchers(issue.RepoID)
|
||||
if err != nil {
|
||||
@@ -89,7 +89,7 @@ func mailIssueCommentToParticipants(issue *models.Issue, doer *models.User, cont
|
||||
}
|
||||
|
||||
for _, to := range tos {
|
||||
SendIssueCommentMail(issue, doer, content, comment, []string{to})
|
||||
SendIssueCommentMail(issue, doer, actionType, content, comment, []string{to})
|
||||
}
|
||||
|
||||
// Mail mentioned people and exclude watchers.
|
||||
@@ -106,7 +106,7 @@ func mailIssueCommentToParticipants(issue *models.Issue, doer *models.User, cont
|
||||
emails := models.GetUserEmailsByNames(tos)
|
||||
|
||||
for _, to := range emails {
|
||||
SendIssueMentionMail(issue, doer, content, comment, []string{to})
|
||||
SendIssueMentionMail(issue, doer, actionType, content, comment, []string{to})
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -131,32 +131,8 @@ func mailParticipants(ctx models.DBContext, issue *models.Issue, doer *models.Us
|
||||
for i, u := range userMentions {
|
||||
mentions[i] = u.LowerName
|
||||
}
|
||||
|
||||
if len(issue.Content) > 0 {
|
||||
if err = mailIssueCommentToParticipants(issue, doer, issue.Content, nil, mentions); err != nil {
|
||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||
}
|
||||
if err = mailIssueCommentToParticipants(issue, doer, opType, issue.Content, nil, mentions); err != nil {
|
||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||
}
|
||||
|
||||
switch opType {
|
||||
case models.ActionCreateIssue, models.ActionCreatePullRequest:
|
||||
if len(issue.Content) == 0 {
|
||||
ct := fmt.Sprintf("Created #%d.", issue.Index)
|
||||
if err = mailIssueCommentToParticipants(issue, doer, ct, nil, mentions); err != nil {
|
||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
case models.ActionCloseIssue, models.ActionClosePullRequest:
|
||||
ct := fmt.Sprintf("Closed #%d.", issue.Index)
|
||||
if err = mailIssueCommentToParticipants(issue, doer, ct, nil, mentions); err != nil {
|
||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||
}
|
||||
case models.ActionReopenIssue, models.ActionReopenPullRequest:
|
||||
ct := fmt.Sprintf("Reopened #%d.", issue.Index)
|
||||
if err = mailIssueCommentToParticipants(issue, doer, ct, nil, mentions); err != nil {
|
||||
log.Error("mailIssueCommentToParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user