diff options
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/blame.go | 4 | ||||
-rw-r--r-- | routers/web/repo/branch.go | 11 | ||||
-rw-r--r-- | routers/web/repo/commit.go | 3 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 22 | ||||
-rw-r--r-- | routers/web/repo/download.go | 3 | ||||
-rw-r--r-- | routers/web/repo/http.go | 14 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 45 | ||||
-rw-r--r-- | routers/web/repo/lfs.go | 15 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 29 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 8 | ||||
-rw-r--r-- | routers/web/repo/setting.go | 85 | ||||
-rw-r--r-- | routers/web/repo/setting_protected_branch.go | 9 | ||||
-rw-r--r-- | routers/web/repo/settings_test.go | 19 | ||||
-rw-r--r-- | routers/web/repo/tag.go | 4 | ||||
-rw-r--r-- | routers/web/repo/view.go | 19 | ||||
-rw-r--r-- | routers/web/repo/wiki_test.go | 10 |
16 files changed, 163 insertions, 137 deletions
diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index 5786aa1eb2..75246c3acb 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -11,7 +11,7 @@ import ( "net/url" "strings" - "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/base" "code.gitea.io/gitea/modules/context" @@ -103,7 +103,7 @@ func RefBlame(ctx *context.Context) { return } - blameReader, err := git.CreateBlameReader(ctx, models.RepoPath(userName, repoName), commitID, fileName) + blameReader, err := git.CreateBlameReader(ctx, repo_model.RepoPath(userName, repoName), commitID, fileName) if err != nil { ctx.NotFound("CreateBlameReader", err) return diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index 9c25180596..f6a475c3c9 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -117,7 +118,7 @@ func RestoreBranchPost(ctx *context.Context) { branchID := ctx.FormInt64("branch_id") branchName := ctx.FormString("name") - deletedBranch, err := ctx.Repo.Repository.GetDeletedBranchByID(branchID) + deletedBranch, err := models.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID) if err != nil { log.Error("GetDeletedBranchByID: %v", err) ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) @@ -179,13 +180,13 @@ func loadBranches(ctx *context.Context, skip, limit int) ([]*Branch, int) { return nil, 0 } - protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches() + protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("GetProtectedBranches", err) return nil, 0 } - repoIDToRepo := map[int64]*models.Repository{} + repoIDToRepo := map[int64]*repo_model.Repository{} repoIDToRepo[ctx.Repo.Repository.ID] = ctx.Repo.Repository repoIDToGitRepo := map[int64]*git.Repository{} @@ -223,7 +224,7 @@ func loadBranches(ctx *context.Context, skip, limit int) ([]*Branch, int) { } func loadOneBranch(ctx *context.Context, rawBranch *git.Branch, protectedBranches []*models.ProtectedBranch, - repoIDToRepo map[int64]*models.Repository, + repoIDToRepo map[int64]*repo_model.Repository, repoIDToGitRepo map[int64]*git.Repository) *Branch { log.Trace("loadOneBranch: '%s'", rawBranch.Name) @@ -311,7 +312,7 @@ func loadOneBranch(ctx *context.Context, rawBranch *git.Branch, protectedBranche func getDeletedBranches(ctx *context.Context) ([]*Branch, error) { branches := []*Branch{} - deletedBranches, err := ctx.Repo.Repository.GetDeletedBranches() + deletedBranches, err := models.GetDeletedBranches(ctx.Repo.Repository.ID) if err != nil { return branches, err } diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 993fc1c335..ef21017a31 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -12,6 +12,7 @@ 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/base" "code.gitea.io/gitea/modules/charset" @@ -382,7 +383,7 @@ func RawDiff(ctx *context.Context) { if ctx.Data["PageIsWiki"] != nil { repoPath = ctx.Repo.Repository.WikiPath() } else { - repoPath = models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + repoPath = repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) } if err := git.GetRawDiff( repoPath, diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 4cd817a399..21311ba97c 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -17,6 +17,8 @@ import ( "strings" "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" @@ -165,7 +167,7 @@ func setCsvCompareContext(ctx *context.Context) { // CompareInfo represents the collected results from ParseCompareInfo type CompareInfo struct { HeadUser *user_model.User - HeadRepo *models.Repository + HeadRepo *repo_model.Repository HeadGitRepo *git.Repository CompareInfo *git.CompareInfo BaseBranch string @@ -259,16 +261,16 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ci.HeadRepo = baseRepo } } else { - ci.HeadRepo, err = models.GetRepositoryByOwnerAndName(headInfosSplit[0], headInfosSplit[1]) + ci.HeadRepo, err = repo_model.GetRepositoryByOwnerAndName(headInfosSplit[0], headInfosSplit[1]) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByOwnerAndName", nil) } else { ctx.ServerError("GetRepositoryByOwnerAndName", err) } return nil } - if err := ci.HeadRepo.GetOwner(); err != nil { + if err := ci.HeadRepo.GetOwner(db.DefaultContext); err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", nil) } else { @@ -320,11 +322,11 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // 1. First if the baseRepo is a fork get the "RootRepo" it was // forked from - var rootRepo *models.Repository + var rootRepo *repo_model.Repository if baseRepo.IsFork { err = baseRepo.GetBaseRepo() if err != nil { - if !models.IsErrRepoNotExist(err) { + if !repo_model.IsErrRepoNotExist(err) { ctx.ServerError("Unable to find root repo", err) return nil } @@ -336,7 +338,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // 2. Now if the current user is not the owner of the baseRepo, // check if they have a fork of the base repo and offer that as // "OwnForkRepo" - var ownForkRepo *models.Repository + var ownForkRepo *repo_model.Repository if ctx.User != nil && baseRepo.OwnerID != ctx.User.ID { repo := models.GetForkedRepo(ctx.User.ID, baseRepo.ID) if repo != nil { @@ -438,7 +440,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { if rootRepo != nil && rootRepo.ID != ci.HeadRepo.ID && rootRepo.ID != baseRepo.ID { - canRead := rootRepo.CheckUnitUser(ctx.User, unit.TypeCode) + canRead := models.CheckRepoUnitUser(rootRepo, ctx.User, unit.TypeCode) if canRead { ctx.Data["RootRepo"] = rootRepo if !fileOnly { @@ -463,7 +465,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ownForkRepo.ID != ci.HeadRepo.ID && ownForkRepo.ID != baseRepo.ID && (rootRepo == nil || ownForkRepo.ID != rootRepo.ID) { - canRead := ownForkRepo.CheckUnitUser(ctx.User, unit.TypeCode) + canRead := models.CheckRepoUnitUser(ownForkRepo, ctx.User, unit.TypeCode) if canRead { ctx.Data["OwnForkRepo"] = ownForkRepo if !fileOnly { @@ -653,7 +655,7 @@ func PrepareCompareDiff( return false } -func getBranchesAndTagsForRepo(repo *models.Repository) (branches, tags []string, err error) { +func getBranchesAndTagsForRepo(repo *repo_model.Repository) (branches, tags []string, err error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, nil, err diff --git a/routers/web/repo/download.go b/routers/web/repo/download.go index 2307f736ad..430de24c69 100644 --- a/routers/web/repo/download.go +++ b/routers/web/repo/download.go @@ -6,6 +6,7 @@ package repo import ( + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/httpcache" @@ -38,7 +39,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error { pointer, _ := lfs.ReadPointer(dataRc) if pointer.IsValid() { - meta, _ := ctx.Repo.Repository.GetLFSMetaObjectByOid(pointer.Oid) + meta, _ := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) if meta == nil { if err = dataRc.Close(); err != nil { log.Error("ServeBlobOrLFS: Close: %v", err) diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 3aa8e84f57..3e12cd3267 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -20,8 +20,10 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/login" "code.gitea.io/gitea/models/perm" + 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/context" @@ -129,9 +131,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { } repoExist := true - repo, err := models.GetRepositoryByName(owner.ID, reponame) + repo, err := repo_model.GetRepositoryByName(owner.ID, reponame) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { if redirectRepoID, err := models.LookupRepoRedirect(owner.ID, reponame); err == nil { context.RedirectToRepo(ctx, redirectRepoID) return @@ -158,7 +160,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { // don't allow anonymous pulls if organization is not public if isPublicPull { - if err := repo.GetOwner(); err != nil { + if err := repo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("GetOwner", err) return } @@ -273,7 +275,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { if isWiki { // Ensure the wiki is enabled before we allow access to it if _, err := repo.GetUnit(unit.TypeWiki); err != nil { - if models.IsErrUnitTypeNotExist(err) { + if repo_model.IsErrUnitTypeNotExist(err) { ctx.HandleText(http.StatusForbidden, "repository wiki is disabled") return } @@ -295,9 +297,9 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { r.URL.Path = strings.ToLower(r.URL.Path) // blue: In case some repo name has upper case name - dir := models.RepoPath(username, reponame) + dir := repo_model.RepoPath(username, reponame) if isWiki { - dir = models.RepoPath(username, wikiRepoName) + dir = repo_model.RepoPath(username, wikiRepoName) } return &serviceHandler{cfg, w, r, dir, cfg.Env} diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 398aa26cc4..df977d2c13 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -272,7 +272,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti ctx.Data["CommitStatus"] = commitStatus // Get assignees. - ctx.Data["Assignees"], err = repo.GetAssignees() + ctx.Data["Assignees"], err = models.GetRepoAssignees(repo) if err != nil { ctx.ServerError("GetAssignees", err) return @@ -412,7 +412,7 @@ func Issues(ctx *context.Context) { } // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository -func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) { +func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) { var err error ctx.Data["OpenMilestones"], _, err = models.GetMilestones(models.GetMilestonesOption{ RepoID: repo.ID, @@ -431,7 +431,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos return } - ctx.Data["Assignees"], err = repo.GetAssignees() + ctx.Data["Assignees"], err = models.GetRepoAssignees(repo) if err != nil { ctx.ServerError("GetAssignees", err) return @@ -440,7 +440,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repos handleTeamMentions(ctx) } -func retrieveProjects(ctx *context.Context, repo *models.Repository) { +func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) { var err error @@ -479,7 +479,7 @@ type repoReviewerSelection struct { } // RetrieveRepoReviewers find all reviewers of a repository -func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue *models.Issue, canChooseReviewer bool) { +func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, issue *models.Issue, canChooseReviewer bool) { ctx.Data["CanChooseReviewer"] = canChooseReviewer originalAuthorReviews, err := models.GetReviewersFromOriginalAuthorsByIssueID(issue.ID) @@ -513,13 +513,13 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue posterID = 0 } - reviewers, err = repo.GetReviewers(ctx.User.ID, posterID) + reviewers, err = models.GetReviewers(repo, ctx.User.ID, posterID) if err != nil { ctx.ServerError("GetReviewers", err) return } - teamReviewers, err = repo.GetReviewerTeams() + teamReviewers, err = models.GetReviewerTeams(repo) if err != nil { ctx.ServerError("GetReviewerTeams", err) return @@ -659,7 +659,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *models.Repository, issue } // RetrieveRepoMetas find all the meta information of a repository -func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository, isPull bool) []*models.Label { +func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull bool) []*models.Label { if !ctx.Repo.CanWriteIssuesOrPulls(isPull) { return nil } @@ -887,11 +887,16 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull // Check milestone. milestoneID := form.MilestoneID if milestoneID > 0 { - ctx.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID) + milestone, err := models.GetMilestoneByID(milestoneID) if err != nil { ctx.ServerError("GetMilestoneByID", err) return nil, nil, 0, 0 } + if milestone.RepoID != repo.ID { + ctx.ServerError("GetMilestoneByID", err) + return nil, nil, 0, 0 + } + ctx.Data["Milestone"] = milestone ctx.Data["milestone_id"] = milestoneID } @@ -1019,7 +1024,7 @@ func NewIssuePost(ctx *context.Context) { } // roleDescriptor returns the Role Decriptor for a comment in/with the given repo, poster and issue -func roleDescriptor(repo *models.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) { +func roleDescriptor(repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) { perm, err := models.GetUserRepoPermission(repo, poster) if err != nil { return models.RoleDescriptorNone, err @@ -1085,7 +1090,7 @@ func ViewIssue(ctx *context.Context) { ctx.Redirect(com.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas)) return } - } else if err != nil && !models.IsErrUnitTypeNotExist(err) { + } else if err != nil && !repo_model.IsErrUnitTypeNotExist(err) { ctx.ServerError("GetUnit", err) return } @@ -1498,7 +1503,7 @@ func ViewIssue(ctx *context.Context) { } if perm.CanWrite(unit.TypeCode) { // Check if branch is not protected - if protected, err := pull.HeadRepo.IsProtectedBranch(pull.HeadBranch); err != nil { + if protected, err := models.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil { log.Error("IsProtectedBranch: %v", err) } else if !protected { canDelete = true @@ -1535,21 +1540,21 @@ func ViewIssue(ctx *context.Context) { prConfig := prUnit.PullRequestsConfig() // Check correct values and select default - if ms, ok := ctx.Data["MergeStyle"].(models.MergeStyle); !ok || + if ms, ok := ctx.Data["MergeStyle"].(repo_model.MergeStyle); !ok || !prConfig.IsMergeStyleAllowed(ms) { defaultMergeStyle := prConfig.GetDefaultMergeStyle() if prConfig.IsMergeStyleAllowed(defaultMergeStyle) && !ok { ctx.Data["MergeStyle"] = defaultMergeStyle } else if prConfig.AllowMerge { - ctx.Data["MergeStyle"] = models.MergeStyleMerge + ctx.Data["MergeStyle"] = repo_model.MergeStyleMerge } else if prConfig.AllowRebase { - ctx.Data["MergeStyle"] = models.MergeStyleRebase + ctx.Data["MergeStyle"] = repo_model.MergeStyleRebase } else if prConfig.AllowRebaseMerge { - ctx.Data["MergeStyle"] = models.MergeStyleRebaseMerge + ctx.Data["MergeStyle"] = repo_model.MergeStyleRebaseMerge } else if prConfig.AllowSquash { - ctx.Data["MergeStyle"] = models.MergeStyleSquash + ctx.Data["MergeStyle"] = repo_model.MergeStyleSquash } else if prConfig.AllowManualMerge { - ctx.Data["MergeStyle"] = models.MergeStyleManuallyMerged + ctx.Data["MergeStyle"] = repo_model.MergeStyleManuallyMerged } else { ctx.Data["MergeStyle"] = "" } @@ -1897,7 +1902,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { } if reviewID < 0 { // negative reviewIDs represent team requests - if err := issue.Repo.GetOwner(); err != nil { + if err := issue.Repo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("issue.Repo.GetOwner", err) return } @@ -2467,7 +2472,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error { if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 { var err error // Set RefRepo for description in template - c.RefRepo, err = models.GetRepositoryByID(c.RefRepoID) + c.RefRepo, err = repo_model.GetRepositoryByID(c.RefRepoID) if err != nil { return err } diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index b1bc06f08b..28d6b12860 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -47,7 +47,7 @@ func LFSFiles(ctx *context.Context) { if page <= 1 { page = 1 } - total, err := ctx.Repo.Repository.CountLFSMetaObjects() + total, err := models.CountLFSMetaObjects(ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("LFSFiles", err) return @@ -57,7 +57,7 @@ func LFSFiles(ctx *context.Context) { pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5) ctx.Data["Title"] = ctx.Tr("repo.settings.lfs") ctx.Data["PageIsSettingsLFS"] = true - lfsMetaObjects, err := ctx.Repo.Repository.GetLFSMetaObjects(pager.Paginater.Current(), setting.UI.ExplorePagingNum) + lfsMetaObjects, err := models.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) if err != nil { ctx.ServerError("LFSFiles", err) return @@ -215,8 +215,7 @@ func LFSLockFile(ctx *context.Context) { return } - _, err := models.CreateLFSLock(&models.LFSLock{ - Repo: ctx.Repo.Repository, + _, err := models.CreateLFSLock(ctx.Repo.Repository, &models.LFSLock{ Path: lockPath, OwnerID: ctx.User.ID, }) @@ -238,7 +237,7 @@ func LFSUnlock(ctx *context.Context) { ctx.NotFound("LFSUnlock", nil) return } - _, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.User, true) + _, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.User, true) if err != nil { ctx.ServerError("LFSUnlock", err) return @@ -256,7 +255,7 @@ func LFSFileGet(ctx *context.Context) { oid := ctx.Params("oid") ctx.Data["Title"] = oid ctx.Data["PageIsSettingsLFS"] = true - meta, err := ctx.Repo.Repository.GetLFSMetaObjectByOid(oid) + meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) if err != nil { if err == models.ErrLFSObjectNotExist { ctx.NotFound("LFSFileGet", nil) @@ -343,7 +342,7 @@ func LFSDelete(ctx *context.Context) { return } oid := ctx.Params("oid") - count, err := ctx.Repo.Repository.RemoveLFSMetaObjectByOid(oid) + count, err := models.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) if err != nil { ctx.ServerError("LFSDelete", err) return @@ -444,7 +443,7 @@ func LFSPointerFiles(ctx *context.Context) { Size: pointerBlob.Size, } - if _, err := repo.GetLFSMetaObjectByOid(pointerBlob.Oid); err != nil { + if _, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil { if err != models.ErrLFSObjectNotExist { return err } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 7593e7fbc8..b08f749cde 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -19,6 +19,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" @@ -59,10 +60,10 @@ var ( } ) -func getRepository(ctx *context.Context, repoID int64) *models.Repository { - repo, err := models.GetRepositoryByID(repoID) +func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository { + repo, err := repo_model.GetRepositoryByID(repoID) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByID", nil) } else { ctx.ServerError("GetRepositoryByID", err) @@ -89,7 +90,7 @@ func getRepository(ctx *context.Context, repoID int64) *models.Repository { return repo } -func getForkRepository(ctx *context.Context) *models.Repository { +func getForkRepository(ctx *context.Context) *repo_model.Repository { forkRepo := getRepository(ctx, ctx.ParamsInt64(":repoid")) if ctx.Written() { return nil @@ -101,7 +102,7 @@ func getForkRepository(ctx *context.Context) *models.Repository { return nil } - if err := forkRepo.GetOwner(); err != nil { + if err := forkRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("GetOwner", err) return nil } @@ -141,7 +142,7 @@ func getForkRepository(ctx *context.Context) *models.Repository { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return nil @@ -209,7 +210,7 @@ func ForkPost(ctx *context.Context) { if !traverseParentRepo.IsFork { break } - traverseParentRepo, err = models.GetRepositoryByID(traverseParentRepo.ForkID) + traverseParentRepo, err = repo_model.GetRepositoryByID(traverseParentRepo.ForkID) if err != nil { ctx.ServerError("GetRepositoryByID", err) return @@ -702,7 +703,7 @@ func ViewPullFiles(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireSimpleMDE"] = true ctx.Data["RequireTribute"] = true - if ctx.Data["Assignees"], err = ctx.Repo.Repository.GetAssignees(); err != nil { + if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil { ctx.ServerError("GetAssignees", err) return } @@ -847,7 +848,7 @@ func MergePullRequest(ctx *context.Context) { } // handle manually-merged mark - if models.MergeStyle(form.Do) == models.MergeStyleManuallyMerged { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleManuallyMerged { if err = pull_service.MergedManually(pr, ctx.User, ctx.Repo.GitRepo, form.MergeCommitID); err != nil { if models.IsErrInvalidMergeStyle(err) { ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option")) @@ -902,13 +903,13 @@ func MergePullRequest(ctx *context.Context) { message := strings.TrimSpace(form.MergeTitleField) if len(message) == 0 { - if models.MergeStyle(form.Do) == models.MergeStyleMerge { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleMerge { message = pr.GetDefaultMergeMessage() } - if models.MergeStyle(form.Do) == models.MergeStyleRebaseMerge { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleRebaseMerge { message = pr.GetDefaultMergeMessage() } - if models.MergeStyle(form.Do) == models.MergeStyleSquash { + if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleSquash { message = pr.GetDefaultSquashMessage() } } @@ -932,7 +933,7 @@ func MergePullRequest(ctx *context.Context) { return } - if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil { + if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), message); err != nil { if models.IsErrInvalidMergeStyle(err) { ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option")) ctx.Redirect(issue.Link()) @@ -1227,7 +1228,7 @@ func CleanUpPullRequest(ctx *context.Context) { } else if err = pr.LoadBaseRepo(); err != nil { ctx.ServerError("LoadBaseRepo", err) return - } else if err = pr.HeadRepo.GetOwner(); err != nil { + } else if err = pr.HeadRepo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("HeadRepo.GetOwner", err) return } diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 69bd1ed416..b4bab5960b 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -146,8 +146,8 @@ func Create(ctx *context.Context) { ctx.Data["repo_template_name"] = ctx.Tr("repo.template_select") templateID := ctx.FormInt64("template_id") if templateID > 0 { - templateRepo, err := models.GetRepositoryByID(templateID) - if err == nil && templateRepo.CheckUnitUser(ctxUser, unit.TypeCode) { + templateRepo, err := repo_model.GetRepositoryByID(templateID) + if err == nil && models.CheckRepoUnitUser(templateRepo, ctxUser, unit.TypeCode) { ctx.Data["repo_template"] = templateID ctx.Data["repo_template_name"] = templateRepo.Name } @@ -213,7 +213,7 @@ func CreatePost(ctx *context.Context) { return } - var repo *models.Repository + var repo *repo_model.Repository var err error if form.RepoTemplate > 0 { opts := models.GenerateRepoOptions{ @@ -261,7 +261,7 @@ func CreatePost(ctx *context.Context) { DefaultBranch: form.DefaultBranch, AutoInit: form.AutoInit, IsTemplate: form.Template, - TrustModel: models.ToTrustModel(form.TrustModel), + TrustModel: repo_model.ToTrustModel(form.TrustModel), }) if err == nil { log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name) diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 4fc1e91c25..68b53f2e90 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" @@ -64,6 +65,12 @@ func Settings(ctx *context.Context) { signing, _ := models.SigningKey(ctx.Repo.Repository.RepoPath()) ctx.Data["SigningKeyAvailable"] = len(signing) > 0 ctx.Data["SigningSettings"] = setting.Repository.Signing + pushMirrors, err := repo_model.GetPushMirrorsByRepoID(ctx.Repo.Repository.ID) + if err != nil { + ctx.ServerError("GetPushMirrorsByRepoID", err) + return + } + ctx.Data["PushMirrors"] = pushMirrors ctx.HTML(http.StatusOK, tplSettingsOptions) } @@ -171,7 +178,7 @@ func SettingsPost(ctx *context.Context) { } else { ctx.Repo.Mirror.NextUpdateUnix = 0 } - if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil { + if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil { ctx.Data["Err_Interval"] = true ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) return @@ -217,7 +224,7 @@ func SettingsPost(ctx *context.Context) { ctx.Repo.Mirror.LFS = form.LFS ctx.Repo.Mirror.LFSEndpoint = form.LFSEndpoint - if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil { + if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil { ctx.ServerError("UpdateMirror", err) return } @@ -274,7 +281,7 @@ func SettingsPost(ctx *context.Context) { return } - if err = models.DeletePushMirrorByID(m.ID); err != nil { + if err = repo_model.DeletePushMirrorByID(m.ID); err != nil { ctx.ServerError("DeletePushMirrorByID", err) return } @@ -315,19 +322,19 @@ func SettingsPost(ctx *context.Context) { return } - m := &models.PushMirror{ + m := &repo_model.PushMirror{ RepoID: repo.ID, Repo: repo, RemoteName: fmt.Sprintf("remote_mirror_%s", remoteSuffix), Interval: interval, } - if err := models.InsertPushMirror(m); err != nil { + if err := repo_model.InsertPushMirror(m); err != nil { ctx.ServerError("InsertPushMirror", err) return } if err := mirror_service.AddPushMirrorRemote(m, address); err != nil { - if err := models.DeletePushMirrorByID(m.ID); err != nil { + if err := repo_model.DeletePushMirrorByID(m.ID); err != nil { log.Error("DeletePushMirrorByID %v", err) } ctx.ServerError("AddPushMirrorRemote", err) @@ -339,7 +346,7 @@ func SettingsPost(ctx *context.Context) { case "advanced": var repoChanged bool - var units []models.RepoUnit + var units []repo_model.RepoUnit var deleteUnitTypes []unit_model.Type // This section doesn't require repo_name/RepoName to be set in the form, don't show it @@ -358,19 +365,19 @@ func SettingsPost(ctx *context.Context) { return } - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypeExternalWiki, - Config: &models.ExternalWikiConfig{ + Config: &repo_model.ExternalWikiConfig{ ExternalWikiURL: form.ExternalWikiURL, }, }) deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki) } else if form.EnableWiki && !form.EnableExternalWiki && !unit_model.TypeWiki.UnitGlobalDisabled() { - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypeWiki, - Config: new(models.UnitConfig), + Config: new(repo_model.UnitConfig), }) deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki) } else { @@ -393,10 +400,10 @@ func SettingsPost(ctx *context.Context) { ctx.Redirect(repo.Link() + "/settings") return } - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypeExternalTracker, - Config: &models.ExternalTrackerConfig{ + Config: &repo_model.ExternalTrackerConfig{ ExternalTrackerURL: form.ExternalTrackerURL, ExternalTrackerFormat: form.TrackerURLFormat, ExternalTrackerStyle: form.TrackerIssueStyle, @@ -404,10 +411,10 @@ func SettingsPost(ctx *context.Context) { }) deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues) } else if form.EnableIssues && !form.EnableExternalTracker && !unit_model.TypeIssues.UnitGlobalDisabled() { - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypeIssues, - Config: &models.IssuesConfig{ + Config: &repo_model.IssuesConfig{ EnableTimetracker: form.EnableTimetracker, AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime, EnableDependencies: form.EnableIssueDependencies, @@ -424,7 +431,7 @@ func SettingsPost(ctx *context.Context) { } if form.EnableProjects && !unit_model.TypeProjects.UnitGlobalDisabled() { - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypeProjects, }) @@ -433,10 +440,10 @@ func SettingsPost(ctx *context.Context) { } if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() { - units = append(units, models.RepoUnit{ + units = append(units, repo_model.RepoUnit{ RepoID: repo.ID, Type: unit_model.TypePullRequests, - Config: &models.PullRequestsConfig{ + Config: &repo_model.PullRequestsConfig{ IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace, AllowMerge: form.PullsAllowMerge, AllowRebase: form.PullsAllowRebase, @@ -445,7 +452,7 @@ func SettingsPost(ctx *context.Context) { AllowManualMerge: form.PullsAllowManualMerge, AutodetectManualMerge: form.EnableAutodetectManualMerge, DefaultDeleteBranchAfterMerge: form.DefaultDeleteBranchAfterMerge, - DefaultMergeStyle: models.MergeStyle(form.PullsDefaultMergeStyle), + DefaultMergeStyle: repo_model.MergeStyle(form.PullsDefaultMergeStyle), }, }) } else if !unit_model.TypePullRequests.UnitGlobalDisabled() { @@ -470,7 +477,7 @@ func SettingsPost(ctx *context.Context) { case "signing": changed := false - trustModel := models.ToTrustModel(form.TrustModel) + trustModel := repo_model.ToTrustModel(form.TrustModel) if trustModel != repo.TrustModel { repo.TrustModel = trustModel changed = true @@ -526,7 +533,7 @@ func SettingsPost(ctx *context.Context) { if _, err := repository.CleanUpMigrateInfo(repo); err != nil { ctx.ServerError("CleanUpMigrateInfo", err) return - } else if err = models.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil { + } else if err = repo_model.DeleteMirrorByRepoID(ctx.Repo.Repository.ID); err != nil { ctx.ServerError("DeleteMirrorByRepoID", err) return } @@ -539,7 +546,7 @@ func SettingsPost(ctx *context.Context) { ctx.Error(http.StatusNotFound) return } - if err := repo.GetOwner(); err != nil { + if err := repo.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("Convert Fork", err) return } @@ -706,7 +713,7 @@ func SettingsPost(ctx *context.Context) { return } - if err := repo.SetArchiveRepoState(true); err != nil { + if err := models.SetArchiveRepoState(repo, true); err != nil { log.Error("Tried to archive a repo: %s", err) ctx.Flash.Error(ctx.Tr("repo.settings.archive.error")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") @@ -724,7 +731,7 @@ func SettingsPost(ctx *context.Context) { return } - if err := repo.SetArchiveRepoState(false); err != nil { + if err := models.SetArchiveRepoState(repo, false); err != nil { log.Error("Tried to unarchive a repo: %s", err) ctx.Flash.Error(ctx.Tr("repo.settings.unarchive.error")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") @@ -770,14 +777,14 @@ func Collaboration(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsCollaboration"] = true - users, err := ctx.Repo.Repository.GetCollaborators(db.ListOptions{}) + users, err := models.GetCollaborators(ctx.Repo.Repository.ID, db.ListOptions{}) if err != nil { ctx.ServerError("GetCollaborators", err) return } ctx.Data["Collaborators"] = users - teams, err := ctx.Repo.Repository.GetRepoTeams() + teams, err := models.GetRepoTeams(ctx.Repo.Repository) if err != nil { ctx.ServerError("GetRepoTeams", err) return @@ -824,13 +831,13 @@ func CollaborationPost(ctx *context.Context) { return } - if got, err := ctx.Repo.Repository.IsCollaborator(u.ID); err == nil && got { + if got, err := models.IsCollaborator(ctx.Repo.Repository.ID, u.ID); err == nil && got { ctx.Flash.Error(ctx.Tr("repo.settings.add_collaborator_duplicate")) ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") return } - if err = ctx.Repo.Repository.AddCollaborator(u); err != nil { + if err = models.AddCollaborator(ctx.Repo.Repository, u); err != nil { ctx.ServerError("AddCollaborator", err) return } @@ -845,7 +852,8 @@ func CollaborationPost(ctx *context.Context) { // ChangeCollaborationAccessMode response for changing access of a collaboration func ChangeCollaborationAccessMode(ctx *context.Context) { - if err := ctx.Repo.Repository.ChangeCollaborationAccessMode( + if err := models.ChangeCollaborationAccessMode( + ctx.Repo.Repository, ctx.FormInt64("uid"), perm.AccessMode(ctx.FormInt("mode"))); err != nil { log.Error("ChangeCollaborationAccessMode: %v", err) @@ -854,7 +862,7 @@ func ChangeCollaborationAccessMode(ctx *context.Context) { // DeleteCollaboration delete a collaboration for a repository func DeleteCollaboration(ctx *context.Context) { - if err := ctx.Repo.Repository.DeleteCollaboration(ctx.FormInt64("id")); err != nil { + if err := models.DeleteCollaboration(ctx.Repo.Repository, ctx.FormInt64("id")); err != nil { ctx.Flash.Error("DeleteCollaboration: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success")) @@ -937,7 +945,7 @@ func DeleteTeam(ctx *context.Context) { } // parseOwnerAndRepo get repos by owner -func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *models.Repository) { +func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *repo_model.Repository) { owner, err := user_model.GetUserByName(ctx.Params(":username")) if err != nil { if user_model.IsErrUserNotExist(err) { @@ -948,9 +956,9 @@ func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *models.Reposito return nil, nil } - repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame")) + repo, err := repo_model.GetRepositoryByName(owner.ID, ctx.Params(":reponame")) if err != nil { - if models.IsErrRepoNotExist(err) { + if repo_model.IsErrRepoNotExist(err) { ctx.NotFound("GetRepositoryByName", err) } else { ctx.ServerError("GetRepositoryByName", err) @@ -1136,7 +1144,7 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error { if !(st.IsImage() && !st.IsSvgImage()) { return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } - if err = ctxRepo.UploadAvatar(data); err != nil { + if err = models.UploadRepoAvatar(ctxRepo, data); err != nil { return fmt.Errorf("UploadAvatar: %v", err) } return nil @@ -1156,23 +1164,24 @@ func SettingsAvatar(ctx *context.Context) { // SettingsDeleteAvatar delete repository avatar func SettingsDeleteAvatar(ctx *context.Context) { - if err := ctx.Repo.Repository.DeleteAvatar(); err != nil { + if err := models.DeleteRepoAvatar(ctx.Repo.Repository); err != nil { ctx.Flash.Error(fmt.Sprintf("DeleteAvatar: %v", err)) } ctx.Redirect(ctx.Repo.RepoLink + "/settings") } -func selectPushMirrorByForm(form *forms.RepoSettingForm, repo *models.Repository) (*models.PushMirror, error) { +func selectPushMirrorByForm(form *forms.RepoSettingForm, repo *repo_model.Repository) (*repo_model.PushMirror, error) { id, err := strconv.ParseInt(form.PushMirrorID, 10, 64) if err != nil { return nil, err } - if err = repo.LoadPushMirrors(); err != nil { + pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID) + if err != nil { return nil, err } - for _, m := range repo.PushMirrors { + for _, m := range pushMirrors { if m.ID == id { return m, nil } diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go index e0580ac6de..1435b820ad 100644 --- a/routers/web/repo/setting_protected_branch.go +++ b/routers/web/repo/setting_protected_branch.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -29,7 +30,7 @@ func ProtectedBranch(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsBranches"] = true - protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches() + protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("GetProtectedBranches", err) return @@ -82,7 +83,7 @@ func ProtectedBranchPost(ctx *context.Context) { return } } - if err := repo.UpdateDefaultBranch(); err != nil { + if err := repo_model.UpdateDefaultBranch(repo); err != nil { ctx.ServerError("SetDefaultBranch", err) return } @@ -123,7 +124,7 @@ func SettingsProtectedBranch(c *context.Context) { } } - users, err := c.Repo.Repository.GetReaders() + users, err := models.GetRepoReaders(c.Repo.Repository) if err != nil { c.ServerError("Repo.Repository.GetReaders", err) return @@ -279,7 +280,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { ctx.Redirect(fmt.Sprintf("%s/settings/branches/%s", ctx.Repo.RepoLink, util.PathEscapeSegments(branch))) } else { if protectBranch != nil { - if err := ctx.Repo.Repository.DeleteProtectedBranch(protectBranch.ID); err != nil { + if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil { ctx.ServerError("DeleteProtectedBranch", err) return } diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index 5f997bc36b..fe6e9b52ba 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + 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/context" @@ -112,7 +113,7 @@ func TestCollaborationPost(t *testing.T) { Type: user_model.UserTypeIndividual, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 2, Owner: u, } @@ -128,7 +129,7 @@ func TestCollaborationPost(t *testing.T) { assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) - exists, err := re.IsCollaborator(4) + exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) assert.True(t, exists) } @@ -172,7 +173,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { Type: user_model.UserTypeIndividual, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 2, Owner: u, } @@ -188,7 +189,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) - exists, err := re.IsCollaborator(4) + exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) assert.True(t, exists) @@ -238,7 +239,7 @@ func TestAddTeamPost(t *testing.T) { OrgID: 26, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 43, Owner: org, OwnerID: 26, @@ -278,7 +279,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { OrgID: 26, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 43, Owner: org, OwnerID: 26, @@ -319,7 +320,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { OrgID: 26, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 43, Owner: org, OwnerID: 26, @@ -355,7 +356,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { Type: user_model.UserTypeOrganization, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 43, Owner: org, OwnerID: 26, @@ -393,7 +394,7 @@ func TestDeleteTeam(t *testing.T) { OrgID: 3, } - re := &models.Repository{ + re := &repo_model.Repository{ ID: 3, Owner: org, OwnerID: 3, diff --git a/routers/web/repo/tag.go b/routers/web/repo/tag.go index 671c388cb1..0114704f82 100644 --- a/routers/web/repo/tag.go +++ b/routers/web/repo/tag.go @@ -135,14 +135,14 @@ func setTagsContext(ctx *context.Context) error { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsTags"] = true - protectedTags, err := ctx.Repo.Repository.GetProtectedTags() + protectedTags, err := models.GetProtectedTags(ctx.Repo.Repository.ID) if err != nil { ctx.ServerError("GetProtectedTags", err) return err } ctx.Data["ProtectedTags"] = protectedTags - users, err := ctx.Repo.Repository.GetReaders() + users, err := models.GetRepoReaders(ctx.Repo.Repository) if err != nil { ctx.ServerError("Repo.Repository.GetReaders", err) return err diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 33420aab3b..bc8396ab79 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" @@ -269,7 +270,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { if isTextFile && setting.LFS.StartServer { pointer, _ := lfs.ReadPointerFromBuffer(buf) if pointer.IsValid() { - meta, err := ctx.Repo.Repository.GetLFSMetaObjectByOid(pointer.Oid) + meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) if err != nil && err != models.ErrLFSObjectNotExist { ctx.ServerError("GetLFSMetaObject", err) return @@ -394,7 +395,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st if isTextFile && setting.LFS.StartServer { pointer, _ := lfs.ReadPointerFromBuffer(buf) if pointer.IsValid() { - meta, err := ctx.Repo.Repository.GetLFSMetaObjectByOid(pointer.Oid) + meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) if err != nil && err != models.ErrLFSObjectNotExist { ctx.ServerError("GetLFSMetaObject", err) return @@ -443,7 +444,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource // Check LFS Lock - lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath) + lfsLock, err := models.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath) ctx.Data["LFSLock"] = lfsLock if err != nil { ctx.ServerError("GetTreePathLock", err) @@ -641,7 +642,7 @@ func checkHomeCodeViewable(ctx *context.Context) { if ctx.IsSigned { // Set repo notification-status read if unread - if err := ctx.Repo.Repository.ReadBy(ctx.User.ID); err != nil { + if err := models.SetRepoReadBy(ctx.Repo.Repository.ID, ctx.User.ID); err != nil { ctx.ServerError("ReadBy", err) return } @@ -808,7 +809,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri } func renderLanguageStats(ctx *context.Context) { - langs, err := ctx.Repo.Repository.GetTopLanguageStats(5) + langs, err := repo_model.GetTopLanguageStats(ctx.Repo.Repository, 5) if err != nil { ctx.ServerError("Repo.GetTopLanguageStats", err) return @@ -926,7 +927,9 @@ func Watchers(ctx *context.Context) { ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers") ctx.Data["PageIsWatchers"] = true - RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, ctx.Repo.Repository.GetWatchers, tplWatchers) + RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, func(opts db.ListOptions) ([]*user_model.User, error) { + return models.GetRepoWatchers(ctx.Repo.Repository.ID, opts) + }, tplWatchers) } // Stars render repository's starred users @@ -951,7 +954,7 @@ func Forks(ctx *context.Context) { pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5) ctx.Data["Page"] = pager - forks, err := ctx.Repo.Repository.GetForks(db.ListOptions{ + forks, err := models.GetForks(ctx.Repo.Repository, db.ListOptions{ Page: pager.Paginater.Current(), PageSize: models.ItemsPerPage, }) @@ -961,7 +964,7 @@ func Forks(ctx *context.Context) { } for _, fork := range forks { - if err = fork.GetOwner(); err != nil { + if err = fork.GetOwner(db.DefaultContext); err != nil { ctx.ServerError("GetOwner", err) return } diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 87f2779c1a..1bfda50d19 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -9,7 +9,7 @@ import ( "net/http" "testing" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/test" @@ -23,7 +23,7 @@ import ( const content = "Wiki contents for unit tests" const message = "Wiki commit message for unit tests" -func wikiEntry(t *testing.T, repo *models.Repository, wikiName string) *git.TreeEntry { +func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName string) *git.TreeEntry { wikiRepo, err := git.OpenRepository(repo.WikiPath()) assert.NoError(t, err) defer wikiRepo.Close() @@ -39,7 +39,7 @@ func wikiEntry(t *testing.T, repo *models.Repository, wikiName string) *git.Tree return nil } -func wikiContent(t *testing.T, repo *models.Repository, wikiName string) string { +func wikiContent(t *testing.T, repo *repo_model.Repository, wikiName string) string { entry := wikiEntry(t, repo, wikiName) if !assert.NotNil(t, entry) { return "" @@ -52,11 +52,11 @@ func wikiContent(t *testing.T, repo *models.Repository, wikiName string) string return string(bytes) } -func assertWikiExists(t *testing.T, repo *models.Repository, wikiName string) { +func assertWikiExists(t *testing.T, repo *repo_model.Repository, wikiName string) { assert.NotNil(t, wikiEntry(t, repo, wikiName)) } -func assertWikiNotExists(t *testing.T, repo *models.Repository, wikiName string) { +func assertWikiNotExists(t *testing.T, repo *repo_model.Repository, wikiName string) { assert.Nil(t, wikiEntry(t, repo, wikiName)) } |