aboutsummaryrefslogtreecommitdiffstats
path: root/services/mailer
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-01-20 18:46:10 +0100
committerGitHub <noreply@github.com>2022-01-20 18:46:10 +0100
commit54e9ee37a7a301dbe74d46fd3c87712e6120e9bf (patch)
tree1be12fb072625c1b896b9d72f7912b018aad502b /services/mailer
parent1d98d205f5825f40110e6628b61a97c91ac7f72d (diff)
downloadgitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.tar.gz
gitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.zip
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
Diffstat (limited to 'services/mailer')
-rw-r--r--services/mailer/mail_issue.go1
-rw-r--r--services/mailer/mail_test.go48
-rw-r--r--services/mailer/mailer.go10
3 files changed, 34 insertions, 25 deletions
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 1df8332116..bd5008f076 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -40,7 +40,6 @@ const (
// 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
// 2. Users who are not in 1. but get mentioned in current issue/comment.
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
-
// Required by the mail composer; make sure to load these before calling the async function
if err := ctx.Issue.LoadRepo(); err != nil {
return fmt.Errorf("LoadRepo(): %v", err)
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index 6a175337ad..07690063cd 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -44,7 +44,7 @@ const bodyTpl = `
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) {
assert.NoError(t, unittest.PrepareTestDatabase())
- var mailService = setting.Mailer{
+ mailService := setting.Mailer{
From: "test@gitea.com",
}
@@ -67,8 +67,10 @@ func TestComposeIssueCommentMessage(t *testing.T) {
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
- msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
- Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment")
+ msgs, err := composeIssueCommentMessages(&mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Content: "test body", Comment: comment,
+ }, "en-US", recipients, false, "issue comment")
assert.NoError(t, err)
assert.Len(t, msgs, 2)
gomailMsg := msgs[0].ToMessage()
@@ -94,8 +96,10 @@ func TestComposeIssueMessage(t *testing.T) {
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
- msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
- Content: "test body"}, "en-US", recipients, false, "issue create")
+ msgs, err := composeIssueCommentMessages(&mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Content: "test body",
+ }, "en-US", recipients, false, "issue create")
assert.NoError(t, err)
assert.Len(t, msgs, 2)
@@ -138,22 +142,30 @@ func TestTemplateSelection(t *testing.T) {
assert.Contains(t, wholemsg, expBody)
}
- msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
- Content: "test body"}, recipients, false, "TestTemplateSelection")
+ msg := testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
+ Content: "test body",
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/new/subject", "issue/new/body")
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/default/subject", "issue/default/body")
pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "pull/comment/subject", "pull/comment/body")
- msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
- Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
+ msg = testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
+ Content: "test body", Comment: comment,
+ }, recipients, false, "TestTemplateSelection")
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
}
@@ -162,15 +174,17 @@ func TestTemplateServices(t *testing.T) {
assert.NoError(t, issue.LoadRepo())
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
- actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) {
-
+ actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
+ ) {
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
btpl := template.Must(template.New("issue/default").Parse(tplBody))
InitMailRender(stpl, btpl)
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
- msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType,
- Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices")
+ msg := testComposeIssueCommentMessage(t, &mailCommentContext{
+ Issue: issue, Doer: doer, ActionType: actionType,
+ Content: "test body", Comment: comment,
+ }, recipients, fromMention, "TestTemplateServices")
subject := msg.ToMessage().GetHeader("Subject")
msgbuf := new(bytes.Buffer)
diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go
index e5e6272f10..eeb98b5879 100644
--- a/services/mailer/mailer.go
+++ b/services/mailer/mailer.go
@@ -141,8 +141,7 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
}
// Sender SMTP mail sender
-type smtpSender struct {
-}
+type smtpSender struct{}
// Send send email
func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
@@ -254,8 +253,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
}
// Sender sendmail mail sender
-type sendmailSender struct {
-}
+type sendmailSender struct{}
// Send send email
func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
@@ -280,7 +278,6 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
cmd := exec.CommandContext(ctx, setting.MailService.SendmailPath, args...)
pipe, err := cmd.StdinPipe()
-
if err != nil {
return err
}
@@ -314,8 +311,7 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
}
// Sender sendmail mail sender
-type dummySender struct {
-}
+type dummySender struct{}
// Send send email
func (s *dummySender) Send(from string, to []string, msg io.WriterTo) error {