diff --git a/gico.go b/bin/commithook/gico.go similarity index 54% rename from gico.go rename to bin/commithook/gico.go index 1f858e5..a0ed63b 100644 --- a/gico.go +++ b/bin/commithook/gico.go @@ -9,8 +9,6 @@ import ( "github.com/taigrr/gico/ui" ) -type Month string - var days [366]int func init() { @@ -26,6 +24,7 @@ func main() { os.Exit(0) } switch args[0] { + // TODO use cobra-cli instead of switch case case "inc", "increment", "add": increment() case "graph": @@ -39,29 +38,12 @@ func main() { } } -type Commit struct { - LOC int `json:"loc,omitempty"` - Message string `json:"message,omitempty"` - TimeStamp time.Time `json:"ts,omitempty"` - Author string `json:"author,omitempty"` - Repo string `json:"repo,omitempty"` - Path string `json:"path,omitempty"` +func NewDataSet() types.DataSet { + return make(types.DataSet) } -type DataSet map[time.Time]WorkDay - -func NewDataSet() DataSet { - return make(DataSet) -} - -type WorkDay struct { - Day time.Time `json:"day"` - Count int `json:"count"` - Commits []Commit `json:"commits,omitempty"` -} - -func NewCommit(Author, Message, Repo, Path string, LOC int) Commit { - ci := Commit{ +func NewCommit(Author, Message, Repo, Path string, LOC int) types.Commit { + ci := types.Commit{ Message: Message, Author: Author, LOC: LOC, TimeStamp: time.Now(), Repo: Repo, Path: Path, @@ -72,8 +54,8 @@ func NewCommit(Author, Message, Repo, Path string, LOC int) Commit { func loadRepo() { } -func readCommitDB() DataSet { - ds := DataSet{} +func readCommitDB() types.DataSet { + ds := types.DataSet{} return ds } diff --git a/bin/gitfetch/gitfetch.go b/bin/gitfetch/gitfetch.go index fa9e0c5..6ab5505 100644 --- a/bin/gitfetch/gitfetch.go +++ b/bin/gitfetch/gitfetch.go @@ -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 { diff --git a/types/helpers.go b/types/helpers.go index 4c91f4c..0f8acd3 100644 --- a/types/helpers.go +++ b/types/helpers.go @@ -1,4 +1,4 @@ -package main +package types import ( "time" diff --git a/types/types.go b/types/types.go index 2459781..6382102 100644 --- a/types/types.go +++ b/types/types.go @@ -1,4 +1,4 @@ -package main +package types import ( "time"