Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing message in git hook when pull requests disabled on fork #22625

Merged
merged 8 commits into from
Jan 29, 2023
19 changes: 10 additions & 9 deletions routers/private/hook_post_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,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 {
Expand All @@ -193,6 +186,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
}
baseRepo = repo.BaseRepo
}

if !baseRepo.AllowsPulls() {
brechtvl marked this conversation as resolved.
Show resolved Hide resolved
// We can stop there's no need to go any further
ctx.JSON(http.StatusOK, private.HookPostReceiveResult{
RepoWasEmpty: wasEmpty,
})
return
}
}

// If our branch is the default branch of an unforked repo - there's no PR to create or refer to
Expand All @@ -217,14 +218,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),
Expand Down