Files
forge/routers/private/hook_proc_receive.go
zeekayandHanzo Dev aa87442fdd Record upstream authorship centrally in NOTICE instead of in every file header
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the
Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in
NOTICE, alongside LICENSE. The header lint accepts any copyright line above the
SPDX line, so it no longer demands an upstream one.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 17:50:35 -07:00

52 lines
1.5 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// SPDX-License-Identifier: MIT
package private
import (
"errors"
"net/http"
issues_model "github.com/hanzoai/git/models/issues"
user_model "github.com/hanzoai/git/models/user"
"github.com/hanzoai/git/modules/git"
"github.com/hanzoai/git/modules/log"
"github.com/hanzoai/git/modules/private"
"github.com/hanzoai/git/modules/web"
"github.com/hanzoai/git/services/agit"
git_context "github.com/hanzoai/git/services/context"
)
// HookProcReceive proc-receive hook - only handles agit Proc-Receive requests at present
func HookProcReceive(ctx *git_context.PrivateContext) {
opts := web.GetForm(ctx).(*private.HookOptions)
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.JSON(http.StatusUnauthorized, private.Response{
Err: err.Error(), UserMsg: "You must be a collaborator to create pull request.",
})
} else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.JSON(http.StatusUnauthorized, private.Response{
Err: err.Error(), UserMsg: "Cannot create pull request because you are blocked by the repository owner.",
})
} else {
log.Error("agit.ProcReceive failed: %v", err)
ctx.JSON(http.StatusInternalServerError, private.Response{
Err: err.Error(),
})
}
return
}
ctx.JSON(http.StatusOK, private.HookProcReceiveResult{
Results: results,
})
}