feat: show link to pull requests targeting a non-default branch when pushing (#10079)

This resolves #10057 by showing a list of links to pull requests with the head branch being the one just pushed.

Since there may be multiple pull requests with different base branches, we find all of them and print them.

Here is a comparison table for pushing to the `feature` branch when having 2 pull requests: `feature -> dev`, and `feature -> prod`. `main` being the default branch.

## Before

remote:
remote: Create a new pull request for 'feature':
remote:   http://localhost:3000/user1/repo1/compare/main...feature
remote:

## After

remote:
remote: Create a new pull request for 'feature':
remote:   http://localhost:3000/user1/repo1/compare/main...feature
remote: Visit the existing pull requests:
remote:   http://localhost:3000/user1/repo1/pulls/1 merges into dev
remote:   http://localhost:3000/user1/repo1/pulls/3 merges into prod
remote:

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10079
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Calixte Pernot <cpernot@praksys.net>
Co-committed-by: Calixte Pernot <cpernot@praksys.net>
This commit is contained in:
Calixte Pernot
2025-11-19 14:59:13 +01:00
committed by Gusted
parent 37f8fcf66d
commit 4d0c7db6cd
6 changed files with 193 additions and 33 deletions
+11 -4
View File
@@ -452,10 +452,17 @@ func hookPrintResults(results []private.HookPostReceiveBranchResult) {
fmt.Fprintln(os.Stderr, "")
if res.Create {
fmt.Fprintf(os.Stderr, "Create a new pull request for '%s':\n", res.Branch)
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
} else {
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
fmt.Fprintf(os.Stderr, " %s\n", res.URL)
fmt.Fprintf(os.Stderr, " %s\n", res.CreateURL)
}
if len(res.PullURLS) != 0 {
if len(res.PullURLS) >= 2 {
fmt.Fprint(os.Stderr, "Visit the existing pull requests:\n")
} else {
fmt.Fprint(os.Stderr, "Visit the existing pull request:\n")
}
for _, url := range res.PullURLS {
fmt.Fprintf(os.Stderr, " %s\n", url)
}
}
fmt.Fprintln(os.Stderr, "")
_ = os.Stderr.Sync()