forked from forgejo/forgejo
Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
4a4bfafa23
commit
1d8543e7db
154 changed files with 1763 additions and 1738 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
|
@ -174,7 +175,7 @@ func AddCollaborator(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := models.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
|
||||
if err := repo_module.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AddCollaborator", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ func Migrate(ctx *context.APIContext) {
|
|||
opts.Releases = false
|
||||
}
|
||||
|
||||
repo, err := repo_module.CreateRepository(ctx.Doer, repoOwner, models.CreateRepoOptions{
|
||||
repo, err := repo_module.CreateRepository(ctx.Doer, repoOwner, repo_module.CreateRepoOptions{
|
||||
Name: opts.RepoName,
|
||||
Description: opts.Description,
|
||||
OriginalURL: form.CloneAddr,
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
pull_model "code.gitea.io/gitea/models/pull"
|
||||
|
@ -753,7 +754,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
|||
|
||||
if ctx.IsSigned {
|
||||
// Update issue-user.
|
||||
if err = models.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
|
||||
if err = activities_model.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -9,6 +9,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/unit"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -49,12 +50,12 @@ func GetRelease(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/notFound"
|
||||
|
||||
id := ctx.ParamsInt64(":id")
|
||||
release, err := models.GetReleaseByID(ctx, id)
|
||||
if err != nil && !models.IsErrReleaseNotExist(err) {
|
||||
release, err := repo_model.GetReleaseByID(ctx, id)
|
||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||
return
|
||||
}
|
||||
if err != nil && models.IsErrReleaseNotExist(err) ||
|
||||
if err != nil && repo_model.IsErrReleaseNotExist(err) ||
|
||||
release.IsTag || release.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.NotFound()
|
||||
return
|
||||
|
@ -114,7 +115,7 @@ func ListReleases(ctx *context.APIContext) {
|
|||
listOptions.PageSize = ctx.FormInt("per_page")
|
||||
}
|
||||
|
||||
opts := models.FindReleasesOptions{
|
||||
opts := repo_model.FindReleasesOptions{
|
||||
ListOptions: listOptions,
|
||||
IncludeDrafts: ctx.Repo.AccessMode >= perm.AccessModeWrite || ctx.Repo.UnitAccessMode(unit.TypeReleases) >= perm.AccessModeWrite,
|
||||
IncludeTags: false,
|
||||
|
@ -122,7 +123,7 @@ func ListReleases(ctx *context.APIContext) {
|
|||
IsPreRelease: ctx.FormOptionalBool("pre-release"),
|
||||
}
|
||||
|
||||
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
releases, err := repo_model.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
|
||||
return
|
||||
|
@ -136,7 +137,7 @@ func ListReleases(ctx *context.APIContext) {
|
|||
rels[i] = convert.ToRelease(release)
|
||||
}
|
||||
|
||||
filteredCount, err := models.CountReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
filteredCount, err := repo_model.CountReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -179,9 +180,9 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
// "409":
|
||||
// "$ref": "#/responses/error"
|
||||
form := web.GetForm(ctx).(*api.CreateReleaseOption)
|
||||
rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
|
||||
rel, err := repo_model.GetRelease(ctx.Repo.Repository.ID, form.TagName)
|
||||
if err != nil {
|
||||
if !models.IsErrReleaseNotExist(err) {
|
||||
if !repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
|
||||
return
|
||||
}
|
||||
|
@ -189,7 +190,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
if len(form.Target) == 0 {
|
||||
form.Target = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
rel = &models.Release{
|
||||
rel = &repo_model.Release{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
PublisherID: ctx.Doer.ID,
|
||||
Publisher: ctx.Doer,
|
||||
|
@ -203,7 +204,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
Repo: ctx.Repo.Repository,
|
||||
}
|
||||
if err := release_service.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
|
||||
if models.IsErrReleaseAlreadyExist(err) {
|
||||
if repo_model.IsErrReleaseAlreadyExist(err) {
|
||||
ctx.Error(http.StatusConflict, "ReleaseAlreadyExist", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "CreateRelease", err)
|
||||
|
@ -272,12 +273,12 @@ func EditRelease(ctx *context.APIContext) {
|
|||
|
||||
form := web.GetForm(ctx).(*api.EditReleaseOption)
|
||||
id := ctx.ParamsInt64(":id")
|
||||
rel, err := models.GetReleaseByID(ctx, id)
|
||||
if err != nil && !models.IsErrReleaseNotExist(err) {
|
||||
rel, err := repo_model.GetReleaseByID(ctx, id)
|
||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||
return
|
||||
}
|
||||
if err != nil && models.IsErrReleaseNotExist(err) ||
|
||||
if err != nil && repo_model.IsErrReleaseNotExist(err) ||
|
||||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.NotFound()
|
||||
return
|
||||
|
@ -307,7 +308,7 @@ func EditRelease(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// reload data from database
|
||||
rel, err = models.GetReleaseByID(ctx, id)
|
||||
rel, err = repo_model.GetReleaseByID(ctx, id)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||
return
|
||||
|
@ -350,12 +351,12 @@ func DeleteRelease(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/empty"
|
||||
|
||||
id := ctx.ParamsInt64(":id")
|
||||
rel, err := models.GetReleaseByID(ctx, id)
|
||||
if err != nil && !models.IsErrReleaseNotExist(err) {
|
||||
rel, err := repo_model.GetReleaseByID(ctx, id)
|
||||
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||
return
|
||||
}
|
||||
if err != nil && models.IsErrReleaseNotExist(err) ||
|
||||
if err != nil && repo_model.IsErrReleaseNotExist(err) ||
|
||||
rel.IsTag || rel.RepoID != ctx.Repo.Repository.ID {
|
||||
ctx.NotFound()
|
||||
return
|
||||
|
|
|
@ -7,7 +7,6 @@ package repo
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -102,9 +101,9 @@ func ListReleaseAttachments(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/AttachmentList"
|
||||
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
release, err := models.GetReleaseByID(ctx, releaseID)
|
||||
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
if repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -172,9 +171,9 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
|||
|
||||
// Check if release exists an load release
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
release, err := models.GetReleaseByID(ctx, releaseID)
|
||||
release, err := repo_model.GetReleaseByID(ctx, releaseID)
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
if repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
releaseservice "code.gitea.io/gitea/services/release"
|
||||
|
@ -44,9 +45,9 @@ func GetReleaseByTag(ctx *context.APIContext) {
|
|||
|
||||
tag := ctx.Params(":tag")
|
||||
|
||||
release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
|
||||
release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag)
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
if repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
@ -97,9 +98,9 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
|
|||
|
||||
tag := ctx.Params(":tag")
|
||||
|
||||
release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
|
||||
release, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tag)
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
if repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
|
@ -232,7 +231,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
|
|||
if opt.AutoInit && opt.Readme == "" {
|
||||
opt.Readme = "Default"
|
||||
}
|
||||
repo, err := repo_service.CreateRepository(ctx.Doer, owner, models.CreateRepoOptions{
|
||||
repo, err := repo_service.CreateRepository(ctx.Doer, owner, repo_module.CreateRepoOptions{
|
||||
Name: opt.Name,
|
||||
Description: opt.Description,
|
||||
IssueLabels: opt.IssueLabels,
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -249,9 +250,9 @@ func DeleteTag(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/conflict"
|
||||
tagName := ctx.Params("*")
|
||||
|
||||
tag, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
|
||||
tag, err := repo_model.GetRelease(ctx.Repo.Repository.ID, tagName)
|
||||
if err != nil {
|
||||
if models.IsErrReleaseNotExist(err) {
|
||||
if repo_model.IsErrReleaseNotExist(err) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
org_service "code.gitea.io/gitea/services/org"
|
||||
)
|
||||
|
||||
// ListTeams list a repository's teams
|
||||
|
@ -199,7 +200,7 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
|
|||
ctx.Error(http.StatusUnprocessableEntity, "alreadyAdded", fmt.Errorf("team '%s' is already added to repo", team.Name))
|
||||
return
|
||||
}
|
||||
err = models.AddRepository(team, ctx.Repo.Repository)
|
||||
err = org_service.TeamAddRepository(team, ctx.Repo.Repository)
|
||||
} else {
|
||||
if !repoHasTeam {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "notAdded", fmt.Errorf("team '%s' was not added to repo", team.Name))
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
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/git"
|
||||
|
@ -72,9 +72,9 @@ func NewWikiPage(ctx *context.APIContext) {
|
|||
form.ContentBase64 = string(content)
|
||||
|
||||
if err := wiki_service.AddWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
|
||||
if models.IsErrWikiReservedName(err) {
|
||||
if repo_model.IsErrWikiReservedName(err) {
|
||||
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
|
||||
} else if models.IsErrWikiAlreadyExist(err) {
|
||||
} else if repo_model.IsErrWikiAlreadyExist(err) {
|
||||
ctx.Error(http.StatusBadRequest, "IsErrWikiAlreadyExists", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "AddWikiPage", err)
|
||||
|
@ -314,7 +314,7 @@ func ListWikiPages(ctx *context.APIContext) {
|
|||
}
|
||||
wikiName, err := wiki_service.FilenameToName(entry.Name())
|
||||
if err != nil {
|
||||
if models.IsErrWikiInvalidFileName(err) {
|
||||
if repo_model.IsErrWikiInvalidFileName(err) {
|
||||
continue
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue