mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
extract common into common.go
This commit is contained in:
@@ -11,14 +11,6 @@ import (
|
|||||||
"github.com/taigrr/mg/parse"
|
"github.com/taigrr/mg/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
|
||||||
Repo git.Repository
|
|
||||||
CommitSet struct {
|
|
||||||
Commits []types.Commit
|
|
||||||
Year int
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func GlobalFrequencyChan(year int, authors []string) (types.YearFreq, error) {
|
func GlobalFrequencyChan(year int, authors []string) (types.YearFreq, error) {
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
if year%4 == 0 {
|
if year%4 == 0 {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package commits
|
package commits
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -13,14 +11,6 @@ import (
|
|||||||
"github.com/taigrr/mg/parse"
|
"github.com/taigrr/mg/parse"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
|
||||||
Repo git.Repository
|
|
||||||
CommitSet struct {
|
|
||||||
Commits []types.Commit
|
|
||||||
Year int
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func GlobalFrequency(year int, authors []string) (types.YearFreq, error) {
|
func GlobalFrequency(year int, authors []string) (types.YearFreq, error) {
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
if year%4 == 0 {
|
if year%4 == 0 {
|
||||||
@@ -52,18 +42,6 @@ func GlobalFrequency(year int, authors []string) (types.YearFreq, error) {
|
|||||||
return gfreq, nil
|
return gfreq, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenRepo(directory string) (Repo, error) {
|
|
||||||
if s, err := os.Stat(directory); err != nil {
|
|
||||||
return Repo{}, err
|
|
||||||
} else {
|
|
||||||
if !s.IsDir() {
|
|
||||||
return Repo{}, errors.New("received path to non-directory for git repo")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r, err := git.PlainOpenWithOptions(directory, &(git.PlainOpenOptions{DetectDotGit: true}))
|
|
||||||
return Repo(*r), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs CommitSet) ToYearFreq() types.YearFreq {
|
func (cs CommitSet) ToYearFreq() types.YearFreq {
|
||||||
year := cs.Year
|
year := cs.Year
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
|
|||||||
30
commits/common.go
Normal file
30
commits/common.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package commits
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
git "github.com/go-git/go-git/v5"
|
||||||
|
|
||||||
|
"github.com/taigrr/gico/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Repo git.Repository
|
||||||
|
CommitSet struct {
|
||||||
|
Commits []types.Commit
|
||||||
|
Year int
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func OpenRepo(directory string) (Repo, error) {
|
||||||
|
if s, err := os.Stat(directory); err != nil {
|
||||||
|
return Repo{}, err
|
||||||
|
} else {
|
||||||
|
if !s.IsDir() {
|
||||||
|
return Repo{}, errors.New("received path to non-directory for git repo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r, err := git.PlainOpenWithOptions(directory, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||||
|
return Repo(*r), err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user