aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/admin/adopt.go9
-rw-r--r--routers/api/v1/api.go5
-rw-r--r--routers/api/v1/org/team.go7
-rw-r--r--routers/api/v1/repo/branch.go10
-rw-r--r--routers/api/v1/repo/collaborators.go17
-rw-r--r--routers/api/v1/repo/commits.go4
-rw-r--r--routers/api/v1/repo/file.go3
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/key.go5
-rw-r--r--routers/api/v1/repo/language.go6
-rw-r--r--routers/api/v1/repo/migrate.go3
-rw-r--r--routers/api/v1/repo/pull.go21
-rw-r--r--routers/api/v1/repo/repo.go61
-rw-r--r--routers/api/v1/repo/repo_test.go6
-rw-r--r--routers/api/v1/repo/subscriber.go3
-rw-r--r--routers/api/v1/repo/teams.go2
-rw-r--r--routers/api/v1/repo/transfer.go3
-rw-r--r--routers/api/v1/user/repo.go3
-rw-r--r--routers/api/v1/user/watch.go3
19 files changed, 94 insertions, 79 deletions
diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go
index 85262bc836..1c0e237cdb 100644
--- a/routers/api/v1/admin/adopt.go
+++ b/routers/api/v1/admin/adopt.go
@@ -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
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 867803f8dd..1d7d4251db 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -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)
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 371f1dc86d..074d6fd009 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -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)
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index e511152e57..56266b406a 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -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
}
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index 80794fa444..d49b6357bd 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -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
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index 9907054b83..117fef08da 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -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"),
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index e84f652ed9..98decfcb6f 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -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 {
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index 33321e6a02..aa51019ebd 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -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
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index ad94da5b2d..03ebcb8f72 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.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/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
}
diff --git a/routers/api/v1/repo/language.go b/routers/api/v1/repo/language.go
index c45911ee66..427a8fd6b5 100644
--- a/routers/api/v1/repo/language.go
+++ b/routers/api/v1/repo/language.go
@@ -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)
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index dba44efb21..108d78ef23 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -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)
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index dd415a34af..3e37da24ec 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -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)
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 2f37e10984..4486e33fe8 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -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
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index 4d4093582b..17b49f7f58 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -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))
}
diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go
index dae92969ba..64a0fc1d5d 100644
--- a/routers/api/v1/repo/subscriber.go
+++ b/routers/api/v1/repo/subscriber.go
@@ -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
diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go
index 1348205ec9..024224b5a3 100644
--- a/routers/api/v1/repo/teams.go
+++ b/routers/api/v1/repo/teams.go
@@ -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
diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go
index 0a698383e5..e2a83c70ec 100644
--- a/routers/api/v1/repo/transfer.go
+++ b/routers/api/v1/repo/transfer.go
@@ -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
diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go
index 760032460e..3d5c841856 100644
--- a/routers/api/v1/user/repo.go
+++ b/routers/api/v1/user/repo.go
@@ -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
}
diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go
index 54d5e74bc0..5c7a4d8d89 100644
--- a/routers/api/v1/user/watch.go
+++ b/routers/api/v1/user/watch.go
@@ -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"
}