extract common into common.go

This commit is contained in:
2023-01-30 22:09:43 -08:00
parent 8b46956ed9
commit 95963a2472
3 changed files with 30 additions and 30 deletions

View File

@@ -11,14 +11,6 @@ import (
"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) {
yearLength := 365
if year%4 == 0 {

View File

@@ -1,8 +1,6 @@
package commits
import (
"errors"
"os"
"regexp"
"time"
@@ -13,14 +11,6 @@ import (
"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) {
yearLength := 365
if year%4 == 0 {
@@ -52,18 +42,6 @@ func GlobalFrequency(year int, authors []string) (types.YearFreq, error) {
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 {
year := cs.Year
yearLength := 365

30
commits/common.go Normal file
View 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
}