From 352dcda8a8917d3c93763a6cc5f8c37b60cece11 Mon Sep 17 00:00:00 2001 From: Burak Olgun Date: Sat, 1 Aug 2020 18:23:01 +0300 Subject: [PATCH] Revert "Add four-key directory information" This reverts commit 6cd5ae227cb8b70b1fb3329e85d1303d8050762d. --- command/command.go | 27 +++++++++---------------- command/command_test.go | 31 ----------------------------- helpers/commit_helper.go | 1 + helpers/repository_metric_helper.go | 4 ++-- helpers/time_helper.go | 19 +++++++++--------- settings/settings.go | 4 ++-- 6 files changed, 24 insertions(+), 62 deletions(-) delete mode 100644 command/command_test.go diff --git a/command/command.go b/command/command.go index a3fc759..5712903 100644 --- a/command/command.go +++ b/command/command.go @@ -1,4 +1,4 @@ -package command +package Command import ( "errors" @@ -11,8 +11,6 @@ import ( "strings" ) -const DefaultFourKeyDirName = "four-key" - func (c *Commander) Info(args ...interface{}) string { f := c.color("\033[1;36m%s\033[0m") return f(args) @@ -49,7 +47,6 @@ type ICommand interface { Command(cmd string, p string) error GetFourKeyPath() string GetRepositoriesPath(cloneDir string) string - GetUserHomeDir() string Info(...interface{}) string Warn(...interface{}) string Fatal(...interface{}) string @@ -75,33 +72,27 @@ func (c *Commander) Command(command string, p string) error { } func (c *Commander) GetFourKeyPath() string { - r := c.GetUserHomeDir() - - p := path.Join(r, DefaultFourKeyDirName) - err := os.Chdir(p) + r, err := os.UserHomeDir() if err != nil { - log.Fatal(c.Fatal("four-key path not found! Error: %v", err)) + log.Fatal(err) } + p := path.Join(r, "four-key") + err = os.Mkdir(p, os.ModePerm) + return p } -func (c *Commander) GetUserHomeDir() string { +func (c *Commander) GetRepositoriesPath(cloneDir string) string { r, err := os.UserHomeDir() if err != nil { log.Fatal(err) } - return r -} - -func (c *Commander) GetRepositoriesPath(cloneDir string) string { - r := c.GetUserHomeDir() - - p := path.Join(r, DefaultFourKeyDirName, cloneDir) - err := os.Mkdir(p, os.ModePerm) + p := path.Join(r, "four-key", cloneDir) + err = os.Mkdir(p, os.ModePerm) log.Println(err) diff --git a/command/command_test.go b/command/command_test.go deleted file mode 100644 index c1e2317..0000000 --- a/command/command_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package command - -import ( - "four-key/command/mocks" - "github.com/stretchr/testify/suite" - "testing" -) - -type Suite struct { - suite.Suite - mock mocks.Command - - command Commander -} - -func (s *Suite) AfterTest(_, _ string) { - s.mock.AssertExpectations(s.T()) - s.command = Commander{} -} - -func TestInit(t *testing.T) { - suite.Run(t, new(Suite)) -} - -func (s *Suite) SetupSuite() { -} - - -func (s *Suite) TestGet_WhenBeforeInitialize_ReturnsError() { - s.True(true) -} diff --git a/helpers/commit_helper.go b/helpers/commit_helper.go index 2a17b5f..623c4a0 100644 --- a/helpers/commit_helper.go +++ b/helpers/commit_helper.go @@ -10,6 +10,7 @@ import ( ) func GetTagFixAndFeatureCommits(fixPatterns []string, tagDateRangeTotalCommits []object.Commit, tagCommits []tagCommit) (metricTags []tagMetricData) { + for i := 0; i < len(tagCommits); i++ { var featureCommits []object.Commit var fixCommits []object.Commit diff --git a/helpers/repository_metric_helper.go b/helpers/repository_metric_helper.go index 93c7199..e8f1942 100644 --- a/helpers/repository_metric_helper.go +++ b/helpers/repository_metric_helper.go @@ -160,11 +160,11 @@ func IsReleaseTag(tagName, releaseTagPattern string) bool { func getTagCommitBetweenDates(r *git.Repository, request MetricsRequest) ([]tagCommit, error) { var commitTags []tagCommit - var sortedTagList = SortTagsByDate(r) + var sortedTagList = GetAscendingOrderByTagDate(r) + var prevTag *tagCommit var lastTag *tagCommit var firstTag *tagCommit - lastTagFound := false firstTagFound := false for _, t := range sortedTagList { diff --git a/helpers/time_helper.go b/helpers/time_helper.go index 42b1a69..2d85722 100644 --- a/helpers/time_helper.go +++ b/helpers/time_helper.go @@ -9,12 +9,12 @@ import ( "time" ) -type TagWrapper struct { +type TagData struct { tagDate time.Time tag *plumbing.Reference } -type timeSlice []TagWrapper +type timeSlice []TagData func (p timeSlice) Len() int { return len(p) @@ -28,8 +28,9 @@ func (p timeSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -func SortTagsByDate(r *git.Repository) (tags []TagWrapper) { - var TagWrapperList = make(map[string]TagWrapper) +func GetAscendingOrderByTagDate(r *git.Repository) (tags []TagData) { + + var tagDataList = make(map[string]TagData) rTags, err := r.Tags() if err != nil { println(err) @@ -37,21 +38,21 @@ func SortTagsByDate(r *git.Repository) (tags []TagWrapper) { var i = 0 err = rTags.ForEach(func(t *plumbing.Reference) error { - c, err := GetCommitFromTagHash(r, t.Hash()) + cm, err := GetCommitFromTagHash(r, t.Hash()) if err != nil { fmt.Println(err) } - if c != nil { - TagWrapperList[string(i)] = TagWrapper{c.Committer.When, t} + if cm != nil { + tagDataList[string(i)] = TagData{cm.Committer.When, t} i++ } return nil }) - sortedTagDataList := make(timeSlice, 0, len(TagWrapperList)) - for _, tag := range TagWrapperList { + sortedTagDataList := make(timeSlice, 0, len(tagDataList)) + for _, tag := range tagDataList { sortedTagDataList = append(sortedTagDataList, tag) } sort.Sort(sortedTagDataList) diff --git a/settings/settings.go b/settings/settings.go index 436c9ac..cacb04d 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -19,7 +19,7 @@ type Setting interface { var settings Settings var isLoaded = false -const DefaultConfigurationFileTemplate = `{"output": "%s", "repositories":[]}` +const TemplateConfig = `{"repositories":[]}` const DefaultTeamName = "master" const EnvironmentFileName = "four-key.json" const DefaultRepositoryDirName = "repos" @@ -65,7 +65,7 @@ func (s *Settings) Load() error { return err } - _, err = f.WriteString(fmt.Sprintf(DefaultConfigurationFileTemplate, s.commander.GetUserHomeDir())) + _, err = f.WriteString(TemplateConfig) fmt.Println(s.commander.Good("Configuration file added.")) fmt.Println(s.commander.Good("please add an repository and run command like -> ./four-key run -s 2018-01-13 -e 2021-01-13"))