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.

fix: render issue titles consistently (#6715)

- Render the issue titles in dashboard feed in consistent manner, by using the existing `RenderIssueTitle`.
- Added integration tests (not exhaustive for all comment types, but exhaustive enough for the current code where some comment types are grouped together).
- Resolves forgejo/forgejo#6705

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6715
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>

authored by

Gusted
Gusted
and committed by
Gusted
5e92674e bd6864fe

+68 -16
+4 -4
templates/user/dashboard/feeds.tmpl
··· 103 103 <a href="{{AppSubUrl}}/{{$push.CompareURL}}">{{ctx.Locale.Tr "action.compare_commits" $push.Len}} »</a> 104 104 {{end}} 105 105 {{else if .GetOpType.InActions "create_issue"}} 106 - <span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span> 106 + <span class="text truncate issue title">{{RenderIssueTitle ctx (index .GetIssueInfos 1) (.Repo.ComposeMetas ctx)}}</span> 107 107 {{else if .GetOpType.InActions "create_pull_request"}} 108 - <span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji $.Context | RenderCodeBlock}}</span> 108 + <span class="text truncate issue title">{{RenderIssueTitle ctx (index .GetIssueInfos 1) (.Repo.ComposeMetas ctx)}}</span> 109 109 {{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}} 110 - <a href="{{.GetCommentLink ctx}}" class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</a> 110 + <a href="{{.GetCommentLink ctx}}" class="text truncate issue title">{{RenderIssueTitle ctx (.GetIssueTitle ctx) (.Repo.ComposeMetas ctx)}}</a> 111 111 {{$comment := index .GetIssueInfos 1}} 112 112 {{if $comment}} 113 113 <div class="markup tw-text-14">{{RenderMarkdownToHtml ctx $comment}}</div> ··· 115 115 {{else if .GetOpType.InActions "merge_pull_request"}} 116 116 <div class="flex-item-body text black">{{index .GetIssueInfos 1}}</div> 117 117 {{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}} 118 - <span class="text truncate issue title">{{(.GetIssueTitle ctx) | RenderEmoji $.Context | RenderCodeBlock}}</span> 118 + <span class="text truncate issue title">{{RenderIssueTitle ctx (.GetIssueTitle ctx) (.Repo.ComposeMetas ctx)}}</span> 119 119 {{else if .GetOpType.InActions "pull_review_dismissed"}} 120 120 <div class="flex-item-body text black">{{ctx.Locale.Tr "action.review_dismissed_reason"}}</div> 121 121 <div class="flex-item-body text black">{{index .GetIssueInfos 2 | RenderEmoji $.Context}}</div>
+6 -9
tests/integration/pull_icon_test.go
··· 133 133 } 134 134 135 135 func createOpenPullRequest(ctx context.Context, t *testing.T, user *user_model.User, repo *repo_model.Repository) *issues_model.PullRequest { 136 - pull := createPullRequest(t, user, repo, "open") 136 + pull := createPullRequest(t, user, repo, "branch-open", "open") 137 137 138 138 assert.False(t, pull.Issue.IsClosed) 139 139 assert.False(t, pull.HasMerged) ··· 143 143 } 144 144 145 145 func createOpenWipPullRequest(ctx context.Context, t *testing.T, user *user_model.User, repo *repo_model.Repository) *issues_model.PullRequest { 146 - pull := createPullRequest(t, user, repo, "open-wip") 146 + pull := createPullRequest(t, user, repo, "branch-open-wip", "open-wip") 147 147 148 148 err := issue_service.ChangeTitle(ctx, pull.Issue, user, "WIP: "+pull.Issue.Title) 149 149 require.NoError(t, err) ··· 156 156 } 157 157 158 158 func createClosedPullRequest(ctx context.Context, t *testing.T, user *user_model.User, repo *repo_model.Repository) *issues_model.PullRequest { 159 - pull := createPullRequest(t, user, repo, "closed") 159 + pull := createPullRequest(t, user, repo, "branch-closed", "closed") 160 160 161 161 err := issue_service.ChangeStatus(ctx, pull.Issue, user, "", true) 162 162 require.NoError(t, err) ··· 169 169 } 170 170 171 171 func createClosedWipPullRequest(ctx context.Context, t *testing.T, user *user_model.User, repo *repo_model.Repository) *issues_model.PullRequest { 172 - pull := createPullRequest(t, user, repo, "closed-wip") 172 + pull := createPullRequest(t, user, repo, "branch-closed-wip", "closed-wip") 173 173 174 174 err := issue_service.ChangeTitle(ctx, pull.Issue, user, "WIP: "+pull.Issue.Title) 175 175 require.NoError(t, err) ··· 185 185 } 186 186 187 187 func createMergedPullRequest(ctx context.Context, t *testing.T, user *user_model.User, repo *repo_model.Repository) *issues_model.PullRequest { 188 - pull := createPullRequest(t, user, repo, "merged") 188 + pull := createPullRequest(t, user, repo, "branch-merged", "merged") 189 189 190 190 gitRepo, err := git.OpenRepository(ctx, repo.RepoPath()) 191 191 defer gitRepo.Close() ··· 202 202 return pull 203 203 } 204 204 205 - func createPullRequest(t *testing.T, user *user_model.User, repo *repo_model.Repository, name string) *issues_model.PullRequest { 206 - branch := "branch-" + name 207 - title := "Testing " + name 208 - 205 + func createPullRequest(t *testing.T, user *user_model.User, repo *repo_model.Repository, branch, title string) *issues_model.PullRequest { 209 206 _, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user, &files_service.ChangeRepoFilesOptions{ 210 207 Files: []*files_service.ChangeRepoFile{ 211 208 {
+7 -3
tests/integration/pull_review_test.go
··· 518 518 resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "a-test-branch", "This is a pull title") 519 519 elem := strings.Split(test.RedirectURL(resp), "/") 520 520 assert.EqualValues(t, "pulls", elem[3]) 521 - testIssueClose(t, user1Session, elem[1], elem[2], elem[4]) 521 + testIssueClose(t, user1Session, elem[1], elem[2], elem[4], true) 522 522 523 523 // Get the commit SHA 524 524 pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ ··· 579 579 return session.MakeRequest(t, req, expectedSubmitStatus) 580 580 } 581 581 582 - func testIssueClose(t *testing.T, session *TestSession, owner, repo, issueNumber string) *httptest.ResponseRecorder { 583 - req := NewRequest(t, "GET", path.Join(owner, repo, "pulls", issueNumber)) 582 + func testIssueClose(t *testing.T, session *TestSession, owner, repo, issueNumber string, isPull bool) *httptest.ResponseRecorder { 583 + issueType := "issues" 584 + if isPull { 585 + issueType = "pulls" 586 + } 587 + req := NewRequest(t, "GET", path.Join(owner, repo, issueType, issueNumber)) 584 588 resp := session.MakeRequest(t, req, http.StatusOK) 585 589 586 590 htmlDoc := NewHTMLParser(t, resp.Body)
+51
tests/integration/user_dashboard_test.go
··· 5 5 6 6 import ( 7 7 "net/http" 8 + "net/url" 9 + "strconv" 8 10 "strings" 9 11 "testing" 10 12 13 + "code.gitea.io/gitea/models/db" 14 + unit_model "code.gitea.io/gitea/models/unit" 11 15 "code.gitea.io/gitea/models/unittest" 16 + user_model "code.gitea.io/gitea/models/user" 12 17 "code.gitea.io/gitea/modules/translation" 18 + issue_service "code.gitea.io/gitea/services/issue" 19 + files_service "code.gitea.io/gitea/services/repository/files" 20 + "code.gitea.io/gitea/tests" 13 21 22 + "github.com/PuerkitoBio/goquery" 14 23 "github.com/stretchr/testify/assert" 15 24 "github.com/stretchr/testify/require" 16 25 ) ··· 28 37 assert.EqualValues(t, locale.TrString("new_migrate.link"), strings.TrimSpace(links.Find("a[href='/repo/migrate']").Text())) 29 38 assert.EqualValues(t, locale.TrString("new_org.link"), strings.TrimSpace(links.Find("a[href='/org/create']").Text())) 30 39 } 40 + 41 + func TestDashboardTitleRendering(t *testing.T) { 42 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 43 + user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) 44 + sess := loginUser(t, user4.Name) 45 + 46 + repo, _, f := tests.CreateDeclarativeRepo(t, user4, "", 47 + []unit_model.Type{unit_model.TypePullRequests, unit_model.TypeIssues}, nil, 48 + []*files_service.ChangeRepoFile{ 49 + { 50 + Operation: "create", 51 + TreePath: "test.txt", 52 + ContentReader: strings.NewReader("Just some text here"), 53 + }, 54 + }, 55 + ) 56 + defer f() 57 + 58 + issue := createIssue(t, user4, repo, "`:exclamation:` not rendered", "Hi there!") 59 + pr := createPullRequest(t, user4, repo, "testing", "`:exclamation:` not rendered") 60 + 61 + _, err := issue_service.CreateIssueComment(db.DefaultContext, user4, repo, issue, "hi", nil) 62 + require.NoError(t, err) 63 + 64 + _, err = issue_service.CreateIssueComment(db.DefaultContext, user4, repo, pr.Issue, "hi", nil) 65 + require.NoError(t, err) 66 + 67 + testIssueClose(t, sess, repo.OwnerName, repo.Name, strconv.Itoa(int(issue.Index)), false) 68 + testIssueClose(t, sess, repo.OwnerName, repo.Name, strconv.Itoa(int(pr.Issue.Index)), true) 69 + 70 + response := sess.MakeRequest(t, NewRequest(t, "GET", "/"), http.StatusOK) 71 + htmlDoc := NewHTMLParser(t, response.Body) 72 + 73 + count := 0 74 + htmlDoc.doc.Find("#activity-feed .flex-item-main .title").Each(func(i int, s *goquery.Selection) { 75 + count++ 76 + assert.EqualValues(t, ":exclamation: not rendered", s.Text()) 77 + }) 78 + 79 + assert.EqualValues(t, 6, count) 80 + }) 81 + }