diff options
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/collaborators.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/release.go | 35 | ||||
-rw-r--r-- | routers/api/v1/repo/release_attachment.go | 9 | ||||
-rw-r--r-- | routers/api/v1/repo/release_tags.go | 9 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/tag.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/teams.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/wiki.go | 8 |
10 files changed, 42 insertions, 38 deletions
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index aa425e5828..0e6236216c 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -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 } diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index f868c53951..ed371d787c 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -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, diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 50d2c9484f..dda05203df 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" + 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 } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index 80009f78e9..acc9696e1b 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -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 diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index 7b63af34c8..a469877c13 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -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 } diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go index 73dee73e1a..2cb97c58a0 100644 --- a/routers/api/v1/repo/release_tags.go +++ b/routers/api/v1/repo/release_tags.go @@ -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 } diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index cdd1f7d5c4..d28b56cab6 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -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, diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go index 433d823c7e..f0f8503996 100644 --- a/routers/api/v1/repo/tag.go +++ b/routers/api/v1/repo/tag.go @@ -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 } diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index 47c69d722b..f485f2086e 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -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)) diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index d423bddbbd..82542d1ab8 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -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) |