From 907c13566c775ac1210bc66de99f7273e7c8a507 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Tue, 25 Jun 2024 20:37:40 +0200 Subject: feat: Add commit page --- pkg/service/git.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pkg/service/git.go') diff --git a/pkg/service/git.go b/pkg/service/git.go index 1d21204..df4e3aa 100644 --- a/pkg/service/git.go +++ b/pkg/service/git.go @@ -94,6 +94,25 @@ func (g *GitService) ListCommits(name, ref string, count int) ([]*object.Commit, return repo.Commits(count) } +func (g *GitService) LastCommit(name, ref string) (*object.Commit, error) { + r := g.configRepo.GetByName(name) + if r == nil { + return nil, ErrRepositoryNotFound + } + + repo, err := git.OpenRepository(r.Path) + if err != nil { + return nil, err + } + + err = repo.SetRef(ref) + if err != nil { + return nil, err + } + + return repo.LastCommit() +} + func (g *GitService) WriteTarGZip(w io.Writer, name, ref string, prefix string) error { r := g.configRepo.GetByName(name) if r == nil { -- cgit v1.2.3