diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-01 19:59:43 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-01 19:59:43 +0200 |
commit | e3705f35c642e578625ce4574d189fa0b0869403 (patch) | |
tree | f63d779d4eb817ad6b5abed30f50ad3b85ffcab1 /pkg/handler | |
parent | f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd (diff) | |
download | cerrado-e3705f35c642e578625ce4574d189fa0b0869403.tar.gz cerrado-e3705f35c642e578625ce4574d189fa0b0869403.tar.bz2 cerrado-e3705f35c642e578625ce4574d189fa0b0869403.zip |
feat: Add ref support
Now log and tree can be loaded using a given reference.
Diffstat (limited to 'pkg/handler')
-rw-r--r-- | pkg/handler/git/handler.go | 33 | ||||
-rw-r--r-- | pkg/handler/router.go | 6 |
2 files changed, 32 insertions, 7 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index d090f22..b77bcfc 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -18,9 +18,10 @@ type ( gitService interface { ListRepositories() ([]*service.Repository, error) - ListCommits(string) ([]*object.Commit, error) - ListTags(string) ([]*object.Tag, error) - ListBranches(string) ([]*plumbing.Reference, error) + ListCommits(name string, ref string) ([]*object.Commit, error) + GetHead(name string) (*plumbing.Reference, error) + ListTags(name string) ([]*object.Tag, error) + ListBranches(name string) ([]*plumbing.Reference, error) } ) @@ -43,8 +44,15 @@ func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) { func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] + ref, err := g.gitService.GetHead(name) + if err != nil { + slog.Error("Error loading head", "error", err) + return + } + gitList := &templates.GitItemPage{ Name: name, + Ref: ref.Name().Short(), GitItemBase: &templates.GitItemSummaryPage{}, } templates.WritePageTemplate(w, gitList) @@ -52,8 +60,14 @@ func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) { func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] + ref, err := g.gitService.GetHead(name) + if err != nil { + slog.Error("Error loading head", "error", err) + return + } gitList := &templates.GitItemPage{ Name: name, + Ref: ref.Name().Short(), GitItemBase: &templates.GitItemAboutPage{}, } templates.WritePageTemplate(w, gitList) @@ -74,8 +88,15 @@ func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) { return } + ref, err := g.gitService.GetHead(name) + if err != nil { + slog.Error("Error loading head", "error", err) + return + } + gitList := &templates.GitItemPage{ Name: name, + Ref: ref.Name().Short(), GitItemBase: &templates.GitItemRefsPage{ Tags: tags, Branches: branches, @@ -86,8 +107,10 @@ func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) { func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] + ref := mux.Vars(r)["ref"] gitList := &templates.GitItemPage{ Name: name, + Ref: ref, GitItemBase: &templates.GitItemTreePage{}, } templates.WritePageTemplate(w, gitList) @@ -95,8 +118,9 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) { func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] + ref := mux.Vars(r)["ref"] - commits, err := g.gitService.ListCommits(name) + commits, err := g.gitService.ListCommits(name, ref) if err != nil { slog.Error("Error loading commits", "error", err) return @@ -104,6 +128,7 @@ func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) { gitList := &templates.GitItemPage{ Name: name, + Ref: ref, GitItemBase: &templates.GitItemLogPage{ Commits: commits, }, diff --git a/pkg/handler/router.go b/pkg/handler/router.go index f73e9fb..79f70f1 100644 --- a/pkg/handler/router.go +++ b/pkg/handler/router.go @@ -34,10 +34,10 @@ func MountHandler( mux.PathPrefix("/static").Handler(staticHandler) mux.HandleFunc("/{name}/about", gitHandler.About) - mux.HandleFunc("/{name}/summary", gitHandler.Summary) + mux.HandleFunc("/{name}", gitHandler.Summary) mux.HandleFunc("/{name}/refs", gitHandler.Refs) - mux.HandleFunc("/{name}/tree", gitHandler.Tree) - mux.HandleFunc("/{name}/log", gitHandler.Log) + mux.HandleFunc("/{name}/tree/{ref}", gitHandler.Tree) + mux.HandleFunc("/{name}/log/{ref}", gitHandler.Log) mux.HandleFunc("/config", configHander) mux.HandleFunc("/about", aboutHandler.About) mux.HandleFunc("/", gitHandler.List) |