mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move some repository related code into sub package (#19711)
* Move some repository related code into sub package * Move more repository functions out of models * Fix lint * Some performance optimization for webhooks and others * some refactors * Fix lint * Fix * Update modules/repository/delete.go Co-authored-by: delvh <dev.lh@web.de> * Fix test * Merge * Fix test * Fix test * Fix test * Fix test Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/upload"
|
||||
"code.gitea.io/gitea/routers/common"
|
||||
"code.gitea.io/gitea/services/attachment"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
|
||||
// UploadIssueAttachment response for Issue/PR attachments
|
||||
@@ -95,7 +95,7 @@ func GetAttachment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
repository, unitType, err := models.LinkedRepository(attach)
|
||||
repository, unitType, err := repo_service.LinkedRepository(attach)
|
||||
if err != nil {
|
||||
ctx.ServerError("LinkedRepository", err)
|
||||
return
|
||||
|
@@ -457,7 +457,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||
if rootRepo != nil &&
|
||||
rootRepo.ID != ci.HeadRepo.ID &&
|
||||
rootRepo.ID != baseRepo.ID {
|
||||
canRead := models.CheckRepoUnitUser(rootRepo, ctx.Doer, unit.TypeCode)
|
||||
canRead := models.CheckRepoUnitUser(ctx, rootRepo, ctx.Doer, unit.TypeCode)
|
||||
if canRead {
|
||||
ctx.Data["RootRepo"] = rootRepo
|
||||
if !fileOnly {
|
||||
@@ -482,7 +482,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||
ownForkRepo.ID != ci.HeadRepo.ID &&
|
||||
ownForkRepo.ID != baseRepo.ID &&
|
||||
(rootRepo == nil || ownForkRepo.ID != rootRepo.ID) {
|
||||
canRead := models.CheckRepoUnitUser(ownForkRepo, ctx.Doer, unit.TypeCode)
|
||||
canRead := models.CheckRepoUnitUser(ctx, ownForkRepo, ctx.Doer, unit.TypeCode)
|
||||
if canRead {
|
||||
ctx.Data["OwnForkRepo"] = ownForkRepo
|
||||
if !fileOnly {
|
||||
|
@@ -49,6 +49,7 @@ import (
|
||||
"code.gitea.io/gitea/services/forms"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -283,7 +284,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
ctx.Data["CommitStatuses"] = commitStatuses
|
||||
|
||||
// Get assignees.
|
||||
ctx.Data["Assignees"], err = models.GetRepoAssignees(repo)
|
||||
ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetAssignees", err)
|
||||
return
|
||||
@@ -441,7 +442,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Assignees"], err = models.GetRepoAssignees(repo)
|
||||
ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetAssignees", err)
|
||||
return
|
||||
@@ -522,13 +523,13 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
|
||||
posterID = 0
|
||||
}
|
||||
|
||||
reviewers, err = models.GetReviewers(repo, ctx.Doer.ID, posterID)
|
||||
reviewers, err = repo_model.GetReviewers(ctx, repo, ctx.Doer.ID, posterID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReviewers", err)
|
||||
return
|
||||
}
|
||||
|
||||
teamReviewers, err = models.GetReviewerTeams(repo)
|
||||
teamReviewers, err = repo_service.GetReviewerTeams(repo)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReviewerTeams", err)
|
||||
return
|
||||
@@ -2160,7 +2161,7 @@ func SearchIssues(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// find repos user can access (for issue search)
|
||||
opts := &models.SearchRepoOptions{
|
||||
opts := &repo_model.SearchRepoOptions{
|
||||
Private: false,
|
||||
AllPublic: true,
|
||||
TopicOnly: false,
|
||||
@@ -2206,8 +2207,8 @@ func SearchIssues(ctx *context.Context) {
|
||||
opts.TeamID = team.ID
|
||||
}
|
||||
|
||||
repoCond := models.SearchRepositoryCondition(opts)
|
||||
repoIDs, _, err := models.SearchRepositoryIDs(opts)
|
||||
repoCond := repo_model.SearchRepositoryCondition(opts)
|
||||
repoIDs, _, err := repo_model.SearchRepositoryIDs(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err.Error())
|
||||
return
|
||||
|
@@ -758,7 +758,7 @@ func ViewPullFiles(ctx *context.Context) {
|
||||
setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
|
||||
ctx.Data["RequireTribute"] = true
|
||||
if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil {
|
||||
if ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository); err != nil {
|
||||
ctx.ServerError("GetAssignees", err)
|
||||
return
|
||||
}
|
||||
|
@@ -152,7 +152,7 @@ func Create(ctx *context.Context) {
|
||||
templateID := ctx.FormInt64("template_id")
|
||||
if templateID > 0 {
|
||||
templateRepo, err := repo_model.GetRepositoryByID(templateID)
|
||||
if err == nil && models.CheckRepoUnitUser(templateRepo, ctxUser, unit.TypeCode) {
|
||||
if err == nil && models.CheckRepoUnitUser(ctx, templateRepo, ctxUser, unit.TypeCode) {
|
||||
ctx.Data["repo_template"] = templateID
|
||||
ctx.Data["repo_template_name"] = templateRepo.Name
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func CreatePost(ctx *context.Context) {
|
||||
var repo *repo_model.Repository
|
||||
var err error
|
||||
if form.RepoTemplate > 0 {
|
||||
opts := models.GenerateRepoOptions{
|
||||
opts := repo_module.GenerateRepoOptions{
|
||||
Name: form.RepoName,
|
||||
Description: form.Description,
|
||||
Private: form.Private,
|
||||
@@ -304,7 +304,7 @@ func Action(ctx *context.Context) {
|
||||
|
||||
ctx.Repo.Repository.Description = ctx.FormString("desc")
|
||||
ctx.Repo.Repository.Website = ctx.FormString("site")
|
||||
err = models.UpdateRepository(ctx.Repo.Repository, false)
|
||||
err = repo_service.UpdateRepository(ctx.Repo.Repository, false)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -509,7 +509,7 @@ func InitiateDownload(ctx *context.Context) {
|
||||
|
||||
// SearchRepo repositories via options
|
||||
func SearchRepo(ctx *context.Context) {
|
||||
opts := &models.SearchRepoOptions{
|
||||
opts := &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: ctx.FormInt("page"),
|
||||
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
||||
@@ -581,7 +581,7 @@ func SearchRepo(ctx *context.Context) {
|
||||
}
|
||||
|
||||
var err error
|
||||
repos, count, err := models.SearchRepository(opts)
|
||||
repos, count, err := repo_model.SearchRepository(opts)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||
OK: false,
|
||||
|
@@ -168,7 +168,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
repo.IsPrivate = form.Private
|
||||
if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
|
||||
if err := repo_service.UpdateRepository(repo, visibilityChanged); err != nil {
|
||||
ctx.ServerError("UpdateRepository", err)
|
||||
return
|
||||
}
|
||||
@@ -491,7 +491,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
if repoChanged {
|
||||
if err := models.UpdateRepository(repo, false); err != nil {
|
||||
if err := repo_service.UpdateRepository(repo, false); err != nil {
|
||||
ctx.ServerError("UpdateRepository", err)
|
||||
return
|
||||
}
|
||||
@@ -510,7 +510,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if changed {
|
||||
if err := models.UpdateRepository(repo, false); err != nil {
|
||||
if err := repo_service.UpdateRepository(repo, false); err != nil {
|
||||
ctx.ServerError("UpdateRepository", err)
|
||||
return
|
||||
}
|
||||
@@ -530,7 +530,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
repo.IsFsckEnabled = form.EnableHealthCheck
|
||||
}
|
||||
|
||||
if err := models.UpdateRepository(repo, false); err != nil {
|
||||
if err := repo_service.UpdateRepository(repo, false); err != nil {
|
||||
ctx.ServerError("UpdateRepository", err)
|
||||
return
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/typesniffer"
|
||||
@@ -905,7 +906,7 @@ func renderCode(ctx *context.Context) {
|
||||
ctx.ServerError("UpdateRepositoryCols", err)
|
||||
return
|
||||
}
|
||||
if err = models.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil {
|
||||
if err = repo_module.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil {
|
||||
ctx.ServerError("UpdateRepoSize", err)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user