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 'Fix expand diff in pull requests being 404 (port of gitea#31013)' (#3885) from algernon/forgejo:gitea/port/31013 into forgejo

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

+44 -8
+4 -3
templates/repo/diff/section_split.tmpl
··· 1 1 {{$file := .file}} 2 + {{$blobExcerptRepoLink := or $.root.CommitRepoLink $.root.RepoLink}} 2 3 <colgroup> 3 4 <col width="50"> 4 5 <col width="10"> ··· 18 19 <td class="lines-num lines-num-old"> 19 20 <div class="tw-flex"> 20 21 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} 21 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 22 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 22 23 {{svg "octicon-fold-down"}} 23 24 </button> 24 25 {{end}} 25 26 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} 26 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 27 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 27 28 {{svg "octicon-fold-up"}} 28 29 </button> 29 30 {{end}} 30 31 {{if eq $line.GetExpandDirection 2}} 31 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 32 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 32 33 {{svg "octicon-fold"}} 33 34 </button> 34 35 {{end}}
+4 -3
templates/repo/diff/section_unified.tmpl
··· 1 1 {{$file := .file}} 2 + {{$blobExcerptRepoLink := or $.root.CommitRepoLink $.root.RepoLink}} 2 3 <colgroup> 3 4 <col width="50"> 4 5 <col width="50"> ··· 14 15 <td colspan="2" class="lines-num"> 15 16 <div class="tw-flex"> 16 17 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5)}} 17 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 18 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 18 19 {{svg "octicon-fold-down"}} 19 20 </button> 20 21 {{end}} 21 22 {{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4)}} 22 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 23 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 23 24 {{svg "octicon-fold-up"}} 24 25 </button> 25 26 {{end}} 26 27 {{if eq $line.GetExpandDirection 2}} 27 - <button class="code-expander-button" hx-target="closest tr" hx-get="{{$.root.CommitRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 28 + <button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}"> 28 29 {{svg "octicon-fold"}} 29 30 </button> 30 31 {{end}}
+36 -2
tests/integration/compare_test.go
··· 18 18 user_model "code.gitea.io/gitea/models/user" 19 19 "code.gitea.io/gitea/modules/gitrepo" 20 20 "code.gitea.io/gitea/modules/optional" 21 + "code.gitea.io/gitea/modules/test" 21 22 repo_service "code.gitea.io/gitea/services/repository" 22 23 files_service "code.gitea.io/gitea/services/repository/files" 23 24 "code.gitea.io/gitea/tests" ··· 251 252 owner.Name, repo.Name, forker.Name, repo.Name+"-copy") 252 253 resp := session.MakeRequest(t, req, http.StatusOK) 253 254 htmlDoc := NewHTMLParser(t, resp.Body) 254 - htmlDoc.AssertElement(t, fmt.Sprintf("button.code-expander-button[hx-get^='/%s/%s/blob_excerpt/'] svg.octicon-fold-up", forker.Name, repo.Name+"-copy"), true) 255 - htmlDoc.AssertElement(t, fmt.Sprintf("button.code-expander-button[hx-get^='/%s/%s/blob_excerpt/'] svg.octicon-fold-down", forker.Name, repo.Name+"-copy"), true) 255 + 256 + els := htmlDoc.Find(`button.code-expander-button[hx-get]`) 257 + 258 + // all the links in the comparison should be to the forked repo&branch 259 + assert.NotZero(t, els.Length()) 260 + expectedPrefix := fmt.Sprintf("/%s/%s/blob_excerpt/", forker.Name, repo.Name+"-copy") 261 + for i := 0; i < els.Length(); i++ { 262 + link := els.Eq(i).AttrOr("hx-get", "") 263 + assert.True(t, strings.HasPrefix(link, expectedPrefix)) 264 + } 265 + }) 266 + 267 + t.Run("code expander targets the repo in a PR", func(t *testing.T) { 268 + defer tests.PrintCurrentTest(t)() 269 + 270 + // Create a pullrequest 271 + resp := testPullCreate(t, session, forker.Name, repo.Name+"-copy", false, "main", "code-expand", "This is a pull title") 272 + 273 + // Grab the URL for the PR 274 + url := test.RedirectURL(resp) + "/files" 275 + 276 + // Visit the PR's diff 277 + req := NewRequest(t, "GET", url) 278 + resp = session.MakeRequest(t, req, http.StatusOK) 279 + htmlDoc := NewHTMLParser(t, resp.Body) 280 + 281 + els := htmlDoc.Find(`button.code-expander-button[hx-get]`) 282 + 283 + // all the links in the comparison should be to the original repo&branch 284 + assert.NotZero(t, els.Length()) 285 + expectedPrefix := fmt.Sprintf("/%s/%s/blob_excerpt/", owner.Name, repo.Name) 286 + for i := 0; i < els.Length(); i++ { 287 + link := els.Eq(i).AttrOr("hx-get", "") 288 + assert.True(t, strings.HasPrefix(link, expectedPrefix)) 289 + } 256 290 }) 257 291 }) 258 292 }