From e6d6bce1f6e13977ed293356376b3ded04127202 Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Sun, 29 Jan 2023 18:55:45 -0600 Subject: [PATCH] Fix missing message in git hook when pull requests disabled on fork (#22625) (#22658) Backport #22625 Co-authored-by: Brecht Van Lommel --- routers/private/hook_post_receive.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 93aa450f9c3b7..614daddc3916f 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -174,13 +174,6 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { return } - if !repo.AllowsPulls() { - // We can stop there's no need to go any further - ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ - RepoWasEmpty: wasEmpty, - }) - return - } baseRepo = repo if repo.IsFork { @@ -192,7 +185,17 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { }) return } - baseRepo = repo.BaseRepo + if repo.BaseRepo.AllowsPulls() { + baseRepo = repo.BaseRepo + } + } + + if !baseRepo.AllowsPulls() { + // We can stop there's no need to go any further + ctx.JSON(http.StatusOK, private.HookPostReceiveResult{ + RepoWasEmpty: wasEmpty, + }) + return } } @@ -218,14 +221,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { branch = fmt.Sprintf("%s:%s", repo.OwnerName, branch) } results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), Create: true, Branch: branch, URL: fmt.Sprintf("%s/compare/%s...%s", baseRepo.HTMLURL(), util.PathEscapeSegments(baseRepo.DefaultBranch), util.PathEscapeSegments(branch)), }) } else { results = append(results, private.HookPostReceiveBranchResult{ - Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Message: setting.Git.PullRequestPushMessage && baseRepo.AllowsPulls(), Create: false, Branch: branch, URL: fmt.Sprintf("%s/pulls/%d", baseRepo.HTMLURL(), pr.Index),