aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-06-15 18:42:48 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-06-15 18:42:48 +0200
commitb71c6c0e5b8dd00d44e40ac0551902a23cbe19d5 (patch)
tree55dc40918dc3adb2171dd9f9bc4cfe92f9f5e769 /pkg
parentd2c4023832e26d3fe3f77c9fa8581588ea812cc2 (diff)
downloadcerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.tar.gz
cerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.tar.bz2
cerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.zip
feat: Add summary page
Diffstat (limited to 'pkg')
-rw-r--r--pkg/git/git.go4
-rw-r--r--pkg/handler/git/handler.go29
-rw-r--r--pkg/service/git.go4
3 files changed, 28 insertions, 9 deletions
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) {