Skip to content

Commit

Permalink
Show in Web UI if file is vendored and generated (#28620)
Browse files Browse the repository at this point in the history
This simple shows in the Web UI is a file is vendored and/or generated.


![grafik](https://github.com/go-gitea/gitea/assets/15185051/bfe45fcc-cfec-4ba1-8d93-c0a262c3ae1c)

![grafik](https://github.com/go-gitea/gitea/assets/15185051/9f222a49-e7bf-4540-ba64-43dcc5767b76)

---------

Co-authored-by: delvh <[email protected]>
Co-authored-by: Lunny Xiao <[email protected]>
  • Loading branch information
3 people committed Jan 24, 2024
1 parent ee3e83e commit 7ed1856
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,8 @@ audio_not_supported_in_browser = Your browser does not support the HTML5 'audio'
stored_lfs = Stored with Git LFS
symbolic_link = Symbolic link
executable_file = Executable File
vendored = Vendored
generated = Generated
commit_graph = Commit Graph
commit_graph.select = Select branches
commit_graph.hide_pr_refs = Hide Pull Requests
Expand Down
15 changes: 15 additions & 0 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
}
}

if ctx.Repo.GitRepo != nil {
checker, deferable := ctx.Repo.GitRepo.CheckAttributeReader(ctx.Repo.CommitID)
if checker != nil {
defer deferable()
attrs, err := checker.CheckPath(ctx.Repo.TreePath)
if err == nil {
vendored, has := attrs["linguist-vendored"]
ctx.Data["IsVendored"] = has && (vendored == "set" || vendored == "true")

generated, has := attrs["linguist-generated"]
ctx.Data["IsGenerated"] = has && (generated == "set" || generated == "true")
}
}
}

if fInfo.st.IsImage() && !fInfo.st.IsSvgImage() {
img, _, err := image.DecodeConfig(bytes.NewReader(buf))
if err == nil {
Expand Down
10 changes: 10 additions & 0 deletions templates/repo/file_info.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
{{ctx.Locale.Tr "repo.executable_file"}}
</div>
{{end}}
{{if .IsVendored}}
<div class="file-info-entry">
{{ctx.Locale.Tr "repo.vendored"}}
</div>
{{end}}
{{if .IsGenerated}}
<div class="file-info-entry">
{{ctx.Locale.Tr "repo.generated"}}
</div>
{{end}}
{{if .ImageSize}}
<div class="file-info-entry">
{{.ImageSize}}
Expand Down

0 comments on commit 7ed1856

Please sign in to comment.