Skip to content

Commit 9735a7d

Browse files
committed
fix: hide repo info within a directory
- The repo description, topics and summary will not be displayed within a directory - The repo home page will still display the repo info - Resolves go-gitea#21406
1 parent bfa09c4 commit 9735a7d

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

routers/web/repo/view.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
119119
}
120120

121121
if ctx.Repo.TreePath != "" {
122+
ctx.Data["HideRepoInfo"] = true
122123
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefName)
123124
}
124125

@@ -360,6 +361,7 @@ func renderReadmeFile(ctx *context.Context, readmeFile *namedBlob, readmeTreelin
360361

361362
func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
362363
ctx.Data["IsViewFile"] = true
364+
ctx.Data["HideRepoInfo"] = true
363365
blob := entry.Blob()
364366
dataRc, err := blob.DataAsync()
365367
if err != nil {

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{{template "repo/header" .}}
44
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
55
{{template "base/alert" .}}
6-
{{if and (not .IsViewFile) (not .IsBlame)}}
6+
{{if and (not .HideRepoInfo) (not .IsBlame)}}
77
<div class="ui repo-description">
88
<div id="repo-desc">
99
{{$description := .Repository.DescriptionHTML $.Context}}

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{if and (not .IsViewFile) (not .IsBlame)}}
1+
{{if and (not .HideRepoInfo) (not .IsBlame)}}
22
<div class="ui segments repository-summary{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo) .LanguageStats}} repository-summary-language-stats{{end}} mt-2 mb-0">
33
<div class="ui segment sub-menu repository-menu">
44
<div class="ui two horizontal center link list">

tests/integration/repo_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
func TestViewRepo(t *testing.T) {
2323
defer tests.PrepareTestEnv(t)()
2424

25-
req := NewRequest(t, "GET", "/user2/repo1")
26-
2725
session := loginUser(t, "user2")
26+
27+
req := NewRequest(t, "GET", "/user2/repo1")
2828
resp := session.MakeRequest(t, req, http.StatusOK)
2929

3030
htmlDoc := NewHTMLParser(t, resp.Body)
@@ -235,3 +235,29 @@ func TestBlameFileInRepo(t *testing.T) {
235235
assert.EqualValues(t, 0, repoTopics.Length())
236236
assert.EqualValues(t, 0, repoSummary.Length())
237237
}
238+
239+
// TestViewRepoDirectory repo description, topics and summary should not be displayed when within a directory
240+
func TestViewRepoDirectory(t *testing.T) {
241+
defer tests.PrepareTestEnv(t)()
242+
243+
session := loginUser(t, "user2")
244+
245+
req := NewRequest(t, "GET", "/user2/repo20/src/branch/master/a")
246+
resp := session.MakeRequest(t, req, http.StatusOK)
247+
248+
htmlDoc := NewHTMLParser(t, resp.Body)
249+
description := htmlDoc.doc.Find("#repo-desc")
250+
repoTopics := htmlDoc.doc.Find("#repo-topics")
251+
repoSummary := htmlDoc.doc.Find(".repository-summary")
252+
253+
directoryBody := htmlDoc.doc.Find("tbody").Children()
254+
assert.True(t, directoryBody.HasClass("has-parent"))
255+
assert.Len(t, directoryBody.Nodes, 4)
256+
assert.Equal(t, "b", directoryBody.Nodes[1].Attr[0].Val)
257+
assert.Equal(t, "c", directoryBody.Nodes[2].Attr[0].Val)
258+
assert.Equal(t, "link_annex", directoryBody.Nodes[3].Attr[0].Val)
259+
260+
assert.EqualValues(t, 0, description.Length())
261+
assert.EqualValues(t, 0, repoTopics.Length())
262+
assert.EqualValues(t, 0, repoSummary.Length())
263+
}

0 commit comments

Comments
 (0)