1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Rename module: middleware -> context

This commit is contained in:
Unknwon
2016-03-11 11:56:52 -05:00
parent cb1eadc276
commit 514382e2eb
54 changed files with 666 additions and 669 deletions

View File

@@ -7,12 +7,12 @@ package repo
import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
func GetBranch(ctx *middleware.Context) {
func GetBranch(ctx *context.Context) {
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
if err != nil {
ctx.APIError(500, "GetBranch", err)
@@ -29,7 +29,7 @@ func GetBranch(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
func ListBranches(ctx *middleware.Context) {
func ListBranches(ctx *context.Context) {
branches, err := ctx.Repo.Repository.GetBranches()
if err != nil {
ctx.APIError(500, "GetBranches", err)

View File

@@ -8,12 +8,12 @@ import (
"github.com/gogits/git-module"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/repo"
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
func GetRawFile(ctx *middleware.Context) {
func GetRawFile(ctx *context.Context) {
if !ctx.Repo.HasAccess() {
ctx.Error(404)
return
@@ -34,7 +34,7 @@ func GetRawFile(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
func GetArchive(ctx *middleware.Context) {
func GetArchive(ctx *context.Context) {
repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {

View File

@@ -12,12 +12,12 @@ import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/routers/api/v1/convert"
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
func ListHooks(ctx *middleware.Context) {
func ListHooks(ctx *context.Context) {
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
if err != nil {
ctx.APIError(500, "GetWebhooksByRepoID", err)
@@ -33,7 +33,7 @@ func ListHooks(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
func CreateHook(ctx *context.Context, form api.CreateHookOption) {
if !models.IsValidHookTaskType(form.Type) {
ctx.APIError(422, "", "Invalid hook type")
return
@@ -98,7 +98,7 @@ func CreateHook(ctx *middleware.Context, form api.CreateHookOption) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
func EditHook(ctx *middleware.Context, form api.EditHookOption) {
func EditHook(ctx *context.Context, form api.EditHookOption) {
w, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrWebhookNotExist(err) {

View File

@@ -10,7 +10,7 @@ import (
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
)
@@ -20,7 +20,7 @@ func composeDeployKeysAPILink(repoPath string) string {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
func ListDeployKeys(ctx *middleware.Context) {
func ListDeployKeys(ctx *context.Context) {
keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
if err != nil {
ctx.Handle(500, "ListDeployKeys", err)
@@ -41,7 +41,7 @@ func ListDeployKeys(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
func GetDeployKey(ctx *middleware.Context) {
func GetDeployKey(ctx *context.Context) {
key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrDeployKeyNotExist(err) {
@@ -61,7 +61,7 @@ func GetDeployKey(ctx *middleware.Context) {
ctx.JSON(200, convert.ToApiDeployKey(apiLink, key))
}
func HandleCheckKeyStringError(ctx *middleware.Context, err error) {
func HandleCheckKeyStringError(ctx *context.Context, err error) {
if models.IsErrKeyUnableVerify(err) {
ctx.APIError(422, "", "Unable to verify key content")
} else {
@@ -69,7 +69,7 @@ func HandleCheckKeyStringError(ctx *middleware.Context, err error) {
}
}
func HandleAddKeyError(ctx *middleware.Context, err error) {
func HandleAddKeyError(ctx *context.Context, err error) {
switch {
case models.IsErrKeyAlreadyExist(err):
ctx.APIError(422, "", "Key content has been used as non-deploy key")
@@ -81,7 +81,7 @@ func HandleAddKeyError(ctx *middleware.Context, err error) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
func CreateDeployKey(ctx *context.Context, form api.CreateKeyOption) {
content, err := models.CheckPublicKeyString(form.Key)
if err != nil {
HandleCheckKeyStringError(ctx, err)
@@ -100,7 +100,7 @@ func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
func DeleteDeploykey(ctx *middleware.Context) {
func DeleteDeploykey(ctx *context.Context) {
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")

View File

@@ -13,14 +13,14 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/routers/api/v1/convert"
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
func Search(ctx *middleware.Context) {
func Search(ctx *context.Context) {
opt := models.SearchOption{
Keyword: path.Base(ctx.Query("q")),
Uid: com.StrTo(ctx.Query("uid")).MustInt64(),
@@ -81,7 +81,7 @@ func Search(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
func ListMyRepos(ctx *middleware.Context) {
func ListMyRepos(ctx *context.Context) {
ownRepos, err := models.GetRepositories(ctx.User.Id, true)
if err != nil {
ctx.APIError(500, "GetRepositories", err)
@@ -113,7 +113,7 @@ func ListMyRepos(ctx *middleware.Context) {
ctx.JSON(200, &repos)
}
func CreateUserRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) {
func CreateUserRepo(ctx *context.Context, owner *models.User, opt api.CreateRepoOption) {
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
Name: opt.Name,
Description: opt.Description,
@@ -143,7 +143,7 @@ func CreateUserRepo(ctx *middleware.Context, owner *models.User, opt api.CreateR
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
func Create(ctx *middleware.Context, opt api.CreateRepoOption) {
func Create(ctx *context.Context, 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")
@@ -152,7 +152,7 @@ func Create(ctx *middleware.Context, opt api.CreateRepoOption) {
CreateUserRepo(ctx, ctx.User, opt)
}
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
func CreateOrgRepo(ctx *context.Context, opt api.CreateRepoOption) {
org, err := models.GetOrgByName(ctx.Params(":org"))
if err != nil {
if models.IsErrUserNotExist(err) {
@@ -171,7 +171,7 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) {
func Migrate(ctx *context.Context, form auth.MigrateRepoForm) {
ctxUser := ctx.User
// Not equal means context user is an organization,
// or is another user/organization if current user is admin.
@@ -242,7 +242,7 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true}))
}
func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) {
func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil {
if models.IsErrUserNotExist(err) {
@@ -267,7 +267,7 @@ func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repositor
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
func Get(ctx *middleware.Context) {
func Get(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() {
return
@@ -277,7 +277,7 @@ func Get(ctx *middleware.Context) {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
func Delete(ctx *middleware.Context) {
func Delete(ctx *context.Context) {
owner, repo := parseOwnerAndRepo(ctx)
if ctx.Written() {
return