diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-26 20:33:37 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-26 20:33:37 +0200 |
commit | 4534dffb865eb1a50bfbc291a5c3798183081caf (patch) | |
tree | d5bd1a2d9912a6442e3be1511ffb1d99f12287b0 /pkg/service/git.go | |
parent | 349a3d1ff36a436261b1b65b870f8f262f06584f (diff) | |
download | cerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.tar.gz cerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.tar.bz2 cerrado-4534dffb865eb1a50bfbc291a5c3798183081caf.zip |
feat: Add actual git listing implementation
Diffstat (limited to 'pkg/service/git.go')
-rw-r--r-- | pkg/service/git.go | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/pkg/service/git.go b/pkg/service/git.go index 0415cee..94ca75e 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -1,30 +1,53 @@ package service -import "fmt" +import ( + "path" + + "git.gabrielgio.me/cerrado/pkg/git" +) type ( - GitService struct{} + GitService struct { + server *git.GitServerRepository + } Repository struct { - Name string - Title string - Description string + Name string + Title string + LastCommitMessage string + LastCommitDate string } ) -func NewGitService() *GitService { - return &GitService{} +// TODO: make it configurable +const timeFormat = "2006.01.02 15:04:05" + +func NewGitService(server *git.GitServerRepository) *GitService { + return &GitService{ + server: server, + } } -func (g *GitService) ListRepositories() []*Repository { - repos := make([]*Repository, 10) +func (g *GitService) ListRepositories() ([]*Repository, error) { + rs, err := g.server.List() + if err != nil { + return nil, err + } + + repos := make([]*Repository, len(rs)) + for i, r := range rs { + obj, err := r.LastCommit() + if err != nil { + return nil, err + } - for i := range 10 { + baseName := path.Base(r.Path()) repos[i] = &Repository{ - Name: fmt.Sprintf("repository-%d", i), - Title: fmt.Sprintf("Repository %d", i), - Description: fmt.Sprintf("This is a description for repository %d", i), + Name: baseName, + Title: baseName, + LastCommitMessage: obj.Message, + LastCommitDate: obj.Author.When.Format(timeFormat), } } - return repos + return repos, nil } |