/** * AltGit - altgit * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2026 */ package handler import ( "altgit/internal/config" "altgit/internal/gitrepo" "altgit/internal/rendering" "fmt" "html/template" "net/url" "strings" "github.com/gin-gonic/gin" ) // HandleRepoList GET / — list all repos func HandleRepoList(cfg config.AltGitConfiguration) gin.HandlerFunc { return func(c *gin.Context) { repos := gitrepo.ListRepos(cfg) var body strings.Builder body.WriteString(fmt.Sprintf( `

Repositories

`+ `

%d repositories

`, len(repos), )) if len(repos) == 0 { body.WriteString(`
No git repositories found.
`) } else { body.WriteString(`
`) for _, r := range repos { meta := r.Branch if r.LastCommit != "" { meta += "  ·  " + template.HTMLEscapeString(r.LastCommit) } body.WriteString(fmt.Sprintf( ``+ `
💽 %s
`+ `
%s
`+ `
%s
`+ `
`, url.PathEscape(r.Name), template.HTMLEscapeString(r.Name), template.HTMLEscapeString(r.Description), meta, )) } body.WriteString("
") } rendering.RenderPage(cfg, c, rendering.PageData{ Title: "altgit", Breadcrumb: template.HTML(`repositories`), //GitCmd: fmt.Sprintf("ls %s", cfg.Root), GitCmd: fmt.Sprintf("ls "), // Do not show the root filepath for security reasons Body: template.HTML(body.String()), }) } } func resolveCloneUrl(cfg config.AltGitConfiguration, c *gin.Context, repoName string) string { if "" == cfg.Domain { return fmt.Sprintf("http://%s/git/%s", c.Request.Host, repoName) } return fmt.Sprintf("https://%s/git/%s", cfg.Domain, repoName) }