Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
53 lines
1.5 KiB
Go
53 lines
1.5 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
|
|
}
|
|
if !loadContextDoerPermission(ctx, opts.UserID, opts.UserExtDoerData) {
|
|
return
|
|
}
|
|
|
|
results, err := agit.ProcReceive(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, &agit.ProcReceiveOptions{
|
|
OldCommitIDs: opts.OldCommitIDs,
|
|
NewCommitIDs: opts.NewCommitIDs,
|
|
RefFullNames: opts.RefFullNames,
|
|
GitPushOptions: opts.GitPushOptions,
|
|
Doer: ctx.Doer,
|
|
})
|
|
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,
|
|
})
|
|
}
|