mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
refactor to make gitfetch compile
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
Reference in New Issue
Block a user