diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 57c11f1de0..7908db8552 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -935,6 +935,8 @@ visibility.private = Private visibility.private_tooltip = Visible only to members of organizations you have joined [repo] +rss.must_be_on_branch = You must be on a branch to have an RSS feed. + new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? Migrate repository. owner = Owner owner_helper = Some organizations may not show up in the dropdown due to a maximum repository count limit. diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index e7d1c04c12..bdee35a233 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -43,9 +43,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 a8064912bc..ce0f21cb9c 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -406,6 +406,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)()