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.

Use absolute links in feeds (#21229)

fixes #20864

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>

authored by

KN4CK3R
wxiaoguang
techknowlogick
and committed by
GitHub
f52fe82a acee32ca

+43 -34
+5
models/activities/action.go
··· 218 218 return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName()), url.PathEscape(a.GetRepoName())) 219 219 } 220 220 221 + // GetRepoAbsoluteLink returns the absolute link to action repository. 222 + func (a *Action) GetRepoAbsoluteLink() string { 223 + return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName()) 224 + } 225 + 221 226 // GetCommentLink returns link to action comment. 222 227 func (a *Action) GetCommentLink() string { 223 228 return a.getCommentLink(db.DefaultContext)
+7 -3
models/activities/action_test.go
··· 10 10 11 11 activities_model "code.gitea.io/gitea/models/activities" 12 12 "code.gitea.io/gitea/models/db" 13 + issue_model "code.gitea.io/gitea/models/issues" 13 14 repo_model "code.gitea.io/gitea/models/repo" 14 15 "code.gitea.io/gitea/models/unittest" 15 16 user_model "code.gitea.io/gitea/models/user" ··· 20 21 21 22 func TestAction_GetRepoPath(t *testing.T) { 22 23 assert.NoError(t, unittest.PrepareTestDatabase()) 23 - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}) 24 + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) 24 25 owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 25 26 action := &activities_model.Action{RepoID: repo.ID} 26 27 assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath()) ··· 28 29 29 30 func TestAction_GetRepoLink(t *testing.T) { 30 31 assert.NoError(t, unittest.PrepareTestDatabase()) 31 - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}) 32 + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) 32 33 owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 33 - action := &activities_model.Action{RepoID: repo.ID} 34 + comment := unittest.AssertExistsAndLoadBean(t, &issue_model.Comment{ID: 2}) 35 + action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID} 34 36 setting.AppSubURL = "/suburl" 35 37 expected := path.Join(setting.AppSubURL, owner.Name, repo.Name) 36 38 assert.Equal(t, expected, action.GetRepoLink()) 39 + assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink()) 40 + assert.Equal(t, comment.HTMLURL(), action.GetCommentLink()) 37 41 } 38 42 39 43 func TestGetFeeds(t *testing.T) {
+31 -31
routers/web/feed/convert.go
··· 24 24 ) 25 25 26 26 func toBranchLink(act *activities_model.Action) string { 27 - return act.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(act.GetBranch()) 27 + return act.GetRepoAbsoluteLink() + "/src/branch/" + util.PathEscapeSegments(act.GetBranch()) 28 28 } 29 29 30 30 func toTagLink(act *activities_model.Action) string { 31 - return act.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(act.GetTag()) 31 + return act.GetRepoAbsoluteLink() + "/src/tag/" + util.PathEscapeSegments(act.GetTag()) 32 32 } 33 33 34 34 func toIssueLink(act *activities_model.Action) string { 35 - return act.GetRepoLink() + "/issues/" + url.PathEscape(act.GetIssueInfos()[0]) 35 + return act.GetRepoAbsoluteLink() + "/issues/" + url.PathEscape(act.GetIssueInfos()[0]) 36 36 } 37 37 38 38 func toPullLink(act *activities_model.Action) string { 39 - return act.GetRepoLink() + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0]) 39 + return act.GetRepoAbsoluteLink() + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0]) 40 40 } 41 41 42 42 func toSrcLink(act *activities_model.Action) string { 43 - return act.GetRepoLink() + "/src/" + util.PathEscapeSegments(act.GetBranch()) 43 + return act.GetRepoAbsoluteLink() + "/src/" + util.PathEscapeSegments(act.GetBranch()) 44 44 } 45 45 46 46 func toReleaseLink(act *activities_model.Action) string { 47 - return act.GetRepoLink() + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch()) 47 + return act.GetRepoAbsoluteLink() + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch()) 48 48 } 49 49 50 50 // renderMarkdown creates a minimal markdown render context from an action. ··· 79 79 title = act.ActUser.DisplayName() + " " 80 80 switch act.OpType { 81 81 case activities_model.ActionCreateRepo: 82 - title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoLink(), act.ShortRepoPath()) 83 - link.Href = act.GetRepoLink() 82 + title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(), act.ShortRepoPath()) 83 + link.Href = act.GetRepoAbsoluteLink() 84 84 case activities_model.ActionRenameRepo: 85 - title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoLink(), act.ShortRepoPath()) 86 - link.Href = act.GetRepoLink() 85 + title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath()) 86 + link.Href = act.GetRepoAbsoluteLink() 87 87 case activities_model.ActionCommitRepo: 88 88 link.Href = toBranchLink(act) 89 89 if len(act.Content) != 0 { 90 - title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) 90 + title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoAbsoluteLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) 91 91 } else { 92 - title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) 92 + title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoAbsoluteLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) 93 93 } 94 94 case activities_model.ActionCreateIssue: 95 95 link.Href = toIssueLink(act) ··· 98 98 link.Href = toPullLink(act) 99 99 title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath()) 100 100 case activities_model.ActionTransferRepo: 101 - link.Href = act.GetRepoLink() 102 - title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoLink(), act.ShortRepoPath()) 101 + link.Href = act.GetRepoAbsoluteLink() 102 + title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(), act.ShortRepoPath()) 103 103 case activities_model.ActionPushTag: 104 104 link.Href = toTagLink(act) 105 - title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoLink(), link.Href, act.GetTag(), act.ShortRepoPath()) 105 + title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(), link.Href, act.GetTag(), act.ShortRepoPath()) 106 106 case activities_model.ActionCommentIssue: 107 107 issueLink := toIssueLink(act) 108 108 if link.Href == "#" { ··· 140 140 } 141 141 title += ctx.TrHTMLEscapeArgs("action.reopen_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) 142 142 case activities_model.ActionDeleteTag: 143 - link.Href = act.GetRepoLink() 144 - title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoLink(), act.GetTag(), act.ShortRepoPath()) 143 + link.Href = act.GetRepoAbsoluteLink() 144 + title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(), act.GetTag(), act.ShortRepoPath()) 145 145 case activities_model.ActionDeleteBranch: 146 - link.Href = act.GetRepoLink() 147 - title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoLink(), html.EscapeString(act.GetBranch()), act.ShortRepoPath()) 146 + link.Href = act.GetRepoAbsoluteLink() 147 + title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(), html.EscapeString(act.GetBranch()), act.ShortRepoPath()) 148 148 case activities_model.ActionMirrorSyncPush: 149 149 srcLink := toSrcLink(act) 150 150 if link.Href == "#" { 151 151 link.Href = srcLink 152 152 } 153 - title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) 153 + title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoAbsoluteLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) 154 154 case activities_model.ActionMirrorSyncCreate: 155 155 srcLink := toSrcLink(act) 156 156 if link.Href == "#" { 157 157 link.Href = srcLink 158 158 } 159 - title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) 159 + title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoAbsoluteLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) 160 160 case activities_model.ActionMirrorSyncDelete: 161 - link.Href = act.GetRepoLink() 162 - title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoLink(), act.GetBranch(), act.ShortRepoPath()) 161 + link.Href = act.GetRepoAbsoluteLink() 162 + title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(), act.GetBranch(), act.ShortRepoPath()) 163 163 case activities_model.ActionApprovePullRequest: 164 164 pullLink := toPullLink(act) 165 165 title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) ··· 174 174 if link.Href == "#" { 175 175 link.Href = releaseLink 176 176 } 177 - title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoLink(), releaseLink, act.ShortRepoPath(), act.Content) 177 + title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoAbsoluteLink(), releaseLink, act.ShortRepoPath(), act.Content) 178 178 case activities_model.ActionPullReviewDismissed: 179 179 pullLink := toPullLink(act) 180 180 title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(), act.GetIssueInfos()[1]) 181 181 case activities_model.ActionStarRepo: 182 - link.Href = act.GetRepoLink() 183 - title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoLink(), act.GetRepoPath()) 182 + link.Href = act.GetRepoAbsoluteLink() 183 + title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath()) 184 184 case activities_model.ActionWatchRepo: 185 - link.Href = act.GetRepoLink() 186 - title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoLink(), act.GetRepoPath()) 185 + link.Href = act.GetRepoAbsoluteLink() 186 + title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(), act.GetRepoPath()) 187 187 default: 188 188 return nil, fmt.Errorf("unknown action type: %v", act.OpType) 189 189 } ··· 193 193 switch act.OpType { 194 194 case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush: 195 195 push := templates.ActionContent2Commits(act) 196 - repoLink := act.GetRepoLink() 196 + repoLink := act.GetRepoAbsoluteLink() 197 197 198 198 for _, commit := range push.Commits { 199 199 if len(desc) != 0 { 200 200 desc += "\n\n" 201 201 } 202 202 desc += fmt.Sprintf("<a href=\"%s\">%s</a>\n%s", 203 - html.EscapeString(fmt.Sprintf("%s/commit/%s", act.GetRepoLink(), commit.Sha1)), 203 + html.EscapeString(fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(), commit.Sha1)), 204 204 commit.Sha1, 205 205 templates.RenderCommitMessage(ctx, commit.Message, repoLink, nil), 206 206 ) ··· 209 209 if push.Len > 1 { 210 210 link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)} 211 211 } else if push.Len == 1 { 212 - link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoLink(), push.Commits[0].Sha1)} 212 + link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(), push.Commits[0].Sha1)} 213 213 } 214 214 215 215 case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest: