aboutsummaryrefslogtreecommitdiff
path: root/pkg/git/git.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-05-27 22:36:50 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-05-27 22:42:16 +0200
commit2dd4cf35aab8324608a83d337459fd8354521b92 (patch)
treeb65ecc803260bc268332fb2fbce83ab5dd209dbc /pkg/git/git.go
parent60e8e751c76d949a28eefe0c5462e0cf17337217 (diff)
downloadcerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.gz
cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.tar.bz2
cerrado-2dd4cf35aab8324608a83d337459fd8354521b92.zip
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.
Diffstat (limited to 'pkg/git/git.go')
-rw-r--r--pkg/git/git.go42
1 files changed, 4 insertions, 38 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 85a3b95..b9ab235 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -2,63 +2,29 @@ package git
import (
"errors"
- "os"
- "path"
- "git.gabrielgio.me/cerrado/pkg/u"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
)
+var ()
+
var (
- ScanPathErr = errors.New("Scan path does not exist")
- RepoPathErr = errors.New("Repository path does not exist")
- missingHeadErr = errors.New("Head not found")
+ MissingHeadErr = errors.New("Head not found")
)
type (
- GitServerRepository struct {
- scanPath string
- }
-
GitRepository struct {
path string
}
)
-func NewGitServerRepository(scanPath string) *GitServerRepository {
- return &GitServerRepository{scanPath}
-}
-
func NewGitRepository(dir string) *GitRepository {
return &GitRepository{
path: dir,
}
}
-func (g *GitServerRepository) List() ([]*GitRepository, error) {
- if !u.FileExist(g.scanPath) {
- return nil, ScanPathErr
- }
-
- entries, err := os.ReadDir(g.scanPath)
- if err != nil {
- return nil, err
- }
-
- repos := make([]*GitRepository, 0)
- for _, e := range entries {
- if !e.IsDir() {
- continue
- }
-
- fullPath := path.Join(g.scanPath, e.Name())
- repos = append(repos, NewGitRepository(fullPath))
- }
-
- return repos, nil
-}
-
func (g *GitRepository) Path() string {
return g.path
}
@@ -71,7 +37,7 @@ func (g *GitRepository) LastCommit() (*object.Commit, error) {
ref, err := repo.Head()
if err != nil {
- return nil, errors.Join(missingHeadErr, err)
+ return nil, errors.Join(MissingHeadErr, err)
}
c, err := repo.CommitObject(ref.Hash())