diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-15 18:42:48 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-15 18:42:48 +0200 |
commit | b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5 (patch) | |
tree | 55dc40918dc3adb2171dd9f9bc4cfe92f9f5e769 | |
parent | d2c4023832e26d3fe3f77c9fa8581588ea812cc2 (diff) | |
download | cerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.tar.gz cerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.tar.bz2 cerrado-b71c6c0e5b8dd00d44e40ac0551902a23cbe19d5.zip |
feat: Add summary page
-rw-r--r-- | pkg/git/git.go | 4 | ||||
-rw-r--r-- | pkg/handler/git/handler.go | 29 | ||||
-rw-r--r-- | pkg/service/git.go | 4 | ||||
-rw-r--r-- | scss/main.scss | 29 | ||||
-rw-r--r-- | templates/gititemlog.qtpl | 4 | ||||
-rw-r--r-- | templates/gititemlog.qtpl.go | 4 | ||||
-rw-r--r-- | templates/gititemsummary.qtpl | 64 | ||||
-rw-r--r-- | 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) %} -<div class="logs"> +<div class="event-list"> {% for _, c := range g.Commits %} - <div class="row"> + <div class="row event"> <div class="col-xxl-2"> {%s TimeFormat(c.Committer.When) %} </div> 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(` -<div class="logs"> +<div class="event-list"> `) //line gititemlog.qtpl:13 for _, c := range g.Commits { //line gititemlog.qtpl:13 qw422016.N().S(` - <div class="row"> + <div class="row event"> <div class="col-xxl-2"> `) //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) %} -<h4>Summary</h4> +<div class="row"> + <div class="col-md-8"> + {% if len(g.Tags) > 0 %} + <div class="event-list"> + {% for _, t := range g.Tags %} + <div class="row event me-md-2"> + <div class="col-4"> + {%s t.Name().Short() %} + </div> + <div class="col-8"> + <div class="float-end"> + <a href="/{%s name %}/tree/{%s t.Name().Short() %}">tree</a> + <a href="/{%s name %}/log/{%s t.Name().Short() %}">log</a> + </div> + </div> + </div> + {% endfor %} + </div> + {% else %} + <p> No tags </p> + {% endif %} + </div> + <div class="col-md-4"> + <div class="event-list"> + {% for _, b := range g.Branches %} + <div class="row event"> + <div class="col-4"> + {%s b.Name().Short() %} + </div> + <div class="col-8"> + <div class="float-end"> + <a href="/{%s name %}/tree/{%s b.Name().Short() %}">tree</a> + <a href="/{%s name %}/log/{%s b.Name().Short() %}">log</a> + </div> + </div> + </div> + {% endfor %} + </div> + </div> +</div> +<div class="row"> + <div class="event-list"> + {% for _, c := range g.Commits %} + <div class="row event"> + <div class="col-xxl-2"> + {%s TimeFormat(c.Committer.When) %} + </div> + <div class="col-xxl-7 code-view"> + <pre>{%s c.Message %}</pre> + </div> + <div class="col-xxl-3"> + <small>{%s c.Committer.Name %} <{%s c.Committer.Email %}></small> + </div> + </div> + {% endfor %} + </div> +</div> {% 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(` +<div class="row"> + <div class="col-md-8"> + `) +//line gititemsummary.qtpl:17 + if len(g.Tags) > 0 { +//line gititemsummary.qtpl:17 + qw422016.N().S(` + <div class="event-list"> + `) +//line gititemsummary.qtpl:19 + for _, t := range g.Tags { +//line gititemsummary.qtpl:19 + qw422016.N().S(` + <div class="row event me-md-2"> + <div class="col-4"> + `) +//line gititemsummary.qtpl:22 + qw422016.E().S(t.Name().Short()) +//line gititemsummary.qtpl:22 + qw422016.N().S(` + </div> + <div class="col-8"> + <div class="float-end"> + <a href="/`) +//line gititemsummary.qtpl:26 + qw422016.E().S(name) +//line gititemsummary.qtpl:26 + qw422016.N().S(`/tree/`) +//line gititemsummary.qtpl:26 + qw422016.E().S(t.Name().Short()) +//line gititemsummary.qtpl:26 + qw422016.N().S(`">tree</a> + <a href="/`) +//line gititemsummary.qtpl:27 + qw422016.E().S(name) +//line gititemsummary.qtpl:27 + qw422016.N().S(`/log/`) +//line gititemsummary.qtpl:27 + qw422016.E().S(t.Name().Short()) +//line gititemsummary.qtpl:27 + qw422016.N().S(`">log</a> + </div> + </div> + </div> + `) +//line gititemsummary.qtpl:31 + } +//line gititemsummary.qtpl:31 + qw422016.N().S(` + </div> + `) +//line gititemsummary.qtpl:33 + } else { +//line gititemsummary.qtpl:33 + qw422016.N().S(` + <p> No tags </p> + `) +//line gititemsummary.qtpl:35 + } +//line gititemsummary.qtpl:35 + qw422016.N().S(` + </div> + <div class="col-md-4"> + <div class="event-list"> + `) +//line gititemsummary.qtpl:39 + for _, b := range g.Branches { +//line gititemsummary.qtpl:39 + qw422016.N().S(` + <div class="row event"> + <div class="col-4"> + `) +//line gititemsummary.qtpl:42 + qw422016.E().S(b.Name().Short()) +//line gititemsummary.qtpl:42 + qw422016.N().S(` + </div> + <div class="col-8"> + <div class="float-end"> + <a href="/`) +//line gititemsummary.qtpl:46 + qw422016.E().S(name) +//line gititemsummary.qtpl:46 + qw422016.N().S(`/tree/`) +//line gititemsummary.qtpl:46 + qw422016.E().S(b.Name().Short()) +//line gititemsummary.qtpl:46 + qw422016.N().S(`">tree</a> + <a href="/`) +//line gititemsummary.qtpl:47 + qw422016.E().S(name) +//line gititemsummary.qtpl:47 + qw422016.N().S(`/log/`) +//line gititemsummary.qtpl:47 + qw422016.E().S(b.Name().Short()) +//line gititemsummary.qtpl:47 + qw422016.N().S(`">log</a> + </div> + </div> + </div> + `) +//line gititemsummary.qtpl:51 + } +//line gititemsummary.qtpl:51 + qw422016.N().S(` + </div> + </div> +</div> +<div class="row"> + <div class="event-list"> + `) +//line gititemsummary.qtpl:57 + for _, c := range g.Commits { +//line gititemsummary.qtpl:57 + qw422016.N().S(` + <div class="row event"> + <div class="col-xxl-2"> + `) +//line gititemsummary.qtpl:60 + qw422016.E().S(TimeFormat(c.Committer.When)) +//line gititemsummary.qtpl:60 + qw422016.N().S(` + </div> + <div class="col-xxl-7 code-view"> + <pre>`) +//line gititemsummary.qtpl:63 + qw422016.E().S(c.Message) +//line gititemsummary.qtpl:63 + qw422016.N().S(`</pre> + </div> + <div class="col-xxl-3"> + <small>`) +//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(`></small> + </div> + </div> + `) +//line gititemsummary.qtpl:69 + } +//line gititemsummary.qtpl:69 qw422016.N().S(` -<h4>Summary</h4> + </div> +</div> `) -//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 } |