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:
parent
3708ca8e28
commit
1a9821f57a
180 changed files with 3667 additions and 3677 deletions
|
@ -20,9 +20,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
pull_model "code.gitea.io/gitea/models/pull"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/analyze"
|
||||
|
@ -82,7 +82,7 @@ type DiffLine struct {
|
|||
Match int
|
||||
Type DiffLineType
|
||||
Content string
|
||||
Comments []*models.Comment
|
||||
Comments []*issues_model.Comment
|
||||
SectionInfo *DiffLineSectionInfo
|
||||
}
|
||||
|
||||
|
@ -704,8 +704,8 @@ type Diff struct {
|
|||
}
|
||||
|
||||
// LoadComments loads comments into each line
|
||||
func (diff *Diff) LoadComments(ctx context.Context, issue *models.Issue, currentUser *user_model.User) error {
|
||||
allComments, err := models.FetchCodeComments(ctx, issue, currentUser)
|
||||
func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User) error {
|
||||
allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1520,7 +1520,7 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
|
|||
|
||||
// SyncAndGetUserSpecificDiff is like GetDiff, except that user specific data such as which files the given user has already viewed on the given PR will also be set
|
||||
// Additionally, the database asynchronously is updated if files have changed since the last review
|
||||
func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *models.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) {
|
||||
func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) {
|
||||
diff, err := GetDiff(gitRepo, opts, files...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1583,7 +1583,7 @@ outer:
|
|||
}
|
||||
|
||||
// CommentAsDiff returns c.Patch as *Diff
|
||||
func CommentAsDiff(c *models.Comment) (*Diff, error) {
|
||||
func CommentAsDiff(c *issues_model.Comment) (*Diff, error) {
|
||||
diff, err := ParsePatch(setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch), "")
|
||||
if err != nil {
|
||||
|
@ -1601,7 +1601,7 @@ func CommentAsDiff(c *models.Comment) (*Diff, error) {
|
|||
}
|
||||
|
||||
// CommentMustAsDiff executes AsDiff and logs the error instead of returning
|
||||
func CommentMustAsDiff(c *models.Comment) *Diff {
|
||||
func CommentMustAsDiff(c *issues_model.Comment) *Diff {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -669,7 +669,7 @@ func setupDefaultDiff() *Diff {
|
|||
func TestDiff_LoadComments(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}).(*issues_model.Issue)
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||
diff := setupDefaultDiff()
|
||||
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user))
|
||||
|
@ -678,15 +678,15 @@ func TestDiff_LoadComments(t *testing.T) {
|
|||
|
||||
func TestDiffLine_CanComment(t *testing.T) {
|
||||
assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
|
||||
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*models.Comment{{Content: "bla"}}}).CanComment())
|
||||
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
|
||||
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
|
||||
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())
|
||||
assert.True(t, (&DiffLine{Type: DiffLinePlain}).CanComment())
|
||||
}
|
||||
|
||||
func TestDiffLine_GetCommentSide(t *testing.T) {
|
||||
assert.Equal(t, "previous", (&DiffLine{Comments: []*models.Comment{{Line: -3}}}).GetCommentSide())
|
||||
assert.Equal(t, "proposed", (&DiffLine{Comments: []*models.Comment{{Line: 3}}}).GetCommentSide())
|
||||
assert.Equal(t, "previous", (&DiffLine{Comments: []*issues_model.Comment{{Line: -3}}}).GetCommentSide())
|
||||
assert.Equal(t, "proposed", (&DiffLine{Comments: []*issues_model.Comment{{Line: 3}}}).GetCommentSide())
|
||||
}
|
||||
|
||||
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
_ "code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue