From 46357e7856edc511aff956299af7e1eb85486f67 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Wed, 31 Jul 2024 13:55:14 +0200 Subject: [PATCH] fix: use `url.JoinPath` to join url parts This avoids duplicated or more slashes. fixes #4759 --- services/pull/merge.go | 7 ++++++- services/pull/pull_test.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/services/pull/merge.go b/services/pull/merge.go index 75b22e00b3..57f3b1e377 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -7,6 +7,7 @@ package pull import ( "context" "fmt" + "net/url" "os" "path/filepath" "regexp" @@ -56,7 +57,11 @@ func getMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issue issueReference = "!" } - reviewedOn := fmt.Sprintf("Reviewed-on: %s/%s", setting.AppURL, pr.Issue.Link()) + issueURL, err := url.JoinPath(setting.AppURL, pr.Issue.Link()) + if err != nil { + return "", "", err + } + reviewedOn := fmt.Sprintf("Reviewed-on: %s", issueURL) reviewedBy := pr.GetApprovers(ctx) if mergeStyle != "" { diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go index ac67d03ee0..c51619e7f6 100644 --- a/services/pull/pull_test.go +++ b/services/pull/pull_test.go @@ -47,9 +47,10 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) { require.NoError(t, err) defer gitRepo.Close() - mergeMessage, _, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "") + mergeMessage, body, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "") require.NoError(t, err) assert.Equal(t, "Merge pull request 'issue3' (#3) from branch2 into master", mergeMessage) + assert.Equal(t, "Reviewed-on: https://try.gitea.io/user2/repo1/pulls/3\n", body) pr.BaseRepoID = 1 pr.HeadRepoID = 2