mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-21 22:40:37 +00:00
943f026844
clean up legacy code, fix various bugs: * add missing "return"
44 lines
1.3 KiB
Go
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,
|
|
})
|
|
}
|