Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show in Web UI if file is vendored and generated #28620

Merged
merged 12 commits into from
Jan 24, 2024
Next Next commit
Show in Web UI if file is vendored and generated
  • Loading branch information
JakobDev committed Dec 27, 2023
commit c13a40a1062a135d496c63dab77d6e07c5688dbe
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,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
19 changes: 19 additions & 0 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,25 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
}

if ctx.Repo.GitRepo != nil {
checker, deferable := ctx.Repo.GitRepo.CheckAttributeReader(ctx.Repo.CommitID)
JakobDev marked this conversation as resolved.
Show resolved Hide resolved
defer deferable()
attrs, err := checker.CheckPath(ctx.Repo.TreePath)
if err == nil {
if vendored, has := attrs["linguist-vendored"]; has {
if vendored == "set" || vendored == "true" {
ctx.Data["IsVendored"] = true
}
}

if generated, has := attrs["linguist-generated"]; has {
if generated == "set" || generated == "true" {
ctx.Data["IsGenerated"] = 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"}}
lunny marked this conversation as resolved.
Show resolved Hide resolved
</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