From 21bd0ef40ae8a33a3843f2b1d78f5b4c35ac3225 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Sun, 2 Oct 2022 17:04:59 +0200 Subject: [PATCH] Fix formatted link for PR review notifications to matrix --- services/webhook/matrix.go | 4 ++-- services/webhook/matrix_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index f4c4cf0e9a01e..59eae48307bc5 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -195,7 +195,7 @@ func (m *MatrixPayloadUnsafe) PullRequest(p *api.PullRequestPayload) (api.Payloa func (m *MatrixPayloadUnsafe) Review(p *api.PullRequestPayload, event webhook_model.HookEventType) (api.Payloader, error) { senderLink := MatrixLinkFormatter(setting.AppURL+url.PathEscape(p.Sender.UserName), p.Sender.UserName) title := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title) - titleLink := fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index) + titleLink := MatrixLinkFormatter(p.PullRequest.URL, title) repoLink := MatrixLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName) var text string @@ -206,7 +206,7 @@ func (m *MatrixPayloadUnsafe) Review(p *api.PullRequestPayload, event webhook_mo return nil, err } - text = fmt.Sprintf("[%s] Pull request review %s: [%s](%s) by %s", repoLink, action, title, titleLink, senderLink) + text = fmt.Sprintf("[%s] Pull request review %s: %s by %s", repoLink, action, titleLink, senderLink) } return getMatrixPayloadUnsafe(text, nil, m.AccessToken, m.MsgType), nil diff --git a/services/webhook/matrix_test.go b/services/webhook/matrix_test.go index 4cab845330c32..624986ee9b95a 100644 --- a/services/webhook/matrix_test.go +++ b/services/webhook/matrix_test.go @@ -140,7 +140,7 @@ func TestMatrixPayload(t *testing.T) { require.IsType(t, &MatrixPayloadUnsafe{}, pl) assert.Equal(t, "[[test/repo](http://localhost:3000/test/repo)] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by [user1](https://try.gitea.io/user1)", pl.(*MatrixPayloadUnsafe).Body) - assert.Equal(t, `[test/repo] Pull request review approved: [#12 Fix bug](http://localhost:3000/test/repo/pulls/12) by user1`, pl.(*MatrixPayloadUnsafe).FormattedBody) + assert.Equal(t, `[test/repo] Pull request review approved: #12 Fix bug by user1`, pl.(*MatrixPayloadUnsafe).FormattedBody) }) t.Run("Repository", func(t *testing.T) {