forked from forgejo/forgejo
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:
parent
fb8166c6c6
commit
719bddcd76
301 changed files with 3193 additions and 2919 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"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/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -30,7 +32,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
|||
if err := issue.LoadRepo(); err != nil {
|
||||
return &api.Issue{}
|
||||
}
|
||||
if err := issue.Repo.GetOwner(); err != nil {
|
||||
if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
|
||||
return &api.Issue{}
|
||||
}
|
||||
|
||||
|
@ -129,10 +131,10 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) {
|
|||
result := api.StopWatches(make([]api.StopWatch, 0, len(sws)))
|
||||
|
||||
issueCache := make(map[int64]*models.Issue)
|
||||
repoCache := make(map[int64]*models.Repository)
|
||||
repoCache := make(map[int64]*repo_model.Repository)
|
||||
var (
|
||||
issue *models.Issue
|
||||
repo *models.Repository
|
||||
repo *repo_model.Repository
|
||||
ok bool
|
||||
err error
|
||||
)
|
||||
|
@ -147,7 +149,7 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) {
|
|||
}
|
||||
repo, ok = repoCache[issue.RepoID]
|
||||
if !ok {
|
||||
repo, err = models.GetRepositoryByID(issue.RepoID)
|
||||
repo, err = repo_model.GetRepositoryByID(issue.RepoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -176,7 +178,7 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList {
|
|||
}
|
||||
|
||||
// ToLabel converts Label to API format
|
||||
func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User) *api.Label {
|
||||
func ToLabel(label *models.Label, repo *repo_model.Repository, org *user_model.User) *api.Label {
|
||||
result := &api.Label{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
|
@ -203,7 +205,7 @@ func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User)
|
|||
}
|
||||
|
||||
// ToLabelList converts list of Label to API format
|
||||
func ToLabelList(labels []*models.Label, repo *models.Repository, org *user_model.User) []*api.Label {
|
||||
func ToLabelList(labels []*models.Label, repo *repo_model.Repository, org *user_model.User) []*api.Label {
|
||||
result := make([]*api.Label, len(labels))
|
||||
for i := range labels {
|
||||
result[i] = ToLabel(labels[i], repo, org)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue