From 2dd4cf35aab8324608a83d337459fd8354521b92 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 27 May 2024 22:36:50 +0200 Subject: feat: Wraps handler into its own package Although this creates more complex folder structure will allow in the feature for a easier testing of those given handlers. --- pkg/service/git.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'pkg/service') diff --git a/pkg/service/git.go b/pkg/service/git.go index 94ca75e..2b1fe25 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -3,44 +3,48 @@ package service import ( "path" + "git.gabrielgio.me/cerrado/pkg/config" "git.gabrielgio.me/cerrado/pkg/git" ) type ( - GitService struct { - server *git.GitServerRepository - } Repository struct { Name string Title string LastCommitMessage string LastCommitDate string } + + GitService struct { + configRepo configurationRepository + } + + configurationRepository interface { + List() []*config.GitRepositoryConfiguration + } ) // TODO: make it configurable const timeFormat = "2006.01.02 15:04:05" -func NewGitService(server *git.GitServerRepository) *GitService { +func NewGitService(configRepo configurationRepository) *GitService { return &GitService{ - server: server, + configRepo: configRepo, } } func (g *GitService) ListRepositories() ([]*Repository, error) { - rs, err := g.server.List() - if err != nil { - return nil, err - } + rs := g.configRepo.List() repos := make([]*Repository, len(rs)) for i, r := range rs { - obj, err := r.LastCommit() + repo := git.NewGitRepository(r.Path) + obj, err := repo.LastCommit() if err != nil { return nil, err } - baseName := path.Base(r.Path()) + baseName := path.Base(r.Path) repos[i] = &Repository{ Name: baseName, Title: baseName, -- cgit v1.2.3