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:
Lunny Xiao 2022-06-13 17:37:59 +08:00 committed by GitHub
parent 3708ca8e28
commit 1a9821f57a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
180 changed files with 3667 additions and 3677 deletions

View file

@ -2,12 +2,13 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package issues
package issues_test
import (
"testing"
"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"
@ -17,12 +18,12 @@ import (
)
func addReaction(t *testing.T, doerID, issueID, commentID int64, content string) {
var reaction *Reaction
var reaction *issues_model.Reaction
var err error
if commentID == 0 {
reaction, err = CreateIssueReaction(doerID, issueID, content)
reaction, err = issues_model.CreateIssueReaction(doerID, issueID, content)
} else {
reaction, err = CreateCommentReaction(doerID, issueID, commentID, content)
reaction, err = issues_model.CreateCommentReaction(doerID, issueID, commentID, content)
}
assert.NoError(t, err)
assert.NotNil(t, reaction)
@ -37,7 +38,7 @@ func TestIssueAddReaction(t *testing.T) {
addReaction(t, user1.ID, issue1ID, 0, "heart")
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID})
unittest.AssertExistsAndLoadBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID})
}
func TestIssueAddDuplicateReaction(t *testing.T) {
@ -49,15 +50,15 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
addReaction(t, user1.ID, issue1ID, 0, "heart")
reaction, err := CreateReaction(&ReactionOptions{
reaction, err := issues_model.CreateReaction(&issues_model.ReactionOptions{
DoerID: user1.ID,
IssueID: issue1ID,
Type: "heart",
})
assert.Error(t, err)
assert.Equal(t, ErrReactionAlreadyExist{Reaction: "heart"}, err)
assert.Equal(t, issues_model.ErrReactionAlreadyExist{Reaction: "heart"}, err)
existingR := unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID}).(*Reaction)
existingR := unittest.AssertExistsAndLoadBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID}).(*issues_model.Reaction)
assert.Equal(t, existingR.ID, reaction.ID)
}
@ -70,10 +71,10 @@ func TestIssueDeleteReaction(t *testing.T) {
addReaction(t, user1.ID, issue1ID, 0, "heart")
err := DeleteIssueReaction(user1.ID, issue1ID, "heart")
err := issues_model.DeleteIssueReaction(user1.ID, issue1ID, "heart")
assert.NoError(t, err)
unittest.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID})
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID})
}
func TestIssueReactionCount(t *testing.T) {
@ -98,7 +99,7 @@ func TestIssueReactionCount(t *testing.T) {
addReaction(t, user4.ID, issueID, 0, "heart")
addReaction(t, ghost.ID, issueID, 0, "-1")
reactionsList, _, err := FindReactions(db.DefaultContext, FindReactionsOptions{
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
IssueID: issueID,
})
assert.NoError(t, err)
@ -128,7 +129,7 @@ func TestIssueCommentAddReaction(t *testing.T) {
addReaction(t, user1.ID, issue1ID, comment1ID, "heart")
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID, CommentID: comment1ID})
unittest.AssertExistsAndLoadBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID, CommentID: comment1ID})
}
func TestIssueCommentDeleteReaction(t *testing.T) {
@ -147,7 +148,7 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
addReaction(t, user3.ID, issue1ID, comment1ID, "heart")
addReaction(t, user4.ID, issue1ID, comment1ID, "+1")
reactionsList, _, err := FindReactions(db.DefaultContext, FindReactionsOptions{
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
IssueID: issue1ID,
CommentID: comment1ID,
})
@ -168,7 +169,7 @@ func TestIssueCommentReactionCount(t *testing.T) {
var comment1ID int64 = 1
addReaction(t, user1.ID, issue1ID, comment1ID, "heart")
assert.NoError(t, DeleteCommentReaction(user1.ID, issue1ID, comment1ID, "heart"))
assert.NoError(t, issues_model.DeleteCommentReaction(user1.ID, issue1ID, comment1ID, "heart"))
unittest.AssertNotExistsBean(t, &Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID, CommentID: comment1ID})
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue1ID, CommentID: comment1ID})
}