loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request '[port] Use old behavior for telegram webhook (gitea#31588)' (#4504) from algernon/forgejo:gitea/port/31588 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4504
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+29 -18
+2 -1
services/webhook/telegram.go
··· 15 15 "code.gitea.io/gitea/modules/git" 16 16 "code.gitea.io/gitea/modules/json" 17 17 "code.gitea.io/gitea/modules/log" 18 + "code.gitea.io/gitea/modules/markup" 18 19 api "code.gitea.io/gitea/modules/structs" 19 20 webhook_module "code.gitea.io/gitea/modules/webhook" 20 21 "code.gitea.io/gitea/services/forms" ··· 213 214 214 215 func createTelegramPayload(message string) TelegramPayload { 215 216 return TelegramPayload{ 216 - Message: strings.TrimSpace(message), 217 + Message: markup.Sanitize(strings.TrimSpace(message)), 217 218 ParseMode: "HTML", 218 219 DisableWebPreview: true, 219 220 }
+27 -17
services/webhook/telegram_test.go
··· 33 33 pl, err := tc.Create(p) 34 34 require.NoError(t, err) 35 35 36 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test">test</a> created`, pl.Message) 36 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> created`, pl.Message) 37 37 }) 38 38 39 39 t.Run("Delete", func(t *testing.T) { ··· 42 42 pl, err := tc.Delete(p) 43 43 require.NoError(t, err) 44 44 45 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test">test</a> deleted`, pl.Message) 45 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a> deleted`, pl.Message) 46 46 }) 47 47 48 48 t.Run("Fork", func(t *testing.T) { ··· 51 51 pl, err := tc.Fork(p) 52 52 require.NoError(t, err) 53 53 54 - assert.Equal(t, `test/repo2 is forked to <a href="http://localhost:3000/test/repo">test/repo</a>`, pl.Message) 54 + assert.Equal(t, `test/repo2 is forked to <a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>`, pl.Message) 55 55 }) 56 56 57 57 t.Run("Push", func(t *testing.T) { ··· 60 60 pl, err := tc.Push(p) 61 61 require.NoError(t, err) 62 62 63 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>:<a href=\"http://localhost:3000/test/repo/src/test\">test</a>] 2 new commits\n[<a href=\"http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\">2020558</a>] commit message - user1\n[<a href=\"http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\">2020558</a>] commit message - user1", pl.Message) 63 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>:<a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a>] 2 new commits 64 + [<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1 65 + [<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1`, pl.Message) 64 66 }) 65 67 66 68 t.Run("Issue", func(t *testing.T) { ··· 70 72 pl, err := tc.Issue(p) 71 73 require.NoError(t, err) 72 74 73 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] Issue opened: <a href=\"http://localhost:3000/test/repo/issues/2\">#2 crash</a> by <a href=\"https://try.gitea.io/user1\">user1</a>\n\nissue body", pl.Message) 75 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue opened: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a> 76 + 77 + issue body`, pl.Message) 74 78 75 79 p.Action = api.HookIssueClosed 76 80 pl, err = tc.Issue(p) 77 81 require.NoError(t, err) 78 82 79 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Issue closed: <a href="http://localhost:3000/test/repo/issues/2">#2 crash</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 83 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Issue closed: <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 80 84 }) 81 85 82 86 t.Run("IssueComment", func(t *testing.T) { ··· 85 89 pl, err := tc.IssueComment(p) 86 90 require.NoError(t, err) 87 91 88 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] New comment on issue <a href=\"http://localhost:3000/test/repo/issues/2\">#2 crash</a> by <a href=\"https://try.gitea.io/user1\">user1</a>\nmore info needed", pl.Message) 92 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on issue <a href="http://localhost:3000/test/repo/issues/2" rel="nofollow">#2 crash</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a> 93 + more info needed`, pl.Message) 89 94 }) 90 95 91 96 t.Run("PullRequest", func(t *testing.T) { ··· 94 99 pl, err := tc.PullRequest(p) 95 100 require.NoError(t, err) 96 101 97 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] Pull request opened: <a href=\"http://localhost:3000/test/repo/pulls/12\">#12 Fix bug</a> by <a href=\"https://try.gitea.io/user1\">user1</a>\nfixes bug #2", pl.Message) 102 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Pull request opened: <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a> 103 + fixes bug #2`, pl.Message) 98 104 }) 99 105 100 106 t.Run("PullRequestComment", func(t *testing.T) { ··· 103 109 pl, err := tc.IssueComment(p) 104 110 require.NoError(t, err) 105 111 106 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>] New comment on pull request <a href=\"http://localhost:3000/test/repo/pulls/12\">#12 Fix bug</a> by <a href=\"https://try.gitea.io/user1\">user1</a>\nchanges requested", pl.Message) 112 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New comment on pull request <a href="http://localhost:3000/test/repo/pulls/12" rel="nofollow">#12 Fix bug</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a> 113 + changes requested`, pl.Message) 107 114 }) 108 115 109 116 t.Run("Review", func(t *testing.T) { ··· 113 120 pl, err := tc.Review(p, webhook_module.HookEventPullRequestReviewApproved) 114 121 require.NoError(t, err) 115 122 116 - assert.Equal(t, "[test/repo] Pull request review approved: #12 Fix bug\ngood job", pl.Message) 123 + assert.Equal(t, `[test/repo] Pull request review approved: #12 Fix bug 124 + good job`, pl.Message) 117 125 }) 118 126 119 127 t.Run("Repository", func(t *testing.T) { ··· 122 130 pl, err := tc.Repository(p) 123 131 require.NoError(t, err) 124 132 125 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Repository created`, pl.Message) 133 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Repository created`, pl.Message) 126 134 }) 127 135 128 136 t.Run("Package", func(t *testing.T) { ··· 131 139 pl, err := tc.Package(p) 132 140 require.NoError(t, err) 133 141 134 - assert.Equal(t, `Package created: <a href="http://localhost:3000/user1/-/packages/container/GiteaContainer/latest">GiteaContainer:latest</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 142 + assert.Equal(t, `Package created: <a href="http://localhost:3000/user1/-/packages/container/GiteaContainer/latest" rel="nofollow">GiteaContainer:latest</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 135 143 }) 136 144 137 145 t.Run("Wiki", func(t *testing.T) { ··· 141 149 pl, err := tc.Wiki(p) 142 150 require.NoError(t, err) 143 151 144 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] New wiki page '<a href="http://localhost:3000/test/repo/wiki/index">index</a>' (Wiki change comment) by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 152 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] New wiki page &#39;<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>&#39; (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 145 153 146 154 p.Action = api.HookWikiEdited 147 155 pl, err = tc.Wiki(p) 148 156 require.NoError(t, err) 149 157 150 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index">index</a>' edited (Wiki change comment) by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 158 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page &#39;<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>&#39; edited (Wiki change comment) by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 151 159 152 160 p.Action = api.HookWikiDeleted 153 161 pl, err = tc.Wiki(p) 154 162 require.NoError(t, err) 155 163 156 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Wiki page '<a href="http://localhost:3000/test/repo/wiki/index">index</a>' deleted by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 164 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Wiki page &#39;<a href="http://localhost:3000/test/repo/wiki/index" rel="nofollow">index</a>&#39; deleted by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 157 165 }) 158 166 159 167 t.Run("Release", func(t *testing.T) { ··· 162 170 pl, err := tc.Release(p) 163 171 require.NoError(t, err) 164 172 165 - assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.Message) 173 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/releases/tag/v1.0" rel="nofollow">v1.0</a> by <a href="https://try.gitea.io/user1" rel="nofollow">user1</a>`, pl.Message) 166 174 }) 167 175 } 168 176 ··· 198 206 var body TelegramPayload 199 207 err = json.NewDecoder(req.Body).Decode(&body) 200 208 assert.NoError(t, err) 201 - assert.Equal(t, "[<a href=\"http://localhost:3000/test/repo\">test/repo</a>:<a href=\"http://localhost:3000/test/repo/src/test\">test</a>] 2 new commits\n[<a href=\"http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\">2020558</a>] commit message - user1\n[<a href=\"http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\">2020558</a>] commit message - user1", body.Message) 209 + assert.Equal(t, `[<a href="http://localhost:3000/test/repo" rel="nofollow">test/repo</a>:<a href="http://localhost:3000/test/repo/src/test" rel="nofollow">test</a>] 2 new commits 210 + [<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1 211 + [<a href="http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778" rel="nofollow">2020558</a>] commit message - user1`, body.Message) 202 212 }