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.

[GITEA] Disable the RSS feed in file view for non-branches

Files can have an RSS feed, but those only make sense when taken in the
context of a branch. There is no history to make a feed of on a tag or a
commit: they're static. Forgejo does not provide a feed for them for
this reason.

However, the file view on the web UI was offering a link to these
non-existent feeds. With this patch, it does that no longer, and only
provides a link when viewing the file in the context of a branch.

Fixes #2102.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit 4b48d21ea7459539dfb1ca5cadd6f9cb99e65fc7)
(cherry picked from commit 70cb2667603bcdb9a8c9bb20c482877ab3f6de39)
(cherry picked from commit 69b45c3feaf92454853ef9b02c9d75092780dabf)

Conflicts:
options/locale/locale_en-US.ini
https://codeberg.org/forgejo/forgejo/pulls/2249
(cherry picked from commit 639a2c07411e6c606dfb81f695fddbad73dca3da)

authored by

Gergely Nagy and committed by
Earl Warren
9809f96a 2e172b3c

+43 -3
+9 -3
templates/repo/view_file.tmpl
··· 59 59 <a download href="{{$.RawFileLink}}"><span class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.download_file"}}">{{svg "octicon-download"}}</span></a> 60 60 <a id="copy-content" class="btn-octicon {{if not .CanCopyContent}} disabled{{end}}"{{if or .IsImageFile (and .HasSourceRenderedToggle (not .IsDisplayingSource))}} data-link="{{$.RawFileLink}}"{{end}} data-tooltip-content="{{if .CanCopyContent}}{{ctx.Locale.Tr "copy_content"}}{{else}}{{ctx.Locale.Tr "copy_type_unsupported"}}{{end}}">{{svg "octicon-copy" 14}}</a> 61 61 {{if .EnableFeed}} 62 - <a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}"> 63 - {{svg "octicon-rss" 14}} 64 - </a> 62 + {{if .IsViewBranch}} 63 + <a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}" data-tooltip-content="{{ctx.Locale.Tr "rss_feed"}}"> 64 + {{svg "octicon-rss" 14}} 65 + </a> 66 + {{else}} 67 + <span class="btn-octicon disabled" data-tooltip-content="{{ctx.Locale.Tr "repo.rss.must_be_on_branch"}}"> 68 + {{svg "octicon-rss" 14}} 69 + </span> 70 + {{end}} 65 71 {{end}} 66 72 {{if .Repository.CanEnableEditor}} 67 73 {{if .CanEditFile}}
+34
tests/integration/repo_test.go
··· 407 407 assert.EqualValues(t, 0, repoSummary.Length()) 408 408 } 409 409 410 + func TestViewFileInRepoRSSFeed(t *testing.T) { 411 + defer tests.PrepareTestEnv(t)() 412 + 413 + hasFileRSSFeed := func(t *testing.T, ref string) bool { 414 + t.Helper() 415 + 416 + req := NewRequestf(t, "GET", "/user2/repo1/src/%s/README.md", ref) 417 + resp := MakeRequest(t, req, http.StatusOK) 418 + 419 + htmlDoc := NewHTMLParser(t, resp.Body) 420 + fileFeed := htmlDoc.doc.Find(`a[href*="/user2/repo1/rss/"]`) 421 + 422 + return fileFeed.Length() != 0 423 + } 424 + 425 + t.Run("branch", func(t *testing.T) { 426 + defer tests.PrintCurrentTest(t)() 427 + 428 + assert.True(t, hasFileRSSFeed(t, "branch/master")) 429 + }) 430 + 431 + t.Run("tag", func(t *testing.T) { 432 + defer tests.PrintCurrentTest(t)() 433 + 434 + assert.False(t, hasFileRSSFeed(t, "tag/v1.1")) 435 + }) 436 + 437 + t.Run("commit", func(t *testing.T) { 438 + defer tests.PrintCurrentTest(t)() 439 + 440 + assert.False(t, hasFileRSSFeed(t, "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d")) 441 + }) 442 + } 443 + 410 444 // TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file 411 445 func TestBlameFileInRepo(t *testing.T) { 412 446 defer tests.PrepareTestEnv(t)()