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 +- scss/main.scss | 29 ----- templates/gititemlog.qtpl | 4 +- templates/gititemlog.qtpl.go | 4 +- templates/gititemsummary.qtpl | 64 ++++++++++- templates/gititemsummary.qtpl.go | 223 +++++++++++++++++++++++++++++++++------ 8 files changed, 285 insertions(+), 76 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) { diff --git a/scss/main.scss b/scss/main.scss index af8a002..107a4c8 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -114,35 +114,6 @@ body { overflow-x: auto; } -.logs { - >div { - background: #f8f9fa; - } - - >div { - padding: 5px; - margin: $spacer; - } - - @include media-breakpoint-down(md) { - >div { - margin: $spacer 0 $spacer 0; - } - } - - pre { - font-size: $base-font-size; - margin: 0; - } -} - -.logs>div>div:first-child { - margin-bottom: 15px; -} -.logs>div>div:last-child { - margin-top: 15px; -} - #about { padding: 0 $spacer $spacer $spacer; > p:first-child { diff --git a/templates/gititemlog.qtpl b/templates/gititemlog.qtpl index 1af05ca..a28e7ad 100644 --- a/templates/gititemlog.qtpl +++ b/templates/gititemlog.qtpl @@ -9,9 +9,9 @@ type GitItemLogPage struct { {% func (g *GitItemLogPage) Nav(name, ref string) %}{%= GitItemNav(name, ref, Log) %}{% endfunc %} {% func (g *GitItemLogPage) GitContent(name, ref string) %} -
+
{% for _, c := range g.Commits %} -
+
{%s TimeFormat(c.Committer.When) %}
diff --git a/templates/gititemlog.qtpl.go b/templates/gititemlog.qtpl.go index 185b153..76c2432 100644 --- a/templates/gititemlog.qtpl.go +++ b/templates/gititemlog.qtpl.go @@ -62,13 +62,13 @@ func (g *GitItemLogPage) Nav(name, ref string) string { func (g *GitItemLogPage) StreamGitContent(qw422016 *qt422016.Writer, name, ref string) { //line gititemlog.qtpl:11 qw422016.N().S(` -
+
`) //line gititemlog.qtpl:13 for _, c := range g.Commits { //line gititemlog.qtpl:13 qw422016.N().S(` -
+
`) //line gititemlog.qtpl:16 diff --git a/templates/gititemsummary.qtpl b/templates/gititemsummary.qtpl index 4cbf324..9a3e2ee 100644 --- a/templates/gititemsummary.qtpl +++ b/templates/gititemsummary.qtpl @@ -1,10 +1,72 @@ +{% import "github.com/go-git/go-git/v5/plumbing" %} +{% import "github.com/go-git/go-git/v5/plumbing/object" %} + {% code type GitItemSummaryPage struct { + Tags []*plumbing.Reference + Branches []*plumbing.Reference + Commits []*object.Commit } %} {% func (g *GitItemSummaryPage) Nav(name, ref string) %}{%= GitItemNav(name, ref, Summary) %}{% endfunc %} {% func (g *GitItemSummaryPage) GitContent(name, ref string) %} -

Summary

+
+
+ {% if len(g.Tags) > 0 %} +
+ {% for _, t := range g.Tags %} +
+
+ {%s t.Name().Short() %} +
+
+
+ tree + log +
+
+
+ {% endfor %} +
+ {% else %} +

No tags

+ {% endif %} +
+
+
+ {% for _, b := range g.Branches %} +
+
+ {%s b.Name().Short() %} +
+
+
+ tree + log +
+
+
+ {% endfor %} +
+
+
+
+
+ {% for _, c := range g.Commits %} +
+
+ {%s TimeFormat(c.Committer.When) %} +
+
+
{%s c.Message %}
+
+
+ {%s c.Committer.Name %} <{%s c.Committer.Email %}> +
+
+ {% endfor %} +
+
{% endfunc %} diff --git a/templates/gititemsummary.qtpl.go b/templates/gititemsummary.qtpl.go index d8606a5..cf1c07c 100644 --- a/templates/gititemsummary.qtpl.go +++ b/templates/gititemsummary.qtpl.go @@ -5,86 +5,243 @@ package templates //line gititemsummary.qtpl:1 +import "github.com/go-git/go-git/v5/plumbing" + +//line gititemsummary.qtpl:2 +import "github.com/go-git/go-git/v5/plumbing/object" + +//line gititemsummary.qtpl:4 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line gititemsummary.qtpl:1 +//line gititemsummary.qtpl:4 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line gititemsummary.qtpl:2 +//line gititemsummary.qtpl:5 type GitItemSummaryPage struct { + Tags []*plumbing.Reference + Branches []*plumbing.Reference + Commits []*object.Commit } -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 func (g *GitItemSummaryPage) StreamNav(qw422016 *qt422016.Writer, name, ref string) { -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 StreamGitItemNav(qw422016, name, ref, Summary) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 } -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 func (g *GitItemSummaryPage) WriteNav(qq422016 qtio422016.Writer, name, ref string) { -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 qw422016 := qt422016.AcquireWriter(qq422016) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 g.StreamNav(qw422016, name, ref) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 qt422016.ReleaseWriter(qw422016) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 } -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 func (g *GitItemSummaryPage) Nav(name, ref string) string { -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 qb422016 := qt422016.AcquireByteBuffer() -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 g.WriteNav(qb422016, name, ref) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 qs422016 := string(qb422016.B) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 qt422016.ReleaseByteBuffer(qb422016) -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 return qs422016 -//line gititemsummary.qtpl:6 +//line gititemsummary.qtpl:12 } -//line gititemsummary.qtpl:8 +//line gititemsummary.qtpl:14 func (g *GitItemSummaryPage) StreamGitContent(qw422016 *qt422016.Writer, name, ref string) { -//line gititemsummary.qtpl:8 +//line gititemsummary.qtpl:14 + qw422016.N().S(` +
+
+ `) +//line gititemsummary.qtpl:17 + if len(g.Tags) > 0 { +//line gititemsummary.qtpl:17 + qw422016.N().S(` +
+ `) +//line gititemsummary.qtpl:19 + for _, t := range g.Tags { +//line gititemsummary.qtpl:19 + qw422016.N().S(` +
+
+ `) +//line gititemsummary.qtpl:22 + qw422016.E().S(t.Name().Short()) +//line gititemsummary.qtpl:22 + qw422016.N().S(` +
+
+
+ tree + log +
+
+
+ `) +//line gititemsummary.qtpl:31 + } +//line gititemsummary.qtpl:31 + qw422016.N().S(` +
+ `) +//line gititemsummary.qtpl:33 + } else { +//line gititemsummary.qtpl:33 + qw422016.N().S(` +

No tags

+ `) +//line gititemsummary.qtpl:35 + } +//line gititemsummary.qtpl:35 + qw422016.N().S(` +
+
+
+ `) +//line gititemsummary.qtpl:39 + for _, b := range g.Branches { +//line gititemsummary.qtpl:39 + qw422016.N().S(` +
+
+ `) +//line gititemsummary.qtpl:42 + qw422016.E().S(b.Name().Short()) +//line gititemsummary.qtpl:42 + qw422016.N().S(` +
+
+
+ tree + log +
+
+
+ `) +//line gititemsummary.qtpl:51 + } +//line gititemsummary.qtpl:51 + qw422016.N().S(` +
+
+
+
+
+ `) +//line gititemsummary.qtpl:57 + for _, c := range g.Commits { +//line gititemsummary.qtpl:57 + qw422016.N().S(` +
+
+ `) +//line gititemsummary.qtpl:60 + qw422016.E().S(TimeFormat(c.Committer.When)) +//line gititemsummary.qtpl:60 + qw422016.N().S(` +
+
+
`)
+//line gititemsummary.qtpl:63
+		qw422016.E().S(c.Message)
+//line gititemsummary.qtpl:63
+		qw422016.N().S(`
+
+
+ `) +//line gititemsummary.qtpl:66 + qw422016.E().S(c.Committer.Name) +//line gititemsummary.qtpl:66 + qw422016.N().S(` <`) +//line gititemsummary.qtpl:66 + qw422016.E().S(c.Committer.Email) +//line gititemsummary.qtpl:66 + qw422016.N().S(`> +
+
+ `) +//line gititemsummary.qtpl:69 + } +//line gititemsummary.qtpl:69 qw422016.N().S(` -

Summary

+
+
`) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 } -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 func (g *GitItemSummaryPage) WriteGitContent(qq422016 qtio422016.Writer, name, ref string) { -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 qw422016 := qt422016.AcquireWriter(qq422016) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 g.StreamGitContent(qw422016, name, ref) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 qt422016.ReleaseWriter(qw422016) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 } -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 func (g *GitItemSummaryPage) GitContent(name, ref string) string { -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 qb422016 := qt422016.AcquireByteBuffer() -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 g.WriteGitContent(qb422016, name, ref) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 qs422016 := string(qb422016.B) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 qt422016.ReleaseByteBuffer(qb422016) -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 return qs422016 -//line gititemsummary.qtpl:10 +//line gititemsummary.qtpl:72 } -- cgit v1.2.3