package service import ( "path" "git.gabrielgio.me/cerrado/pkg/git" ) type ( GitService struct { server *git.GitServerRepository } Repository struct { Name string Title string LastCommitMessage string LastCommitDate string } ) // 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, 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 } baseName := path.Base(r.Path()) repos[i] = &Repository{ Name: baseName, Title: baseName, LastCommitMessage: obj.Message, LastCommitDate: obj.Author.When.Format(timeFormat), } } return repos, nil }