mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Convert all API handers to use *context.APIContext
This commit is contained in:
@@ -12,16 +12,16 @@ import (
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
|
||||
func GetBranch(ctx *context.Context) {
|
||||
func GetBranch(ctx *context.APIContext) {
|
||||
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetBranch", err)
|
||||
ctx.Error(500, "GetBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
c, err := branch.GetCommit()
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetCommit", err)
|
||||
ctx.Error(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ func GetBranch(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
|
||||
func ListBranches(ctx *context.Context) {
|
||||
func ListBranches(ctx *context.APIContext) {
|
||||
branches, err := ctx.Repo.Repository.GetBranches()
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetBranches", err)
|
||||
ctx.Error(500, "GetBranches", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func ListBranches(ctx *context.Context) {
|
||||
for i := range branches {
|
||||
c, err := branches[i].GetCommit()
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetCommit", err)
|
||||
ctx.Error(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
apiBranches[i] = convert.ToApiBranch(branches[i], c)
|
||||
|
@@ -13,35 +13,35 @@ import (
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
|
||||
func GetRawFile(ctx *context.Context) {
|
||||
func GetRawFile(ctx *context.APIContext) {
|
||||
if !ctx.Repo.HasAccess() {
|
||||
ctx.Error(404)
|
||||
ctx.Status(404)
|
||||
return
|
||||
}
|
||||
|
||||
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.APIError(500, "GetBlobByPath", err)
|
||||
ctx.Error(500, "GetBlobByPath", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err = repo.ServeBlob(ctx, blob); err != nil {
|
||||
ctx.APIError(500, "ServeBlob", err)
|
||||
if err = repo.ServeBlob(ctx.Context, blob); err != nil {
|
||||
ctx.Error(500, "ServeBlob", err)
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
|
||||
func GetArchive(ctx *context.Context) {
|
||||
func GetArchive(ctx *context.APIContext) {
|
||||
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
if err != nil {
|
||||
ctx.APIError(500, "OpenRepository", err)
|
||||
ctx.Error(500, "OpenRepository", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.GitRepo = gitRepo
|
||||
|
||||
repo.Download(ctx)
|
||||
repo.Download(ctx.Context)
|
||||
}
|
||||
|
@@ -17,10 +17,10 @@ import (
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
func ListHooks(ctx *context.Context) {
|
||||
func ListHooks(ctx *context.APIContext) {
|
||||
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetWebhooksByRepoID", err)
|
||||
ctx.Error(500, "GetWebhooksByRepoID", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -33,19 +33,19 @@ func ListHooks(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
||||
func CreateHook(ctx *context.Context, form api.CreateHookOption) {
|
||||
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
if !models.IsValidHookTaskType(form.Type) {
|
||||
ctx.APIError(422, "", "Invalid hook type")
|
||||
ctx.Error(422, "", "Invalid hook type")
|
||||
return
|
||||
}
|
||||
for _, name := range []string{"url", "content_type"} {
|
||||
if _, ok := form.Config[name]; !ok {
|
||||
ctx.APIError(422, "", "Missing config option: "+name)
|
||||
ctx.Error(422, "", "Missing config option: "+name)
|
||||
return
|
||||
}
|
||||
}
|
||||
if !models.IsValidHookContentType(form.Config["content_type"]) {
|
||||
ctx.APIError(422, "", "Invalid content type")
|
||||
ctx.Error(422, "", "Invalid content type")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func CreateHook(ctx *context.Context, form api.CreateHookOption) {
|
||||
if w.HookTaskType == models.SLACK {
|
||||
channel, ok := form.Config["channel"]
|
||||
if !ok {
|
||||
ctx.APIError(422, "", "Missing config option: channel")
|
||||
ctx.Error(422, "", "Missing config option: channel")
|
||||
return
|
||||
}
|
||||
meta, err := json.Marshal(&models.SlackMeta{
|
||||
@@ -80,17 +80,17 @@ func CreateHook(ctx *context.Context, form api.CreateHookOption) {
|
||||
Color: form.Config["color"],
|
||||
})
|
||||
if err != nil {
|
||||
ctx.APIError(500, "slack: JSON marshal failed", err)
|
||||
ctx.Error(500, "slack: JSON marshal failed", err)
|
||||
return
|
||||
}
|
||||
w.Meta = string(meta)
|
||||
}
|
||||
|
||||
if err := w.UpdateEvent(); err != nil {
|
||||
ctx.APIError(500, "UpdateEvent", err)
|
||||
ctx.Error(500, "UpdateEvent", err)
|
||||
return
|
||||
} else if err := models.CreateWebhook(w); err != nil {
|
||||
ctx.APIError(500, "CreateWebhook", err)
|
||||
ctx.Error(500, "CreateWebhook", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,13 +98,13 @@ func CreateHook(ctx *context.Context, form api.CreateHookOption) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
func EditHook(ctx *context.Context, form api.EditHookOption) {
|
||||
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrWebhookNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.APIError(500, "GetWebhookByID", err)
|
||||
ctx.Error(500, "GetWebhookByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func EditHook(ctx *context.Context, form api.EditHookOption) {
|
||||
}
|
||||
if ct, ok := form.Config["content_type"]; ok {
|
||||
if !models.IsValidHookContentType(ct) {
|
||||
ctx.APIError(422, "", "Invalid content type")
|
||||
ctx.Error(422, "", "Invalid content type")
|
||||
return
|
||||
}
|
||||
w.ContentType = models.ToHookContentType(ct)
|
||||
@@ -130,7 +130,7 @@ func EditHook(ctx *context.Context, form api.EditHookOption) {
|
||||
Color: form.Config["color"],
|
||||
})
|
||||
if err != nil {
|
||||
ctx.APIError(500, "slack: JSON marshal failed", err)
|
||||
ctx.Error(500, "slack: JSON marshal failed", err)
|
||||
return
|
||||
}
|
||||
w.Meta = string(meta)
|
||||
@@ -148,7 +148,7 @@ func EditHook(ctx *context.Context, form api.EditHookOption) {
|
||||
w.Create = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE))
|
||||
w.Push = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH))
|
||||
if err = w.UpdateEvent(); err != nil {
|
||||
ctx.APIError(500, "UpdateEvent", err)
|
||||
ctx.Error(500, "UpdateEvent", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func EditHook(ctx *context.Context, form api.EditHookOption) {
|
||||
}
|
||||
|
||||
if err := models.UpdateWebhook(w); err != nil {
|
||||
ctx.APIError(500, "UpdateWebhook", err)
|
||||
ctx.Error(500, "UpdateWebhook", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -20,10 +20,10 @@ func composeDeployKeysAPILink(repoPath string) string {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
|
||||
func ListDeployKeys(ctx *context.Context) {
|
||||
func ListDeployKeys(ctx *context.APIContext) {
|
||||
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "ListDeployKeys", err)
|
||||
ctx.Error(500, "ListDeployKeys", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func ListDeployKeys(ctx *context.Context) {
|
||||
apiKeys := make([]*api.DeployKey, len(keys))
|
||||
for i := range keys {
|
||||
if err = keys[i].GetContent(); err != nil {
|
||||
ctx.APIError(500, "GetContent", err)
|
||||
ctx.Error(500, "GetContent", err)
|
||||
return
|
||||
}
|
||||
apiKeys[i] = convert.ToApiDeployKey(apiLink, keys[i])
|
||||
@@ -41,19 +41,19 @@ func ListDeployKeys(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
|
||||
func GetDeployKey(ctx *context.Context) {
|
||||
func GetDeployKey(ctx *context.APIContext) {
|
||||
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrDeployKeyNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.Handle(500, "GetDeployKeyByID", err)
|
||||
ctx.Error(500, "GetDeployKeyByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err = key.GetContent(); err != nil {
|
||||
ctx.APIError(500, "GetContent", err)
|
||||
ctx.Error(500, "GetContent", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -61,27 +61,27 @@ func GetDeployKey(ctx *context.Context) {
|
||||
ctx.JSON(200, convert.ToApiDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
func HandleCheckKeyStringError(ctx *context.Context, err error) {
|
||||
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||
if models.IsErrKeyUnableVerify(err) {
|
||||
ctx.APIError(422, "", "Unable to verify key content")
|
||||
ctx.Error(422, "", "Unable to verify key content")
|
||||
} else {
|
||||
ctx.APIError(422, "", fmt.Errorf("Invalid key content: %v", err))
|
||||
ctx.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func HandleAddKeyError(ctx *context.Context, err error) {
|
||||
func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||
switch {
|
||||
case models.IsErrKeyAlreadyExist(err):
|
||||
ctx.APIError(422, "", "Key content has been used as non-deploy key")
|
||||
ctx.Error(422, "", "Key content has been used as non-deploy key")
|
||||
case models.IsErrKeyNameAlreadyUsed(err):
|
||||
ctx.APIError(422, "", "Key title has been used")
|
||||
ctx.Error(422, "", "Key title has been used")
|
||||
default:
|
||||
ctx.APIError(500, "AddKey", err)
|
||||
ctx.Error(500, "AddKey", err)
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
|
||||
func CreateDeployKey(ctx *context.Context, form api.CreateKeyOption) {
|
||||
func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
content, err := models.CheckPublicKeyString(form.Key)
|
||||
if err != nil {
|
||||
HandleCheckKeyStringError(ctx, err)
|
||||
@@ -100,12 +100,12 @@ func CreateDeployKey(ctx *context.Context, form api.CreateKeyOption) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
|
||||
func DeleteDeploykey(ctx *context.Context) {
|
||||
func DeleteDeploykey(ctx *context.APIContext) {
|
||||
if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
|
||||
if models.IsErrKeyAccessDenied(err) {
|
||||
ctx.APIError(403, "", "You do not have access to this key")
|
||||
ctx.Error(403, "", "You do not have access to this key")
|
||||
} else {
|
||||
ctx.APIError(500, "DeleteDeployKey", err)
|
||||
ctx.Error(500, "DeleteDeployKey", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
func Search(ctx *context.Context) {
|
||||
func Search(ctx *context.APIContext) {
|
||||
opts := &models.SearchRepoOptions{
|
||||
Keyword: path.Base(ctx.Query("q")),
|
||||
OwnerID: com.StrTo(ctx.Query("uid")).MustInt64(),
|
||||
@@ -81,17 +81,17 @@ func Search(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
func ListMyRepos(ctx *context.Context) {
|
||||
func ListMyRepos(ctx *context.APIContext) {
|
||||
ownRepos, err := models.GetRepositories(ctx.User.Id, true)
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetRepositories", err)
|
||||
ctx.Error(500, "GetRepositories", err)
|
||||
return
|
||||
}
|
||||
numOwnRepos := len(ownRepos)
|
||||
|
||||
accessibleRepos, err := ctx.User.GetRepositoryAccesses()
|
||||
if err != nil {
|
||||
ctx.APIError(500, "GetRepositoryAccesses", err)
|
||||
ctx.Error(500, "GetRepositoryAccesses", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func ListMyRepos(ctx *context.Context) {
|
||||
ctx.JSON(200, &repos)
|
||||
}
|
||||
|
||||
func CreateUserRepo(ctx *context.Context, owner *models.User, opt api.CreateRepoOption) {
|
||||
func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
|
||||
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
|
||||
Name: opt.Name,
|
||||
Description: opt.Description,
|
||||
@@ -127,14 +127,14 @@ func CreateUserRepo(ctx *context.Context, owner *models.User, opt api.CreateRepo
|
||||
if models.IsErrRepoAlreadyExist(err) ||
|
||||
models.IsErrNameReserved(err) ||
|
||||
models.IsErrNamePatternNotAllowed(err) {
|
||||
ctx.APIError(422, "", err)
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
if repo != nil {
|
||||
if err = models.DeleteRepository(ctx.User.Id, repo.ID); err != nil {
|
||||
log.Error(4, "DeleteRepository: %v", err)
|
||||
}
|
||||
}
|
||||
ctx.APIError(500, "CreateRepository", err)
|
||||
ctx.Error(500, "CreateRepository", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -143,35 +143,35 @@ func CreateUserRepo(ctx *context.Context, owner *models.User, opt api.CreateRepo
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
func Create(ctx *context.Context, opt api.CreateRepoOption) {
|
||||
func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
if ctx.User.IsOrganization() {
|
||||
ctx.APIError(422, "", "not allowed creating repository for organization")
|
||||
ctx.Error(422, "", "not allowed creating repository for organization")
|
||||
return
|
||||
}
|
||||
CreateUserRepo(ctx, ctx.User, opt)
|
||||
}
|
||||
|
||||
func CreateOrgRepo(ctx *context.Context, opt api.CreateRepoOption) {
|
||||
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.APIError(422, "", err)
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
ctx.APIError(500, "GetOrgByName", err)
|
||||
ctx.Error(500, "GetOrgByName", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if !org.IsOwnedBy(ctx.User.Id) {
|
||||
ctx.APIError(403, "", "Given user is not owner of organization.")
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
CreateUserRepo(ctx, org, opt)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||
func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||
ctxUser := ctx.User
|
||||
// Not equal means context user is an organization,
|
||||
// or is another user/organization if current user is admin.
|
||||
@@ -179,9 +179,9 @@ func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
org, err := models.GetUserByID(form.Uid)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.APIError(422, "", err)
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
ctx.APIError(500, "GetUserByID", err)
|
||||
ctx.Error(500, "GetUserByID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -189,14 +189,14 @@ func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.APIError(422, "", ctx.GetErrMsg())
|
||||
ctx.Error(422, "", ctx.GetErrMsg())
|
||||
return
|
||||
}
|
||||
|
||||
if ctxUser.IsOrganization() && !ctx.User.IsAdmin {
|
||||
// Check ownership of organization.
|
||||
if !ctxUser.IsOwnedBy(ctx.User.Id) {
|
||||
ctx.APIError(403, "", "Given user is not owner of organization.")
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -207,16 +207,16 @@ func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
addrErr := err.(models.ErrInvalidCloneAddr)
|
||||
switch {
|
||||
case addrErr.IsURLError:
|
||||
ctx.APIError(422, "", err)
|
||||
ctx.Error(422, "", err)
|
||||
case addrErr.IsPermissionDenied:
|
||||
ctx.APIError(422, "", "You are not allowed to import local repositories.")
|
||||
ctx.Error(422, "", "You are not allowed to import local repositories.")
|
||||
case addrErr.IsInvalidPath:
|
||||
ctx.APIError(422, "", "Invalid local path, it does not exist or not a directory.")
|
||||
ctx.Error(422, "", "Invalid local path, it does not exist or not a directory.")
|
||||
default:
|
||||
ctx.APIError(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
|
||||
ctx.Error(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
|
||||
}
|
||||
} else {
|
||||
ctx.APIError(500, "ParseRemoteAddr", err)
|
||||
ctx.Error(500, "ParseRemoteAddr", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -234,7 +234,7 @@ func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
log.Error(4, "DeleteRepository: %v", errDelete)
|
||||
}
|
||||
}
|
||||
ctx.APIError(500, "MigrateRepository", models.HandleCloneUserCredentials(err.Error(), true))
|
||||
ctx.Error(500, "MigrateRepository", models.HandleCloneUserCredentials(err.Error(), true))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -242,13 +242,13 @@ func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||
ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
|
||||
func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
|
||||
owner, err := models.GetUserByName(ctx.Params(":username"))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.APIError(422, "", err)
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
ctx.APIError(500, "GetUserByName", err)
|
||||
ctx.Error(500, "GetUserByName", err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -256,9 +256,9 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
|
||||
repo, err := models.GetRepositoryByName(owner.Id, ctx.Params(":reponame"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoNotExist(err) {
|
||||
ctx.Error(404)
|
||||
ctx.Status(404)
|
||||
} else {
|
||||
ctx.APIError(500, "GetRepositoryByName", err)
|
||||
ctx.Error(500, "GetRepositoryByName", err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -267,7 +267,7 @@ func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
func Get(ctx *context.Context) {
|
||||
func Get(ctx *context.APIContext) {
|
||||
owner, repo := parseOwnerAndRepo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -277,19 +277,19 @@ func Get(ctx *context.Context) {
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
func Delete(ctx *context.Context) {
|
||||
func Delete(ctx *context.APIContext) {
|
||||
owner, repo := parseOwnerAndRepo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) {
|
||||
ctx.APIError(403, "", "Given user is not owner of organization.")
|
||||
ctx.Error(403, "", "Given user is not owner of organization.")
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(owner.Id, repo.ID); err != nil {
|
||||
ctx.APIError(500, "DeleteRepository", err)
|
||||
ctx.Error(500, "DeleteRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user