From b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 15 Jun 2024 18:42:48 +0200 Subject: feat: Add summary page --- pkg/git/git.go | 4 ++-- pkg/handler/git/handler.go | 29 ++++++++++++++++++++++++----- pkg/service/git.go | 4 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) (limited to 'pkg') diff --git a/pkg/git/git.go b/pkg/git/git.go index 428bfb1..b725cd8 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -77,7 +77,7 @@ func (g *GitRepository) LastCommit() (*object.Commit, error) { return c, nil } -func (g *GitRepository) Commits() ([]*object.Commit, error) { +func (g *GitRepository) Commits(count int) ([]*object.Commit, error) { err := g.validateRef() if err != nil { return nil, err @@ -90,7 +90,7 @@ func (g *GitRepository) Commits() ([]*object.Commit, error) { commits := []*object.Commit{} // TODO: for now only load first 1000 - for x := 0; x < 1000; x++ { + for x := 0; x < count; x++ { c, err := ci.Next() if err != nil && errors.Is(err, io.EOF) { break diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index 4809362..899f61e 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -29,7 +29,7 @@ type ( gitService interface { ListRepositories() ([]*service.Repository, error) - ListCommits(name string, ref string) ([]*object.Commit, error) + ListCommits(name string, ref string, count int) ([]*object.Commit, error) GetHead(name string) (*plumbing.Reference, error) GetTree(name, ref, path string) (*object.Tree, error) GetFileContent(name, ref, path string) (string, error) @@ -91,10 +91,29 @@ func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) error { return err } + tags, err := g.gitService.ListTags(name) + if err != nil { + return err + } + + branches, err := g.gitService.ListBranches(name) + if err != nil { + return err + } + + commits, err := g.gitService.ListCommits(name, "", 10) + if err != nil { + return err + } + gitList := &templates.GitItemPage{ - Name: name, - Ref: ref.Name().Short(), - GitItemBase: &templates.GitItemSummaryPage{}, + Name: name, + Ref: ref.Name().Short(), + GitItemBase: &templates.GitItemSummaryPage{ + Tags: tags, + Branches: branches, + Commits: commits, + }, } templates.WritePageTemplate(w, gitList) return nil @@ -215,7 +234,7 @@ func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) error { name := r.PathValue("name") ref := r.PathValue("ref") - commits, err := g.gitService.ListCommits(name, ref) + commits, err := g.gitService.ListCommits(name, ref, 1000) if err != nil { return err } diff --git a/pkg/service/git.go b/pkg/service/git.go index 071e10d..2165abe 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -74,7 +74,7 @@ func (g *GitService) ListRepositories() ([]*Repository, error) { return repos, nil } -func (g *GitService) ListCommits(name, ref string) ([]*object.Commit, error) { +func (g *GitService) ListCommits(name, ref string, count int) ([]*object.Commit, error) { r := g.configRepo.GetByName(name) if r == nil { return nil, RepositoryNotFoundErr @@ -89,7 +89,7 @@ func (g *GitService) ListCommits(name, ref string) ([]*object.Commit, error) { if err != nil { return nil, err } - return repo.Commits() + return repo.Commits(count) } func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) { -- cgit v1.2.3