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
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"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/context"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
@ -91,12 +92,12 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := models.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
isDir, err := util.IsDir(models.RepoPath(ctxUser.Name, repoName))
|
||||
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -153,12 +154,12 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := models.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
isDir, err := util.IsDir(models.RepoPath(ctxUser.Name, repoName))
|
||||
isDir, err := util.IsDir(repo_model.RepoPath(ctxUser.Name, repoName))
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -71,6 +71,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
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"
|
||||
|
@ -157,9 +158,9 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
ctx.Repo.Owner = owner
|
||||
|
||||
// Get repository.
|
||||
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) {
|
||||
redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName)
|
||||
if err == nil {
|
||||
context.RedirectToRepo(ctx.Context, redirectRepoID)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -512,10 +513,10 @@ func GetTeamRepos(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// getRepositoryByParams get repository by a team's organization ID and repo name
|
||||
func getRepositoryByParams(ctx *context.APIContext) *models.Repository {
|
||||
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
|
||||
func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository {
|
||||
repo, err := repo_model.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if repo_model.IsErrRepoNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByName", err)
|
||||
|
|
|
@ -69,7 +69,7 @@ func GetBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branchName)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branchName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -210,7 +210,7 @@ func CreateBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branch.Name)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch.Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -270,7 +270,7 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
branchProtection, err := ctx.Repo.Repository.GetBranchProtection(branches[i].Name)
|
||||
branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branches[i].Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err)
|
||||
return
|
||||
|
@ -354,7 +354,7 @@ func ListBranchProtections(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/BranchProtectionList"
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
bps, err := repo.GetProtectedBranches()
|
||||
bps, err := models.GetProtectedBranches(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetProtectedBranches", err)
|
||||
return
|
||||
|
@ -811,7 +811,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.DeleteProtectedBranch(bp.ID); err != nil {
|
||||
if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -48,13 +49,13 @@ func ListCollaborators(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
count, err := ctx.Repo.Repository.CountCollaborators()
|
||||
count, err := models.CountCollaborators(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
collaborators, err := ctx.Repo.Repository.GetCollaborators(utils.GetListOptions(ctx))
|
||||
collaborators, err := models.GetCollaborators(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||
return
|
||||
|
@ -109,7 +110,7 @@ func IsCollaborator(ctx *context.APIContext) {
|
|||
}
|
||||
return
|
||||
}
|
||||
isColab, err := ctx.Repo.Repository.IsCollaborator(user.ID)
|
||||
isColab, err := models.IsCollaborator(ctx.Repo.Repository.ID, user.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsCollaborator", err)
|
||||
return
|
||||
|
@ -171,13 +172,13 @@ func AddCollaborator(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil {
|
||||
if err := models.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AddCollaborator", err)
|
||||
return
|
||||
}
|
||||
|
||||
if form.Permission != nil {
|
||||
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, perm.ParseAccessMode(*form.Permission)); err != nil {
|
||||
if err := models.ChangeCollaborationAccessMode(ctx.Repo.Repository, collaborator.ID, perm.ParseAccessMode(*form.Permission)); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ChangeCollaborationAccessMode", err)
|
||||
return
|
||||
}
|
||||
|
@ -225,7 +226,7 @@ func DeleteCollaborator(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.DeleteCollaboration(collaborator.ID); err != nil {
|
||||
if err := models.DeleteCollaboration(ctx.Repo.Repository, collaborator.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteCollaboration", err)
|
||||
return
|
||||
}
|
||||
|
@ -254,7 +255,7 @@ func GetReviewers(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
reviewers, err := ctx.Repo.Repository.GetReviewers(ctx.User.ID, 0)
|
||||
reviewers, err := models.GetReviewers(ctx.Repo.Repository, ctx.User.ID, 0)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||
return
|
||||
|
@ -284,7 +285,7 @@ func GetAssignees(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
assignees, err := ctx.Repo.Repository.GetAssignees()
|
||||
assignees, err := models.GetRepoAssignees(ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
|
||||
return
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"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/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -249,7 +249,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/string"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
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,
|
||||
ctx.Params(":sha"),
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -119,7 +120,7 @@ func GetArchive(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
||||
repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
|
|
|
@ -50,7 +50,7 @@ func ListForks(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
forks, err := ctx.Repo.Repository.GetForks(utils.GetListOptions(ctx))
|
||||
forks, err := models.GetForks(ctx.Repo.Repository, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetForks", err)
|
||||
return
|
||||
|
|
|
@ -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/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -21,12 +22,12 @@ import (
|
|||
)
|
||||
|
||||
// appendPrivateInformation appends the owner and key type information to api.PublicKey
|
||||
func appendPrivateInformation(apiKey *api.DeployKey, key *models.DeployKey, repository *models.Repository) (*api.DeployKey, error) {
|
||||
func appendPrivateInformation(apiKey *api.DeployKey, key *models.DeployKey, repository *repo_model.Repository) (*api.DeployKey, error) {
|
||||
apiKey.ReadOnly = key.Mode == perm.AccessModeRead
|
||||
if repository.ID == key.RepoID {
|
||||
apiKey.Repository = convert.ToRepo(repository, key.Mode)
|
||||
} else {
|
||||
repo, err := models.GetRepositoryByID(key.RepoID)
|
||||
repo, err := repo_model.GetRepositoryByID(key.RepoID)
|
||||
if err != nil {
|
||||
return apiKey, err
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
type languageResponse []*models.LanguageStat
|
||||
type languageResponse []*repo_model.LanguageStat
|
||||
|
||||
func (l languageResponse) MarshalJSON() ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
|
@ -68,7 +68,7 @@ func GetLanguages(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LanguageStatistics"
|
||||
|
||||
langs, err := ctx.Repo.Repository.GetLanguageStats()
|
||||
langs, err := repo_model.GetLanguageStats(ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
log.Error("GetLanguageStats failed: %v", err)
|
||||
ctx.InternalServerError(err)
|
||||
|
|
|
@ -14,6 +14,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"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -173,7 +174,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
GitServiceType: gitServiceType,
|
||||
IsPrivate: opts.Private,
|
||||
IsMirror: opts.Mirror,
|
||||
Status: models.RepositoryBeingMigrated,
|
||||
Status: repo_model.RepositoryBeingMigrated,
|
||||
})
|
||||
if err != nil {
|
||||
handleMigrateError(ctx, repoOwner, remoteAddr, err)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
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"
|
||||
|
@ -763,10 +764,10 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// 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.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", models.MergeStyle(form.Do)))
|
||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||
return
|
||||
}
|
||||
if strings.Contains(err.Error(), "Wrong commit ID") {
|
||||
|
@ -818,15 +819,15 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if len(form.Do) == 0 {
|
||||
form.Do = string(models.MergeStyleMerge)
|
||||
form.Do = string(repo_model.MergeStyleMerge)
|
||||
}
|
||||
|
||||
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.MergeStyleSquash {
|
||||
if repo_model.MergeStyle(form.Do) == repo_model.MergeStyleSquash {
|
||||
message = pr.GetDefaultSquashMessage()
|
||||
}
|
||||
}
|
||||
|
@ -836,9 +837,9 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
message += "\n\n" + form.MergeMessageField
|
||||
}
|
||||
|
||||
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.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", models.MergeStyle(form.Do)))
|
||||
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
|
||||
return
|
||||
} else if models.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(models.ErrMergeConflicts)
|
||||
|
@ -901,7 +902,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
ctx.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) {
|
||||
func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *repo_model.Repository, *git.Repository, *git.CompareInfo, string, string) {
|
||||
baseRepo := ctx.Repo.Repository
|
||||
|
||||
// Get compared branches information
|
||||
|
@ -966,7 +967,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||
headRepo = ctx.Repo.Repository
|
||||
headGitRepo = ctx.Repo.GitRepo
|
||||
} else {
|
||||
headGitRepo, err = git.OpenRepository(models.RepoPath(headUser.Name, headRepo.Name))
|
||||
headGitRepo, err = git.OpenRepository(repo_model.RepoPath(headUser.Name, headRepo.Name))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
|
||||
return nil, nil, nil, nil, "", ""
|
||||
|
@ -1018,7 +1019,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
|||
return nil, nil, nil, nil, "", ""
|
||||
}
|
||||
|
||||
compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch, true, false)
|
||||
compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch, true, false)
|
||||
if err != nil {
|
||||
headGitRepo.Close()
|
||||
ctx.Error(http.StatusInternalServerError, "GetCompareInfo", err)
|
||||
|
|
|
@ -14,6 +14,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/context"
|
||||
|
@ -216,7 +217,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
results := make([]*api.Repository, len(repos))
|
||||
for i, repo := range repos {
|
||||
if err = repo.GetOwner(); err != nil {
|
||||
if err = repo.GetOwner(db.DefaultContext); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||
OK: false,
|
||||
Error: err.Error(),
|
||||
|
@ -256,7 +257,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
|||
IsPrivate: opt.Private,
|
||||
AutoInit: opt.AutoInit,
|
||||
DefaultBranch: opt.DefaultBranch,
|
||||
TrustModel: models.ToTrustModel(opt.TrustModel),
|
||||
TrustModel: repo_model.ToTrustModel(opt.TrustModel),
|
||||
IsTemplate: opt.Template,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -272,7 +273,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
|||
}
|
||||
|
||||
// reload repo from db to get a real state after creation
|
||||
repo, err = models.GetRepositoryByID(repo.ID)
|
||||
repo, err = repo_model.GetRepositoryByID(repo.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
|
||||
}
|
||||
|
@ -553,9 +554,9 @@ func GetByID(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/Repository"
|
||||
|
||||
repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id"))
|
||||
repo, err := repo_model.GetRepositoryByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
if repo_model.IsErrRepoNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err)
|
||||
|
@ -628,7 +629,7 @@ func Edit(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
repo, err := models.GetRepositoryByID(ctx.Repo.Repository.ID)
|
||||
repo, err := repo_model.GetRepositoryByID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -738,7 +739,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
var units []models.RepoUnit
|
||||
var units []repo_model.RepoUnit
|
||||
var deleteUnitTypes []unit_model.Type
|
||||
|
||||
if opts.HasIssues != nil {
|
||||
|
@ -755,10 +756,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
return err
|
||||
}
|
||||
|
||||
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: opts.ExternalTracker.ExternalTrackerURL,
|
||||
ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
|
||||
ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
|
||||
|
@ -767,17 +768,17 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
|
||||
} else if *opts.HasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
|
||||
// Default to built-in tracker
|
||||
var config *models.IssuesConfig
|
||||
var config *repo_model.IssuesConfig
|
||||
|
||||
if opts.InternalTracker != nil {
|
||||
config = &models.IssuesConfig{
|
||||
config = &repo_model.IssuesConfig{
|
||||
EnableTimetracker: opts.InternalTracker.EnableTimeTracker,
|
||||
AllowOnlyContributorsToTrackTime: opts.InternalTracker.AllowOnlyContributorsToTrackTime,
|
||||
EnableDependencies: opts.InternalTracker.EnableIssueDependencies,
|
||||
}
|
||||
} else if unit, err := repo.GetUnit(unit_model.TypeIssues); err != nil {
|
||||
// Unit type doesn't exist so we make a new config file with default values
|
||||
config = &models.IssuesConfig{
|
||||
config = &repo_model.IssuesConfig{
|
||||
EnableTimetracker: true,
|
||||
AllowOnlyContributorsToTrackTime: true,
|
||||
EnableDependencies: true,
|
||||
|
@ -786,7 +787,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
config = unit.IssuesConfig()
|
||||
}
|
||||
|
||||
units = append(units, models.RepoUnit{
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypeIssues,
|
||||
Config: config,
|
||||
|
@ -811,17 +812,17 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
return err
|
||||
}
|
||||
|
||||
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: opts.ExternalWiki.ExternalWikiURL,
|
||||
},
|
||||
})
|
||||
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki)
|
||||
} else if *opts.HasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
|
||||
config := &models.UnitConfig{}
|
||||
units = append(units, models.RepoUnit{
|
||||
config := &repo_model.UnitConfig{}
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypeWiki,
|
||||
Config: config,
|
||||
|
@ -843,10 +844,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
// we get the config settings and then set them
|
||||
// if those settings were provided in the opts.
|
||||
unit, err := repo.GetUnit(unit_model.TypePullRequests)
|
||||
var config *models.PullRequestsConfig
|
||||
var config *repo_model.PullRequestsConfig
|
||||
if err != nil {
|
||||
// Unit type doesn't exist so we make a new config file with default values
|
||||
config = &models.PullRequestsConfig{
|
||||
config = &repo_model.PullRequestsConfig{
|
||||
IgnoreWhitespaceConflicts: false,
|
||||
AllowMerge: true,
|
||||
AllowRebase: true,
|
||||
|
@ -855,7 +856,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
AllowManualMerge: true,
|
||||
AutodetectManualMerge: false,
|
||||
DefaultDeleteBranchAfterMerge: false,
|
||||
DefaultMergeStyle: models.MergeStyleMerge,
|
||||
DefaultMergeStyle: repo_model.MergeStyleMerge,
|
||||
}
|
||||
} else {
|
||||
config = unit.PullRequestsConfig()
|
||||
|
@ -886,10 +887,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
config.DefaultDeleteBranchAfterMerge = *opts.DefaultDeleteBranchAfterMerge
|
||||
}
|
||||
if opts.DefaultMergeStyle != nil {
|
||||
config.DefaultMergeStyle = models.MergeStyle(*opts.DefaultMergeStyle)
|
||||
config.DefaultMergeStyle = repo_model.MergeStyle(*opts.DefaultMergeStyle)
|
||||
}
|
||||
|
||||
units = append(units, models.RepoUnit{
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypePullRequests,
|
||||
Config: config,
|
||||
|
@ -901,7 +902,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
|
||||
if opts.HasProjects != nil && !unit_model.TypeProjects.UnitGlobalDisabled() {
|
||||
if *opts.HasProjects {
|
||||
units = append(units, models.RepoUnit{
|
||||
units = append(units, repo_model.RepoUnit{
|
||||
RepoID: repo.ID,
|
||||
Type: unit_model.TypeProjects,
|
||||
})
|
||||
|
@ -930,14 +931,14 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
|
|||
return err
|
||||
}
|
||||
if *opts.Archived {
|
||||
if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
|
||||
if err := models.SetArchiveRepoState(repo, *opts.Archived); err != nil {
|
||||
log.Error("Tried to archive a repo: %s", err)
|
||||
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
|
||||
return err
|
||||
}
|
||||
log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
||||
} else {
|
||||
if err := repo.SetArchiveRepoState(*opts.Archived); err != nil {
|
||||
if err := models.SetArchiveRepoState(repo, *opts.Archived); err != nil {
|
||||
log.Error("Tried to un-archive a repo: %s", err)
|
||||
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
|
||||
return err
|
||||
|
@ -958,14 +959,16 @@ func updateMirrorInterval(ctx *context.APIContext, opts api.EditRepoOption) erro
|
|||
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
|
||||
return err
|
||||
}
|
||||
if err := repo.GetMirror(); err != nil {
|
||||
mirror, err := repo_model.GetMirrorByRepoID(repo.ID)
|
||||
if err != nil {
|
||||
log.Error("Failed to get mirror: %s", err)
|
||||
ctx.Error(http.StatusInternalServerError, "MirrorInterval", err)
|
||||
return err
|
||||
}
|
||||
if interval, err := time.ParseDuration(*opts.MirrorInterval); err == nil {
|
||||
repo.Mirror.Interval = interval
|
||||
if err := models.UpdateMirror(repo.Mirror); err != nil {
|
||||
mirror.Interval = interval
|
||||
mirror.Repo = repo
|
||||
if err := repo_model.UpdateMirror(mirror); err != nil {
|
||||
log.Error("Failed to Set Mirror Interval: %s", err)
|
||||
ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err)
|
||||
return err
|
||||
|
@ -1007,7 +1010,7 @@ func Delete(ctx *context.APIContext) {
|
|||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
canDelete, err := repo.CanUserDelete(ctx.User)
|
||||
canDelete, err := models.CanUserDelete(repo, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CanUserDelete", err)
|
||||
return
|
||||
|
|
|
@ -8,7 +8,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/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -60,7 +60,7 @@ func TestRepoEdit(t *testing.T) {
|
|||
Edit(apiCtx)
|
||||
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Repository{
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
||||
ID: 1,
|
||||
}, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func TestRepoEditNameChange(t *testing.T) {
|
|||
Edit(apiCtx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &models.Repository{
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
||||
ID: 1,
|
||||
}, unittest.Cond("name = ?", opts.Name))
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package repo
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -43,7 +44,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/UserList"
|
||||
|
||||
subscribers, err := ctx.Repo.Repository.GetWatchers(utils.GetListOptions(ctx))
|
||||
subscribers, err := models.GetRepoWatchers(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetWatchers", err)
|
||||
return
|
||||
|
|
|
@ -41,7 +41,7 @@ func ListTeams(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
teams, err := ctx.Repo.Repository.GetRepoTeams()
|
||||
teams, err := models.GetRepoTeams(ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -112,7 +113,7 @@ func Transfer(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Repository.Status == models.RepositoryPendingTransfer {
|
||||
if ctx.Repo.Repository.Status == repo_model.RepositoryPendingTransfer {
|
||||
log.Trace("Repository transfer initiated: %s -> %s", ctx.Repo.Repository.FullName(), newOwner.Name)
|
||||
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx.Repo.Repository, perm.AccessModeAdmin))
|
||||
return
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -118,7 +119,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
|||
|
||||
results := make([]*api.Repository, len(repos))
|
||||
for i, repo := range repos {
|
||||
if err = repo.GetOwner(); err != nil {
|
||||
if err = repo.GetOwner(db.DefaultContext); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -9,6 +9,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/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -201,6 +202,6 @@ func Unwatch(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// subscriptionURL returns the URL of the subscription API endpoint of a repo
|
||||
func subscriptionURL(repo *models.Repository) string {
|
||||
func subscriptionURL(repo *repo_model.Repository) string {
|
||||
return repo.APIURL() + "/subscription"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue