From 719bddcd76610a63dadc8555760072957a11cf30 Mon Sep 17 00:00:00 2001
From: Lunny Xiao <xiaolunwen@gmail.com>
Date: Fri, 10 Dec 2021 09:27:50 +0800
Subject: 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
---
 routers/web/user/home.go | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

(limited to 'routers/web/user/home.go')

diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index ca2705a42f..d3883571ed 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -16,6 +16,7 @@ import (
 
 	"code.gitea.io/gitea/models"
 	"code.gitea.io/gitea/models/db"
+	repo_model "code.gitea.io/gitea/models/repo"
 	"code.gitea.io/gitea/models/unit"
 	user_model "code.gitea.io/gitea/models/user"
 	"code.gitea.io/gitea/modules/base"
@@ -96,7 +97,7 @@ func Dashboard(ctx *context.Context) {
 	}
 
 	var err error
-	var mirrors []*models.Repository
+	var mirrors []*repo_model.Repository
 	if ctxUser.IsOrganization() {
 		var env models.AccessibleReposEnvironment
 		if ctx.Org.Team != nil {
@@ -114,7 +115,7 @@ func Dashboard(ctx *context.Context) {
 			return
 		}
 	} else {
-		mirrors, err = models.GetUserMirrorRepositories(ctxUser.ID)
+		mirrors, err = repo_model.GetUserMirrorRepositories(ctxUser.ID)
 		if err != nil {
 			ctx.ServerError("GetUserMirrorRepositories", err)
 			return
@@ -122,7 +123,7 @@ func Dashboard(ctx *context.Context) {
 	}
 	ctx.Data["MaxShowRepoNum"] = setting.UI.User.RepoPagingNum
 
-	if err := models.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil {
+	if err := repo_model.MirrorRepositoryList(mirrors).LoadAttributes(); err != nil {
 		ctx.ServerError("MirrorRepositoryList.LoadAttributes", err)
 		return
 	}
@@ -524,7 +525,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
 	// showReposMap maps repository IDs to their Repository pointers.
 	showReposMap, err := repoIDMap(ctxUser, issueCountByRepo, unitType)
 	if err != nil {
-		if models.IsErrRepoNotExist(err) {
+		if repo_model.IsErrRepoNotExist(err) {
 			ctx.NotFound("GetRepositoryByID", err)
 			return
 		}
@@ -795,15 +796,15 @@ func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.I
 	return issueIDsFromSearch, nil
 }
 
-func repoIDMap(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) {
-	repoByID := make(map[int64]*models.Repository, len(issueCountByRepo))
+func repoIDMap(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) {
+	repoByID := make(map[int64]*repo_model.Repository, len(issueCountByRepo))
 	for id := range issueCountByRepo {
 		if id <= 0 {
 			continue
 		}
 		if _, ok := repoByID[id]; !ok {
-			repo, err := models.GetRepositoryByID(id)
-			if models.IsErrRepoNotExist(err) {
+			repo, err := repo_model.GetRepositoryByID(id)
+			if repo_model.IsErrRepoNotExist(err) {
 				return nil, err
 			} else if err != nil {
 				return nil, fmt.Errorf("GetRepositoryByID: [%d]%v", id, err)
-- 
cgit v1.2.3