Lightweight and easily self-hostable Git forge. git.poy.ooo
git-forge selfhosting homebrew
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485package git
import ( "errors" "farga/lib" errs "farga/lib/errors" "time"
"github.com/go-git/go-git/v6" "github.com/go-git/go-git/v6/plumbing/object")
type LogOptions struct { Repo *git.Repository Branch string FileName string}
type GitCommitAuthor struct { Name string Email string}
type Commit struct { Hash string ShortHash string Author GitCommitAuthor Message string Time time.Time}
type Log []Commit
// gets the log of a branch or file. Don't forget to pass in your repo!func GetLog(o LogOptions) (Log, error) { if o.Repo == nil { return nil, errs.ErrMissingProperty("Repo") }
ref, err := ResolveHead(o.Repo, o.Branch)
if err != nil { return nil, err }
if ref == nil { return nil, ErrRepoHasNoHead }
gitLog, err := o.Repo.Log(&git.LogOptions{ From: ref.Hash(), })
if err != nil { return nil, err }
var log Log
err = gitLog.ForEach(func(c *object.Commit) error { shortHash, err := ShortenHash(c.Hash.String()) if err != nil { return errors.New("Invalid hash length") } log = append(log, Commit{ Hash: c.Hash.String(), ShortHash: shortHash, Author: GitCommitAuthor{ Name: c.Author.Name, Email: c.Author.Email, }, Message: c.Message, Time: c.Author.When, }) return nil })
return log, err}
// shortens a hash. returns the full string if it's asked to trim it at a length greater than it is.func ShortenHash(hash string) (string, error) { return lib.TruncateString(hash, lib.GitHashLength)}