mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access * fix test * fix git test * Move functions sequence * Some improvements per @KN4CK3R and @delvh * Move issues related code to models/issues * Move some issues related sub package * Merge * Fix test * Fix test * Fix test * Fix test * Rename some files
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
@@ -220,10 +221,10 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
prefix string
|
||||
// Fall back subject for bad templates, make sure subject is never empty
|
||||
fallback string
|
||||
reviewComments []*models.Comment
|
||||
reviewComments []*issues_model.Comment
|
||||
)
|
||||
|
||||
commentType := models.CommentTypeComment
|
||||
commentType := issues_model.CommentTypeComment
|
||||
if ctx.Comment != nil {
|
||||
commentType = ctx.Comment.Type
|
||||
link = ctx.Issue.HTMLURL() + "#" + ctx.Comment.HashTag()
|
||||
@@ -231,7 +232,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
link = ctx.Issue.HTMLURL()
|
||||
}
|
||||
|
||||
reviewType := models.ReviewTypeComment
|
||||
reviewType := issues_model.ReviewTypeComment
|
||||
if ctx.Comment != nil && ctx.Comment.Review != nil {
|
||||
reviewType = ctx.Comment.Review.Type
|
||||
}
|
||||
@@ -254,7 +255,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
fallback = prefix + fallbackMailSubject(ctx.Issue)
|
||||
|
||||
if ctx.Comment != nil && ctx.Comment.Review != nil {
|
||||
reviewComments = make([]*models.Comment, 0, 10)
|
||||
reviewComments = make([]*issues_model.Comment, 0, 10)
|
||||
for _, lines := range ctx.Comment.Review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
reviewComments = append(reviewComments, comments...)
|
||||
@@ -328,7 +329,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
||||
return msgs, nil
|
||||
}
|
||||
|
||||
func createReference(issue *models.Issue, comment *models.Comment, actionType models.ActionType) string {
|
||||
func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType models.ActionType) string {
|
||||
var path string
|
||||
if issue.IsPull {
|
||||
path = "pulls"
|
||||
@@ -400,7 +401,7 @@ func sanitizeSubject(subject string) string {
|
||||
}
|
||||
|
||||
// SendIssueAssignedMail composes and sends issue assigned email
|
||||
func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content string, comment *models.Comment, recipients []*user_model.User) error {
|
||||
func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, content string, comment *issues_model.Comment, recipients []*user_model.User) error {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
@@ -439,8 +440,8 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
|
||||
|
||||
// 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 *models.Issue, actionType models.ActionType,
|
||||
commentType models.CommentType, reviewType models.ReviewType,
|
||||
func actionToTemplate(issue *issues_model.Issue, actionType models.ActionType,
|
||||
commentType issues_model.CommentType, reviewType issues_model.ReviewType,
|
||||
) (typeName, name, template string) {
|
||||
if issue.IsPull {
|
||||
typeName = "pull"
|
||||
@@ -464,20 +465,20 @@ func actionToTemplate(issue *models.Issue, actionType models.ActionType,
|
||||
name = "ready_for_review"
|
||||
default:
|
||||
switch commentType {
|
||||
case models.CommentTypeReview:
|
||||
case issues_model.CommentTypeReview:
|
||||
switch reviewType {
|
||||
case models.ReviewTypeApprove:
|
||||
case issues_model.ReviewTypeApprove:
|
||||
name = "approve"
|
||||
case models.ReviewTypeReject:
|
||||
case issues_model.ReviewTypeReject:
|
||||
name = "reject"
|
||||
default:
|
||||
name = "review"
|
||||
}
|
||||
case models.CommentTypeCode:
|
||||
case issues_model.CommentTypeCode:
|
||||
name = "code"
|
||||
case models.CommentTypeAssignees:
|
||||
case issues_model.CommentTypeAssignees:
|
||||
name = "assigned"
|
||||
case models.CommentTypePullRequestPush:
|
||||
case issues_model.CommentTypePullRequestPush:
|
||||
name = "push"
|
||||
default:
|
||||
name = "default"
|
||||
|
@@ -8,20 +8,21 @@ import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
|
||||
func MailParticipantsComment(ctx context.Context, c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error {
|
||||
func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType models.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
}
|
||||
|
||||
content := c.Content
|
||||
if c.Type == models.CommentTypePullRequestPush {
|
||||
if c.Type == issues_model.CommentTypePullRequestPush {
|
||||
content = ""
|
||||
}
|
||||
if err := mailIssueCommentToParticipants(
|
||||
@@ -39,7 +40,7 @@ func MailParticipantsComment(ctx context.Context, c *models.Comment, opType mode
|
||||
}
|
||||
|
||||
// MailMentionsComment sends email to users mentioned in a code comment
|
||||
func MailMentionsComment(ctx context.Context, pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) {
|
||||
func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) (err error) {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -16,17 +17,17 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
func fallbackMailSubject(issue *models.Issue) string {
|
||||
func fallbackMailSubject(issue *issues_model.Issue) string {
|
||||
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, issue.Index)
|
||||
}
|
||||
|
||||
type mailCommentContext struct {
|
||||
context.Context
|
||||
Issue *models.Issue
|
||||
Issue *issues_model.Issue
|
||||
Doer *user_model.User
|
||||
ActionType models.ActionType
|
||||
Content string
|
||||
Comment *models.Comment
|
||||
Comment *issues_model.Comment
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -57,21 +58,21 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
unfiltered[0] = ctx.Issue.PosterID
|
||||
|
||||
// =========== Assignees ===========
|
||||
ids, err := models.GetAssigneeIDsByIssue(ctx.Issue.ID)
|
||||
ids, err := issues_model.GetAssigneeIDsByIssue(ctx.Issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetAssigneeIDsByIssue(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
// =========== Participants (i.e. commenters, reviewers) ===========
|
||||
ids, err = models.GetParticipantsIDsByIssueID(ctx.Issue.ID)
|
||||
ids, err = issues_model.GetParticipantsIDsByIssueID(ctx.Issue.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
unfiltered = append(unfiltered, ids...)
|
||||
|
||||
// =========== Issue watchers ===========
|
||||
ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
|
||||
ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
}
|
||||
|
||||
// Avoid mailing explicit unwatched
|
||||
ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
|
||||
ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
|
||||
}
|
||||
@@ -171,7 +172,7 @@ 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 *models.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
|
||||
func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
|
||||
if setting.MailService == nil {
|
||||
// No mail service configured
|
||||
return nil
|
||||
|
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -46,7 +47,7 @@ const bodyTpl = `
|
||||
</html>
|
||||
`
|
||||
|
||||
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) {
|
||||
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
mailService := setting.Mailer{
|
||||
From: "test@gitea.com",
|
||||
@@ -57,9 +58,9 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Re
|
||||
|
||||
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer}).(*repo_model.Repository)
|
||||
issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
|
||||
issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1, Repo: repo, Poster: doer}).(*issues_model.Issue)
|
||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2, Issue: issue}).(*issues_model.Comment)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,8 +163,8 @@ func TestTemplateSelection(t *testing.T) {
|
||||
}, 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)
|
||||
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer}).(*issues_model.Issue)
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull}).(*issues_model.Comment)
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
|
||||
@@ -183,7 +184,7 @@ func TestTemplateServices(t *testing.T) {
|
||||
doer, _, issue, comment := prepareMailerTest(t)
|
||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
|
||||
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
|
||||
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,
|
||||
) {
|
||||
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
|
||||
@@ -268,8 +269,8 @@ func Test_createReference(t *testing.T) {
|
||||
pullIssue.IsPull = true
|
||||
|
||||
type args struct {
|
||||
issue *models.Issue
|
||||
comment *models.Comment
|
||||
issue *issues_model.Issue
|
||||
comment *issues_model.Comment
|
||||
actionType models.ActionType
|
||||
}
|
||||
tests := []struct {
|
||||
|
Reference in New Issue
Block a user