diff options
Diffstat (limited to 'pkg/service')
-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 } |