From 7a6ff3565e8e5f55d50c509c9ee12438b61c850e Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Mon, 12 Dec 2022 21:58:47 +0530 Subject: routes: refs view --- git/git.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'git') diff --git a/git/git.go b/git/git.go index 34a25e5..a34d679 100644 --- a/git/git.go +++ b/git/git.go @@ -78,3 +78,35 @@ func (g *GitRepo) FileContent(path string) (string, error) { return file.Contents() } + +func (g *GitRepo) Tags() ([]*object.Tag, error) { + ti, err := g.r.TagObjects() + if err != nil { + return nil, fmt.Errorf("tag objects: %w", err) + } + + tags := []*object.Tag{} + + _ = ti.ForEach(func(t *object.Tag) error { + tags = append(tags, t) + return nil + }) + + return tags, nil +} + +func (g *GitRepo) Branches() ([]*plumbing.Reference, error) { + bi, err := g.r.Branches() + if err != nil { + return nil, fmt.Errorf("branchs: %w", err) + } + + branches := []*plumbing.Reference{} + + _ = bi.ForEach(func(ref *plumbing.Reference) error { + branches = append(branches, ref) + return nil + }) + + return branches, nil +} -- cgit