Files
Gitea/routers/private/hook_proc_receive.go
T
wxiaoguang 943f026844 refactor: deploy key and private route handlers (#38999)
clean up legacy code, fix various bugs:

* add missing "return"
2026-08-20 15:57:17 +00:00

44 lines
1.3 KiB
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package private
import (
"errors"
"net/http"
issues_model "gitea.dev/models/issues"
user_model "gitea.dev/models/user"
"gitea.dev/modules/git"
"gitea.dev/modules/private"
"gitea.dev/modules/web"
"gitea.dev/services/agit"
gitea_context "gitea.dev/services/context"
)
// HookProcReceive proc-receive hook - only handles agit Proc-Receive requests at present
func HookProcReceive(ctx *gitea_context.PrivateContext) {
opts := web.GetForm[*private.HookOptions](ctx)
if !git.DefaultFeatures().SupportProcReceive {
ctx.Status(http.StatusNotFound)
return
}
results, err := agit.ProcReceive(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, opts)
if err != nil {
if errors.Is(err, issues_model.ErrMustCollaborator) {
ctx.PrivateUserErrorf(http.StatusUnauthorized, "You must be a collaborator to create pull request.")
} else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.PrivateUserErrorf(http.StatusUnauthorized, "Cannot create pull request because you are blocked by the repository owner.")
} else {
ctx.PrivateInternalErrorf("agit.ProcReceive failed: %v", err)
}
return
}
ctx.JSON(http.StatusOK, private.HookProcReceiveResult{
Results: results,
})
}