mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
rename bin to cmd
This commit is contained in:
74
cmd/commithook/gico.go
Normal file
74
cmd/commithook/gico.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/taigrr/gico/ui"
|
||||
)
|
||||
|
||||
var days [366]int
|
||||
|
||||
func init() {
|
||||
// parse configs
|
||||
// choose action from CLI
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
printGraph()
|
||||
os.Exit(0)
|
||||
}
|
||||
switch args[0] {
|
||||
// TODO use cobra-cli instead of switch case
|
||||
case "inc", "increment", "add":
|
||||
increment()
|
||||
case "graph":
|
||||
printGraph()
|
||||
case "interactive":
|
||||
ui.InteractiveGraph()
|
||||
case "loadRepo":
|
||||
loadRepo()
|
||||
default:
|
||||
printHelp()
|
||||
}
|
||||
}
|
||||
|
||||
func NewDataSet() types.DataSet {
|
||||
return make(types.DataSet)
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
return ci
|
||||
}
|
||||
|
||||
func loadRepo() {
|
||||
}
|
||||
|
||||
func readCommitDB() types.DataSet {
|
||||
ds := types.DataSet{}
|
||||
return ds
|
||||
}
|
||||
|
||||
func printHelp() {
|
||||
fmt.Println("help:")
|
||||
}
|
||||
|
||||
func increment() {
|
||||
commits := readCommitDB()
|
||||
// crea
|
||||
fmt.Printf("%v\n", commits)
|
||||
}
|
||||
|
||||
func printGraph() {
|
||||
fmt.Println("printGraph")
|
||||
}
|
||||
64
cmd/gitfetch/gitfetch.go
Normal file
64
cmd/gitfetch/gitfetch.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
gterm "github.com/taigrr/gitgraph/term"
|
||||
|
||||
"github.com/taigrr/gico/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
GetYear()
|
||||
}
|
||||
|
||||
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()})
|
||||
|
||||
err = cIter.ForEach(func(c *object.Commit) error {
|
||||
ts := c.Author.When
|
||||
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 = types.WorkDay{}
|
||||
wd.Commits = []types.Commit{}
|
||||
}
|
||||
wd.Commits = append(wd.Commits, commit)
|
||||
wd.Count++
|
||||
wd.Day = roundedTS
|
||||
data[roundedTS] = wd
|
||||
return nil
|
||||
})
|
||||
|
||||
freq := make([]int, yearLength)
|
||||
for k, v := range data {
|
||||
if k.Year() != year {
|
||||
continue
|
||||
}
|
||||
// this is equivalent to adding len(commits) to the freq total, but
|
||||
// it's a stub for later when we do more here
|
||||
for range v.Commits {
|
||||
freq[k.YearDay()-1]++
|
||||
}
|
||||
}
|
||||
gterm.GetYearUnicode(freq)
|
||||
}
|
||||
Reference in New Issue
Block a user