diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-07 14:02:25 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-07 14:02:25 +0200 |
commit | 18aa098f50e2a2c7db01dd4d04dde460fd40f5d5 (patch) | |
tree | 5e3b3d3ba3206f2765db1a23a378275852154a51 /pkg/service | |
parent | d0e0c1eb99303e1000140d4b98c610077278dc42 (diff) | |
download | cerrado-18aa098f50e2a2c7db01dd4d04dde460fd40f5d5.tar.gz cerrado-18aa098f50e2a2c7db01dd4d04dde460fd40f5d5.tar.bz2 cerrado-18aa098f50e2a2c7db01dd4d04dde460fd40f5d5.zip |
feat: Add blob endpoint
Diffstat (limited to 'pkg/service')
-rw-r--r-- | pkg/service/git.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/service/git.go b/pkg/service/git.go index 9bf11f4..f886785 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -89,6 +89,38 @@ func (g *GitService) ListCommits(name, ref string) ([]*object.Commit, error) { return repo.Commits() } +func (g *GitService) GetTree(name, ref, path string) (*object.Tree, error) { + // TODO: handle nil + r := g.configRepo.GetByName(name) + + repo, err := git.OpenRepository(r.Path) + if err != nil { + return nil, err + } + err = repo.SetRef(ref) + if err != nil { + return nil, err + } + + return repo.Tree(path) +} + +func (g *GitService) GetFileContent(name, ref, path string) (string, error) { + // TODO: handle nil + r := g.configRepo.GetByName(name) + + repo, err := git.OpenRepository(r.Path) + if err != nil { + return "", err + } + err = repo.SetRef(ref) + if err != nil { + return "", err + } + + return repo.FileContent(path) +} + func (g *GitService) ListTags(name string) ([]*object.Tag, error) { // TODO: handle nil r := g.configRepo.GetByName(name) |