refactor to make gitfetch compile

This commit is contained in:
2023-01-26 23:55:26 -08:00
parent 0e40bbab31
commit 0cdc55f430
4 changed files with 22 additions and 37 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
gterm "github.com/taigrr/gitgraph/term"
"github.com/taigrr/gico"
"github.com/taigrr/gico/types"
)
func main() {
@@ -17,24 +17,30 @@ func main() {
}
func GetYear() {
year := time.Now().Year()
yearLength := 365
if year%4 == 0 {
yearLength++
}
data := types.NewDataSet()
r, err := git.PlainOpenWithOptions(".", &(git.PlainOpenOptions{DetectDotGit: true}))
if err != nil {
fmt.Printf("gitfetch error: Could not find a git repository to open!\n")
os.Exit(1)
}
ref, err := r.Head()
// TODO handle this error
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
year := time.Now().Year()
data := gico.NewDataSet()
err = cIter.ForEach(func(c *object.Commit) error {
ts := c.Author.When
commit := gico.Commit{Author: c.Author.Name, Message: c.Message, TimeStamp: ts}
commit := types.Commit{Author: c.Author.Name, Message: c.Message, TimeStamp: ts}
roundedTS := ts.Round(time.Hour * 24)
wd, ok := data[roundedTS]
if !ok {
wd = gico.WorkDay{}
wd.Commits = []gico.Commit{}
wd = types.WorkDay{}
wd.Commits = []types.Commit{}
}
wd.Commits = append(wd.Commits, commit)
wd.Count++
@@ -42,10 +48,7 @@ func GetYear() {
data[roundedTS] = wd
return nil
})
yearLength := 365
if year%4 == 0 {
yearLength++
}
freq := make([]int, yearLength)
for k, v := range data {
if k.Year() != year {