mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
move types to types package
This commit is contained in:
@@ -8,12 +8,13 @@ import (
|
|||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
git "github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
gterm "github.com/taigrr/gico/gitgraph/term"
|
|
||||||
|
|
||||||
"github.com/taigrr/gico/types"
|
"github.com/taigrr/gico/types"
|
||||||
"github.com/taigrr/mg/parse"
|
"github.com/taigrr/mg/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Repo git.Repository
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
year := time.Now().Year() - 1
|
year := time.Now().Year() - 1
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
@@ -21,7 +22,7 @@ func main() {
|
|||||||
yearLength++
|
yearLength++
|
||||||
}
|
}
|
||||||
|
|
||||||
gfreq := make(YearFreq, yearLength)
|
gfreq := make(types.YearFreq, yearLength)
|
||||||
|
|
||||||
mrconf, err := parse.LoadMRConfig()
|
mrconf, err := parse.LoadMRConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,22 +43,6 @@ func main() {
|
|||||||
fmt.Print(gfreq.String())
|
fmt.Print(gfreq.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repo git.Repository
|
|
||||||
|
|
||||||
func (a YearFreq) Merge(b YearFreq) YearFreq {
|
|
||||||
x := len(a)
|
|
||||||
y := len(b)
|
|
||||||
if x < y {
|
|
||||||
x = y
|
|
||||||
}
|
|
||||||
c := make(YearFreq, x)
|
|
||||||
copy(c, a)
|
|
||||||
for i := 0; i < y; i++ {
|
|
||||||
c[i] += b[i]
|
|
||||||
}
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func OpenRepo(directory string) (Repo, error) {
|
func OpenRepo(directory string) (Repo, error) {
|
||||||
if s, err := os.Stat(directory); err != nil {
|
if s, err := os.Stat(directory); err != nil {
|
||||||
return Repo{}, err
|
return Repo{}, err
|
||||||
@@ -71,13 +56,7 @@ func OpenRepo(directory string) (Repo, error) {
|
|||||||
return Repo(*r), err
|
return Repo(*r), err
|
||||||
}
|
}
|
||||||
|
|
||||||
type YearFreq []int
|
func (repo Repo) GetYear(year int) (types.YearFreq, error) {
|
||||||
|
|
||||||
func (yf YearFreq) String() string {
|
|
||||||
return gterm.GetYearUnicode(yf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo Repo) GetYear(year int) (YearFreq, error) {
|
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
if year%4 == 0 {
|
if year%4 == 0 {
|
||||||
yearLength++
|
yearLength++
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
gterm "github.com/taigrr/gico/gitgraph/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDataSet() DataSet {
|
func NewDataSet() DataSet {
|
||||||
@@ -9,10 +11,27 @@ func NewDataSet() DataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCommit(Author, Message, Repo, Path string, LOC int) Commit {
|
func NewCommit(Author, Message, Repo, Path string, LOC int) Commit {
|
||||||
ci := Commit{
|
return Commit{
|
||||||
Message: Message,
|
Message: Message,
|
||||||
Author: Author, LOC: LOC, TimeStamp: time.Now(),
|
Author: Author, LOC: LOC, TimeStamp: time.Now(),
|
||||||
Repo: Repo, Path: Path,
|
Repo: Repo, Path: Path,
|
||||||
}
|
}
|
||||||
return ci
|
}
|
||||||
|
|
||||||
|
func (yf YearFreq) String() string {
|
||||||
|
return gterm.GetYearUnicode(yf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a YearFreq) Merge(b YearFreq) YearFreq {
|
||||||
|
x := len(a)
|
||||||
|
y := len(b)
|
||||||
|
if x < y {
|
||||||
|
x = y
|
||||||
|
}
|
||||||
|
c := make(YearFreq, x)
|
||||||
|
copy(c, a)
|
||||||
|
for i := 0; i < y; i++ {
|
||||||
|
c[i] += b[i]
|
||||||
|
}
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Month string
|
type (
|
||||||
|
Month string
|
||||||
type Commit struct {
|
Commit struct {
|
||||||
LOC int `json:"loc,omitempty"`
|
LOC int `json:"loc,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
TimeStamp time.Time `json:"ts,omitempty"`
|
TimeStamp time.Time `json:"ts,omitempty"`
|
||||||
@@ -14,11 +14,11 @@ type Commit struct {
|
|||||||
Repo string `json:"repo,omitempty"`
|
Repo string `json:"repo,omitempty"`
|
||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
DataSet map[time.Time]WorkDay
|
||||||
type DataSet map[time.Time]WorkDay
|
YearFreq []int
|
||||||
|
WorkDay struct {
|
||||||
type WorkDay struct {
|
|
||||||
Day time.Time `json:"day"`
|
Day time.Time `json:"day"`
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Commits []Commit `json:"commits,omitempty"`
|
Commits []Commit `json:"commits,omitempty"`
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user