summaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-12 21:58:47 +0530
committerLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-12 21:58:47 +0530
commit7a6ff3565e8e5f55d50c509c9ee12438b61c850e (patch)
tree58d609ef2fba68fb82bd0e8a47d6c98692361f6e /routes
parent01f27147baf80e2222927ddca9369c7d99b4ff3c (diff)
downloadlegit-7a6ff3565e8e5f55d50c509c9ee12438b61c850e.tar.gz
legit-7a6ff3565e8e5f55d50c509c9ee12438b61c850e.tar.bz2
legit-7a6ff3565e8e5f55d50c509c9ee12438b61c850e.zip
routes: refs view
Diffstat (limited to 'routes')
-rw-r--r--routes/handler.go1
-rw-r--r--routes/routes.go39
2 files changed, 40 insertions, 0 deletions
diff --git a/routes/handler.go b/routes/handler.go
index 0c4f7b8..3abc4fd 100644
--- a/routes/handler.go
+++ b/routes/handler.go
@@ -21,5 +21,6 @@ func Handlers(c *config.Config) *flow.Mux {
mux.HandleFunc("/:name/blob/:ref/...", d.FileContent, "GET")
mux.HandleFunc("/:name/log/:ref", d.Log, "GET")
mux.HandleFunc("/:name/commit/:ref", d.Diff, "GET")
+ mux.HandleFunc("/:name/refs", d.Refs, "GET")
return mux
}
diff --git a/routes/routes.go b/routes/routes.go
index ebb1622..1683404 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -216,3 +216,42 @@ func (d *deps) Diff(w http.ResponseWriter, r *http.Request) {
return
}
}
+
+func (d *deps) Refs(w http.ResponseWriter, r *http.Request) {
+ name := flow.Param(r.Context(), "name")
+
+ path := filepath.Join(d.c.Git.ScanPath, name)
+ gr, err := git.Open(path, "")
+ if err != nil {
+ d.Write404(w)
+ return
+ }
+
+ tags, err := gr.Tags()
+ if err != nil {
+ // Non-fatal, we *should* have at least one branch to show.
+ log.Println(err)
+ }
+
+ branches, err := gr.Branches()
+ if err != nil {
+ log.Println(err)
+ d.Write500(w)
+ return
+ }
+
+ tpath := filepath.Join(d.c.Template.Dir, "*")
+ t := template.Must(template.ParseGlob(tpath))
+
+ data := make(map[string]interface{})
+
+ data["meta"] = d.c.Meta
+ data["name"] = name
+ data["branches"] = branches
+ data["tags"] = tags
+
+ if err := t.ExecuteTemplate(w, "refs", data); err != nil {
+ log.Println(err)
+ return
+ }
+}