From 9809f96a4a3c40163a4da7f2cbea44dac6407d9b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 6 Jan 2024 10:06:17 +0100 Subject: [PATCH] [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 (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) --- templates/repo/view_file.tmpl | 12 +++++++++--- tests/integration/repo_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 1f9e0b5028..b8eb2393fe 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -59,9 +59,15 @@ {{svg "octicon-download"}} {{svg "octicon-copy" 14}} {{if .EnableFeed}} - - {{svg "octicon-rss" 14}} - + {{if .IsViewBranch}} + + {{svg "octicon-rss" 14}} + + {{else}} + + {{svg "octicon-rss" 14}} + + {{end}} {{end}} {{if .Repository.CanEnableEditor}} {{if .CanEditFile}} diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 15292bbec1..3f2755870e 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -407,6 +407,40 @@ func TestViewFileInRepo(t *testing.T) { assert.EqualValues(t, 0, repoSummary.Length()) } +func TestViewFileInRepoRSSFeed(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + hasFileRSSFeed := func(t *testing.T, ref string) bool { + t.Helper() + + req := NewRequestf(t, "GET", "/user2/repo1/src/%s/README.md", ref) + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + fileFeed := htmlDoc.doc.Find(`a[href*="/user2/repo1/rss/"]`) + + return fileFeed.Length() != 0 + } + + t.Run("branch", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assert.True(t, hasFileRSSFeed(t, "branch/master")) + }) + + t.Run("tag", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assert.False(t, hasFileRSSFeed(t, "tag/v1.1")) + }) + + t.Run("commit", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + assert.False(t, hasFileRSSFeed(t, "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d")) + }) +} + // TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file func TestBlameFileInRepo(t *testing.T) { defer tests.PrepareTestEnv(t)()