cerrado @ 60e8e751c76d949a28eefe0c5462e0cf17337217

 1package service
 2
 3import (
 4	"path"
 5
 6	"git.gabrielgio.me/cerrado/pkg/git"
 7)
 8
 9type (
10	GitService struct {
11		server *git.GitServerRepository
12	}
13	Repository struct {
14		Name              string
15		Title             string
16		LastCommitMessage string
17		LastCommitDate    string
18	}
19)
20
21// TODO: make it configurable
22const timeFormat = "2006.01.02 15:04:05"
23
24func NewGitService(server *git.GitServerRepository) *GitService {
25	return &GitService{
26		server: server,
27	}
28}
29
30func (g *GitService) ListRepositories() ([]*Repository, error) {
31	rs, err := g.server.List()
32	if err != nil {
33		return nil, err
34	}
35
36	repos := make([]*Repository, len(rs))
37	for i, r := range rs {
38		obj, err := r.LastCommit()
39		if err != nil {
40			return nil, err
41		}
42
43		baseName := path.Base(r.Path())
44		repos[i] = &Repository{
45			Name:              baseName,
46			Title:             baseName,
47			LastCommitMessage: obj.Message,
48			LastCommitDate:    obj.Author.When.Format(timeFormat),
49		}
50	}
51
52	return repos, nil
53}