mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move repository model into models/repo (#17933)
* Some refactors related repository model * Move more methods out of repository * Move repository into models/repo * Fix test * Fix test * some improvements * Remove unnecessary function
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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/references"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
@@ -85,7 +86,7 @@ func issueAddTime(issue *models.Issue, doer *user_model.User, time time.Time, ti
|
||||
|
||||
// getIssueFromRef returns the issue referenced by a ref. Returns a nil *Issue
|
||||
// if the provided ref references a non-existent issue.
|
||||
func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error) {
|
||||
func getIssueFromRef(repo *repo_model.Repository, index int64) (*models.Issue, error) {
|
||||
issue, err := models.GetIssueByIndex(repo.ID, index)
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
@@ -97,7 +98,7 @@ func getIssueFromRef(repo *models.Repository, index int64) (*models.Issue, error
|
||||
}
|
||||
|
||||
// UpdateIssuesCommit checks if issues are manipulated by commit message.
|
||||
func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error {
|
||||
func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, commits []*repository.PushCommit, branchName string) error {
|
||||
// Commits are appended in the reverse order.
|
||||
for i := len(commits) - 1; i >= 0; i-- {
|
||||
c := commits[i]
|
||||
@@ -108,7 +109,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *models.Repository, commits
|
||||
}
|
||||
|
||||
refMarked := make(map[markKey]bool)
|
||||
var refRepo *models.Repository
|
||||
var refRepo *repo_model.Repository
|
||||
var refIssue *models.Issue
|
||||
var err error
|
||||
for _, ref := range references.FindAllIssueReferences(c.Message) {
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
@@ -46,7 +47,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
}
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||
repo.Owner = user
|
||||
|
||||
commentBean := &models.Comment{
|
||||
@@ -75,7 +76,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
Message: "close #1",
|
||||
},
|
||||
}
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
|
||||
commentBean = &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -101,7 +102,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
Message: "close " + setting.AppURL + repo.FullName() + "/pulls/1",
|
||||
},
|
||||
}
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
|
||||
commentBean = &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef3",
|
||||
@@ -132,7 +133,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
|
||||
}
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
||||
repo.Owner = user
|
||||
|
||||
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
|
||||
@@ -159,7 +160,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -194,7 +195,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -229,7 +230,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -272,7 +273,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 6}).(*repo_model.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef3",
|
||||
|
@@ -7,6 +7,7 @@ package issue
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// NewIssue creates new issue with labels for repository.
|
||||
func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
|
||||
func NewIssue(repo *repo_model.Repository, issue *models.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
|
||||
if err := models.NewIssue(repo, issue, labelIDs, uuids); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user