diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-10 09:27:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 09:27:50 +0800 |
commit | 719bddcd76610a63dadc8555760072957a11cf30 (patch) | |
tree | 0df26092fba7e3e21444fe493e6b349473b6b0cb /services/issue | |
parent | fb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff) | |
download | gitea-719bddcd76610a63dadc8555760072957a11cf30.tar.gz gitea-719bddcd76610a63dadc8555760072957a11cf30.zip |
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
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/commit.go | 7 | ||||
-rw-r--r-- | services/issue/commit_test.go | 17 | ||||
-rw-r--r-- | services/issue/issue.go | 3 |
3 files changed, 15 insertions, 12 deletions
diff --git a/services/issue/commit.go b/services/issue/commit.go index 3e2f6c471b..0dda5f202f 100644 --- a/services/issue/commit.go +++ b/services/issue/commit.go @@ -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) { diff --git a/services/issue/commit_test.go b/services/issue/commit_test.go index 1addbd080f..37283a7890 100644 --- a/services/issue/commit_test.go +++ b/services/issue/commit_test.go @@ -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", diff --git a/services/issue/issue.go b/services/issue/issue.go index cb34a9eacd..ef2894b929 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -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 } |