mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
texttmpl "text/template"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -302,7 +302,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
|
||||
// Make sure to compose independent messages to avoid leaking user emails
|
||||
msgID := createReference(ctx.Issue, ctx.Comment, ctx.ActionType)
|
||||
reference := createReference(ctx.Issue, nil, models.ActionType(0))
|
||||
reference := createReference(ctx.Issue, nil, activities_model.ActionType(0))
|
||||
|
||||
msgs := make([]*Message, 0, len(recipients))
|
||||
for _, recipient := range recipients {
|
||||
@@ -323,7 +323,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
return msgs, nil
|
||||
}
|
||||
|
||||
func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType models.ActionType) string {
|
||||
func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType activities_model.ActionType) string {
|
||||
var path string
|
||||
if issue.IsPull {
|
||||
path = "pulls"
|
||||
@@ -336,13 +336,13 @@ func createReference(issue *issues_model.Issue, comment *issues_model.Comment, a
|
||||
extra = fmt.Sprintf("/comment/%d", comment.ID)
|
||||
} else {
|
||||
switch actionType {
|
||||
case models.ActionCloseIssue, models.ActionClosePullRequest:
|
||||
case activities_model.ActionCloseIssue, activities_model.ActionClosePullRequest:
|
||||
extra = fmt.Sprintf("/close/%d", time.Now().UnixNano()/1e6)
|
||||
case models.ActionReopenIssue, models.ActionReopenPullRequest:
|
||||
case activities_model.ActionReopenIssue, activities_model.ActionReopenPullRequest:
|
||||
extra = fmt.Sprintf("/reopen/%d", time.Now().UnixNano()/1e6)
|
||||
case models.ActionMergePullRequest:
|
||||
case activities_model.ActionMergePullRequest:
|
||||
extra = fmt.Sprintf("/merge/%d", time.Now().UnixNano()/1e6)
|
||||
case models.ActionPullRequestReadyForReview:
|
||||
case activities_model.ActionPullRequestReadyForReview:
|
||||
extra = fmt.Sprintf("/ready/%d", time.Now().UnixNano()/1e6)
|
||||
}
|
||||
}
|
||||
@@ -420,7 +420,7 @@ func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, con
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue,
|
||||
Doer: doer,
|
||||
ActionType: models.ActionType(0),
|
||||
ActionType: activities_model.ActionType(0),
|
||||
Content: content,
|
||||
Comment: comment,
|
||||
}, lang, tos, false, "issue assigned")
|
||||
@@ -433,8 +433,8 @@ func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, con
|
||||
}
|
||||
|
||||
// actionToTemplate returns the type and name of the action facing the user
|
||||
// (slightly different from models.ActionType) and the name of the template to use (based on availability)
|
||||
func actionToTemplate(issue *issues_model.Issue, actionType models.ActionType,
|
||||
// (slightly different from activities_model.ActionType) and the name of the template to use (based on availability)
|
||||
func actionToTemplate(issue *issues_model.Issue, actionType activities_model.ActionType,
|
||||
commentType issues_model.CommentType, reviewType issues_model.ReviewType,
|
||||
) (typeName, name, template string) {
|
||||
if issue.IsPull {
|
||||
@@ -443,19 +443,19 @@ func actionToTemplate(issue *issues_model.Issue, actionType models.ActionType,
|
||||
typeName = "issue"
|
||||
}
|
||||
switch actionType {
|
||||
case models.ActionCreateIssue, models.ActionCreatePullRequest:
|
||||
case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest:
|
||||
name = "new"
|
||||
case models.ActionCommentIssue, models.ActionCommentPull:
|
||||
case activities_model.ActionCommentIssue, activities_model.ActionCommentPull:
|
||||
name = "comment"
|
||||
case models.ActionCloseIssue, models.ActionClosePullRequest:
|
||||
case activities_model.ActionCloseIssue, activities_model.ActionClosePullRequest:
|
||||
name = "close"
|
||||
case models.ActionReopenIssue, models.ActionReopenPullRequest:
|
||||
case activities_model.ActionReopenIssue, activities_model.ActionReopenPullRequest:
|
||||
name = "reopen"
|
||||
case models.ActionMergePullRequest:
|
||||
case activities_model.ActionMergePullRequest:
|
||||
name = "merge"
|
||||
case models.ActionPullReviewDismissed:
|
||||
case activities_model.ActionPullReviewDismissed:
|
||||
name = "review_dismissed"
|
||||
case models.ActionPullRequestReadyForReview:
|
||||
case activities_model.ActionPullRequestReadyForReview:
|
||||
name = "ready_for_review"
|
||||
default:
|
||||
switch commentType {
|
||||
|
@@ -7,7 +7,7 @@ package mailer
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
|
||||
func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType models.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
|
||||
func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType activities_model.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
@@ -53,7 +53,7 @@ func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *i
|
||||
Context: ctx,
|
||||
Issue: pr.Issue,
|
||||
Doer: c.Poster,
|
||||
ActionType: models.ActionCommentPull,
|
||||
ActionType: activities_model.ActionCommentPull,
|
||||
Content: c.Content,
|
||||
Comment: c,
|
||||
}, mentions, visited, true); err != nil {
|
||||
|
@@ -8,8 +8,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -25,7 +26,7 @@ type mailCommentContext struct {
|
||||
context.Context
|
||||
Issue *issues_model.Issue
|
||||
Doer *user_model.User
|
||||
ActionType models.ActionType
|
||||
ActionType activities_model.ActionType
|
||||
Content string
|
||||
Comment *issues_model.Comment
|
||||
}
|
||||
@@ -80,7 +81,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
|
||||
// =========== Repo watchers ===========
|
||||
// Make repo watchers last, since it's likely the list with the most users
|
||||
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != models.ActionCreatePullRequest) {
|
||||
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != activities_model.ActionCreatePullRequest) {
|
||||
ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
|
||||
@@ -149,7 +150,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
|
||||
visited[user.ID] = true
|
||||
|
||||
// test if this user is allowed to see the issue/pull
|
||||
if !models.CheckRepoUnitUser(ctx, ctx.Issue.Repo, user, checkUnit) {
|
||||
if !access_model.CheckRepoUnitUser(ctx, ctx.Issue.Repo, user, checkUnit) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -175,16 +176,16 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
|
||||
|
||||
// MailParticipants sends new issue thread created emails to repository watchers
|
||||
// and mentioned people.
|
||||
func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
|
||||
func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType activities_model.ActionType, mentions []*user_model.User) error {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
}
|
||||
|
||||
content := issue.Content
|
||||
if opType == models.ActionCloseIssue || opType == models.ActionClosePullRequest ||
|
||||
opType == models.ActionReopenIssue || opType == models.ActionReopenPullRequest ||
|
||||
opType == models.ActionMergePullRequest {
|
||||
if opType == activities_model.ActionCloseIssue || opType == activities_model.ActionClosePullRequest ||
|
||||
opType == activities_model.ActionReopenIssue || opType == activities_model.ActionReopenPullRequest ||
|
||||
opType == activities_model.ActionMergePullRequest {
|
||||
content = ""
|
||||
}
|
||||
if err := mailIssueCommentToParticipants(
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
@@ -25,7 +24,7 @@ const (
|
||||
)
|
||||
|
||||
// MailNewRelease send new release notify to all all repo watchers.
|
||||
func MailNewRelease(ctx context.Context, rel *models.Release) {
|
||||
func MailNewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return
|
||||
@@ -55,7 +54,7 @@ func MailNewRelease(ctx context.Context, rel *models.Release) {
|
||||
}
|
||||
}
|
||||
|
||||
func mailNewRelease(ctx context.Context, lang string, tos []string, rel *models.Release) {
|
||||
func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_model.Release) {
|
||||
locale := translation.NewLocale(lang)
|
||||
|
||||
var err error
|
||||
|
@@ -13,7 +13,7 @@ import (
|
||||
"testing"
|
||||
texttmpl "text/template"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -73,7 +73,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, "en-US", recipients, false, "issue comment")
|
||||
assert.NoError(t, err)
|
||||
@@ -102,7 +102,7 @@ func TestComposeIssueMessage(t *testing.T) {
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
|
||||
Content: "test body",
|
||||
}, "en-US", recipients, false, "issue create")
|
||||
assert.NoError(t, err)
|
||||
@@ -147,14 +147,14 @@ func TestTemplateSelection(t *testing.T) {
|
||||
|
||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
|
||||
Content: "test body",
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "issue/new/subject", "issue/new/body")
|
||||
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "issue/default/subject", "issue/default/body")
|
||||
@@ -163,14 +163,14 @@ func TestTemplateSelection(t *testing.T) {
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
|
||||
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "pull/comment/subject", "pull/comment/body")
|
||||
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
|
||||
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
|
||||
@@ -181,7 +181,7 @@ func TestTemplateServices(t *testing.T) {
|
||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
|
||||
expect := func(t *testing.T, issue *issues_model.Issue, comment *issues_model.Comment, doer *user_model.User,
|
||||
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
|
||||
actionType activities_model.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
|
||||
) {
|
||||
subjectTemplates = texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
|
||||
bodyTemplates = template.Must(template.New("issue/default").Parse(tplBody))
|
||||
@@ -202,19 +202,19 @@ func TestTemplateServices(t *testing.T) {
|
||||
assert.Contains(t, wholemsg, "\r\n"+expBody+"\r\n")
|
||||
}
|
||||
|
||||
expect(t, issue, comment, doer, models.ActionCommentIssue, false,
|
||||
expect(t, issue, comment, doer, activities_model.ActionCommentIssue, false,
|
||||
"{{.SubjectPrefix}}[{{.Repo}}]: @{{.Doer.Name}} commented on #{{.Issue.Index}} - {{.Issue.Title}}",
|
||||
"//{{.ActionType}},{{.ActionName}},{{if .IsMention}}norender{{end}}//",
|
||||
"Re: [user2/repo1]: @user2 commented on #1 - issue1",
|
||||
"//issue,comment,//")
|
||||
|
||||
expect(t, issue, comment, doer, models.ActionCommentIssue, true,
|
||||
expect(t, issue, comment, doer, activities_model.ActionCommentIssue, true,
|
||||
"{{if .IsMention}}must render{{end}}",
|
||||
"//subject is: {{.Subject}}//",
|
||||
"must render",
|
||||
"//subject is: must render//")
|
||||
|
||||
expect(t, issue, comment, doer, models.ActionCommentIssue, true,
|
||||
expect(t, issue, comment, doer, activities_model.ActionCommentIssue, true,
|
||||
"{{.FallbackSubject}}",
|
||||
"//{{.SubjectPrefix}}//",
|
||||
"Re: [user2/repo1] issue1 (#1)",
|
||||
@@ -266,7 +266,7 @@ func Test_createReference(t *testing.T) {
|
||||
type args struct {
|
||||
issue *issues_model.Issue
|
||||
comment *issues_model.Comment
|
||||
actionType models.ActionType
|
||||
actionType activities_model.ActionType
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -278,7 +278,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Open Issue",
|
||||
args: args{
|
||||
issue: issue,
|
||||
actionType: models.ActionCreateIssue,
|
||||
actionType: activities_model.ActionCreateIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/issues/%d@%s", issue.Repo.FullName(), issue.Index, setting.Domain),
|
||||
},
|
||||
@@ -286,7 +286,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Open Pull",
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
actionType: models.ActionCreatePullRequest,
|
||||
actionType: activities_model.ActionCreatePullRequest,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d@%s", issue.Repo.FullName(), issue.Index, setting.Domain),
|
||||
},
|
||||
@@ -295,7 +295,7 @@ func Test_createReference(t *testing.T) {
|
||||
args: args{
|
||||
issue: issue,
|
||||
comment: comment,
|
||||
actionType: models.ActionCommentIssue,
|
||||
actionType: activities_model.ActionCommentIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/issues/%d/comment/%d@%s", issue.Repo.FullName(), issue.Index, comment.ID, setting.Domain),
|
||||
},
|
||||
@@ -304,7 +304,7 @@ func Test_createReference(t *testing.T) {
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
comment: comment,
|
||||
actionType: models.ActionCommentPull,
|
||||
actionType: activities_model.ActionCommentPull,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d/comment/%d@%s", issue.Repo.FullName(), issue.Index, comment.ID, setting.Domain),
|
||||
},
|
||||
@@ -312,7 +312,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Close Issue",
|
||||
args: args{
|
||||
issue: issue,
|
||||
actionType: models.ActionCloseIssue,
|
||||
actionType: activities_model.ActionCloseIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/issues/%d/close/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
@@ -320,7 +320,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Close Pull",
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
actionType: models.ActionClosePullRequest,
|
||||
actionType: activities_model.ActionClosePullRequest,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d/close/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
@@ -328,7 +328,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Reopen Issue",
|
||||
args: args{
|
||||
issue: issue,
|
||||
actionType: models.ActionReopenIssue,
|
||||
actionType: activities_model.ActionReopenIssue,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/issues/%d/reopen/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
@@ -336,7 +336,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Reopen Pull",
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
actionType: models.ActionReopenPullRequest,
|
||||
actionType: activities_model.ActionReopenPullRequest,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d/reopen/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
@@ -344,7 +344,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Merge Pull",
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
actionType: models.ActionMergePullRequest,
|
||||
actionType: activities_model.ActionMergePullRequest,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d/merge/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
@@ -352,7 +352,7 @@ func Test_createReference(t *testing.T) {
|
||||
name: "Ready Pull",
|
||||
args: args{
|
||||
issue: pullIssue,
|
||||
actionType: models.ActionPullRequestReadyForReview,
|
||||
actionType: activities_model.ActionPullRequestReadyForReview,
|
||||
},
|
||||
prefix: fmt.Sprintf("%s/pulls/%d/ready/", issue.Repo.FullName(), issue.Index),
|
||||
},
|
||||
|
Reference in New Issue
Block a user