Skip to content

Commit c35531d

Browse files
authored
Fix #21406: Hide repo information from file view/blame mode (#21420)
# Summary The repo information such as description, stats and topics are getting displayed in the top-bar when viewing a file. This has been fixed to display the repo information only while navigating the repo and not while viewing or blaming a file from the repo ## Before fix Screenshot from the issue ![image](https://user-images.githubusercontent.com/47709856/195278543-9afbb735-7bd3-4f42-b3ba-da514c6989d2.png) ## After the fix - **Repo homepage** The repo description, topics and summary will be displayed ![image](https://user-images.githubusercontent.com/47709856/195443913-2ca967cd-6694-4a97-98d0-4d0750692b5d.png) - **When opening a file** The repo description, topic and summary has been conditionally hidden from the view <img width="1311" alt="image" src="https://user-images.githubusercontent.com/47709856/195278964-9479231c-62ad-4c0e-b438-2018f22289db.png"> - **When running blame on a file** > This was originally not part of the issue #21406. However the fix seems relevant for the blame view as well. <img width="1312" alt="image" src="https://user-images.githubusercontent.com/47709856/195279619-02010775-aec3-4c8d-a184-d2d838c797e8.png"> - **From within a directory** The repo description, topics and summary will not be displayed ![image](https://user-images.githubusercontent.com/47709856/195444080-ff5b2def-7e0f-47d7-b54a-7e9df5f9edd8.png) Supporting integration tests have also been added.
1 parent cda2c38 commit c35531d

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

routers/web/repo/view.go

+2
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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{{template "repo/header" .}}
44
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
55
{{template "base/alert" .}}
6+
{{if and (not .HideRepoInfo) (not .IsBlame)}}
67
<div class="ui repo-description">
78
<div id="repo-desc">
89
{{$description := .Repository.DescriptionHTML $.Context}}
@@ -31,6 +32,7 @@
3132
{{range .Topics}}<a class="ui repo-topic large label topic" href="{{AppSubUrl}}/explore/repos?q={{.Name}}&topic=1">{{.Name}}</a>{{end}}
3233
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}<a id="manage_topic" class="muted">{{.locale.Tr "repo.topic.manage_topics"}}</a>{{end}}
3334
</div>
35+
{{end}}
3436
{{if and .Permission.IsAdmin (not .Repository.IsArchived)}}
3537
<div class="ui repo-topic-edit grid form" id="topic_edit" style="display:none">
3638
<div class="fourteen wide column">

templates/repo/sub_menu.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{if and (not .HideRepoInfo) (not .IsBlame)}}
12
<div class="ui segments repository-summary{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo) .LanguageStats}} repository-summary-language-stats{{end}} mt-2 mb-0">
23
<div class="ui segment sub-menu repository-menu">
34
<div class="ui two horizontal center link list">
@@ -44,3 +45,4 @@
4445
</a>
4546
{{end}}
4647
</div>
48+
{{end}}

tests/integration/repo_test.go

+77-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@ import (
2222
func TestViewRepo(t *testing.T) {
2323
defer tests.PrepareTestEnv(t)()
2424

25+
session := loginUser(t, "user2")
26+
2527
req := NewRequest(t, "GET", "/user2/repo1")
26-
MakeRequest(t, req, http.StatusOK)
28+
resp := session.MakeRequest(t, req, http.StatusOK)
29+
30+
htmlDoc := NewHTMLParser(t, resp.Body)
31+
noDescription := htmlDoc.doc.Find("#repo-desc").Children()
32+
repoTopics := htmlDoc.doc.Find("#repo-topics").Children()
33+
repoSummary := htmlDoc.doc.Find(".repository-summary").Children()
34+
35+
assert.True(t, noDescription.HasClass("no-description"))
36+
assert.True(t, repoTopics.HasClass("repo-topic"))
37+
assert.True(t, repoSummary.HasClass("repository-menu"))
2738

2839
req = NewRequest(t, "GET", "/user3/repo3")
2940
MakeRequest(t, req, http.StatusNotFound)
3041

31-
session := loginUser(t, "user1")
42+
session = loginUser(t, "user1")
3243
session.MakeRequest(t, req, http.StatusNotFound)
3344
}
3445

@@ -178,7 +189,71 @@ func TestViewAsRepoAdmin(t *testing.T) {
178189

179190
htmlDoc := NewHTMLParser(t, resp.Body)
180191
noDescription := htmlDoc.doc.Find("#repo-desc").Children()
192+
repoTopics := htmlDoc.doc.Find("#repo-topics").Children()
193+
repoSummary := htmlDoc.doc.Find(".repository-summary").Children()
181194

182195
assert.Equal(t, expectedNoDescription, noDescription.HasClass("no-description"))
196+
assert.True(t, repoTopics.HasClass("repo-topic"))
197+
assert.True(t, repoSummary.HasClass("repository-menu"))
183198
}
184199
}
200+
201+
// TestViewFileInRepo repo description, topics and summary should not be displayed when viewing a file
202+
func TestViewFileInRepo(t *testing.T) {
203+
defer tests.PrepareTestEnv(t)()
204+
205+
session := loginUser(t, "user2")
206+
207+
req := NewRequest(t, "GET", "/user2/repo1/src/branch/master/README.md")
208+
resp := session.MakeRequest(t, req, http.StatusOK)
209+
210+
htmlDoc := NewHTMLParser(t, resp.Body)
211+
description := htmlDoc.doc.Find("#repo-desc")
212+
repoTopics := htmlDoc.doc.Find("#repo-topics")
213+
repoSummary := htmlDoc.doc.Find(".repository-summary")
214+
215+
assert.EqualValues(t, 0, description.Length())
216+
assert.EqualValues(t, 0, repoTopics.Length())
217+
assert.EqualValues(t, 0, repoSummary.Length())
218+
}
219+
220+
// TestBlameFileInRepo repo description, topics and summary should not be displayed when running blame on a file
221+
func TestBlameFileInRepo(t *testing.T) {
222+
defer tests.PrepareTestEnv(t)()
223+
224+
session := loginUser(t, "user2")
225+
226+
req := NewRequest(t, "GET", "/user2/repo1/blame/branch/master/README.md")
227+
resp := session.MakeRequest(t, req, http.StatusOK)
228+
229+
htmlDoc := NewHTMLParser(t, resp.Body)
230+
description := htmlDoc.doc.Find("#repo-desc")
231+
repoTopics := htmlDoc.doc.Find("#repo-topics")
232+
repoSummary := htmlDoc.doc.Find(".repository-summary")
233+
234+
assert.EqualValues(t, 0, description.Length())
235+
assert.EqualValues(t, 0, repoTopics.Length())
236+
assert.EqualValues(t, 0, repoSummary.Length())
237+
}
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+
repoFilesTable := htmlDoc.doc.Find("#repo-files-table")
254+
assert.NotZero(t, len(repoFilesTable.Nodes))
255+
256+
assert.Zero(t, description.Length())
257+
assert.Zero(t, repoTopics.Length())
258+
assert.Zero(t, repoSummary.Length())
259+
}

0 commit comments

Comments
 (0)