From 95963a2472bed743afb685f5db130e6a761e700b Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Mon, 30 Jan 2023 22:09:43 -0800 Subject: [PATCH] extract common into common.go --- commits/chancommits.go | 8 -------- commits/commits.go | 22 ---------------------- commits/common.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 commits/common.go diff --git a/commits/chancommits.go b/commits/chancommits.go index 7cfb850..5c00dcc 100644 --- a/commits/chancommits.go +++ b/commits/chancommits.go @@ -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 { diff --git a/commits/commits.go b/commits/commits.go index 8de7776..7833f51 100644 --- a/commits/commits.go +++ b/commits/commits.go @@ -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 diff --git a/commits/common.go b/commits/common.go new file mode 100644 index 0000000..56703e8 --- /dev/null +++ b/commits/common.go @@ -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 +}