Browse Source

Merge pull request #25 from vmarkovtsev/master

Rename stdout -> yaml
Vadim Markovtsev 7 years ago
parent
commit
9b30d2abc0
7 changed files with 19 additions and 13 deletions
  1. 1 1
      Makefile
  2. 6 6
      burndown.go
  3. 1 0
      cmd/hercules-generate-plugin/plugin.template
  4. 5 5
      couples.go
  5. 2 0
      day.go
  6. 3 0
      day_test.go
  7. 1 1
      stdout/utils.go

+ 1 - 1
Makefile

@@ -20,7 +20,7 @@ ${GOPATH}/src/gopkg.in/bblfsh/client-go.v2:
 	make dependencies
 
 .ONESHELL:
-${GOPATH}/bin/hercules: *.go cmd/hercules/*.go rbtree/*.go stdout/*.go toposort/*.go pb/*.go
+${GOPATH}/bin/hercules: *.go cmd/hercules/*.go rbtree/*.go yaml/*.go toposort/*.go pb/*.go
 	cd ${GOPATH}/src/gopkg.in/src-d/hercules.v3
 	go get -ldflags "-X gopkg.in/src-d/hercules.v3.GIT_HASH=$$(git rev-parse HEAD)" gopkg.in/src-d/hercules.v3/cmd/hercules
 

+ 6 - 6
burndown.go

@@ -15,7 +15,7 @@ import (
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
 	"gopkg.in/src-d/go-git.v4/utils/merkletrie"
 	"gopkg.in/src-d/hercules.v3/pb"
-	"gopkg.in/src-d/hercules.v3/stdout"
+	"gopkg.in/src-d/hercules.v3/yaml"
 )
 
 // BurndownAnalyser allows to gather the line burndown statistics for a Git repository.
@@ -262,26 +262,26 @@ func (analyser *BurndownAnalysis) Serialize(result interface{}, binary bool, wri
 func (analyser *BurndownAnalysis) serializeText(result *BurndownResult, writer io.Writer) {
 	fmt.Fprintln(writer, "  granularity:", analyser.Granularity)
 	fmt.Fprintln(writer, "  sampling:", analyser.Sampling)
-	stdout.PrintMatrix(writer, result.GlobalHistory, 2, "project", true)
+	yaml.PrintMatrix(writer, result.GlobalHistory, 2, "project", true)
 	if len(result.FileHistories) > 0 {
 		fmt.Fprintln(writer, "  files:")
 		keys := sortedKeys(result.FileHistories)
 		for _, key := range keys {
-			stdout.PrintMatrix(writer, result.FileHistories[key], 4, key, true)
+			yaml.PrintMatrix(writer, result.FileHistories[key], 4, key, true)
 		}
 	}
 
 	if len(result.PeopleHistories) > 0 {
 		fmt.Fprintln(writer, "  people_sequence:")
 		for key := range result.PeopleHistories {
-			fmt.Fprintln(writer, "    - "+stdout.SafeString(analyser.reversedPeopleDict[key]))
+			fmt.Fprintln(writer, "    - "+yaml.SafeString(analyser.reversedPeopleDict[key]))
 		}
 		fmt.Fprintln(writer, "  people:")
 		for key, val := range result.PeopleHistories {
-			stdout.PrintMatrix(writer, val, 4, analyser.reversedPeopleDict[key], true)
+			yaml.PrintMatrix(writer, val, 4, analyser.reversedPeopleDict[key], true)
 		}
 		fmt.Fprintln(writer, "  people_interaction: |-")
-		stdout.PrintMatrix(writer, result.PeopleMatrix, 4, "", false)
+		yaml.PrintMatrix(writer, result.PeopleMatrix, 4, "", false)
 	}
 }
 

+ 1 - 0
cmd/hercules-generate-plugin/plugin.template

@@ -15,6 +15,7 @@
 // Usage:
 //
 //    hercules -plugin {{.shlib}} -{{.flag}}
+//    hercules -plugin {{.shlib}} -help
 
 package {{.package}}
 

+ 5 - 5
couples.go

@@ -10,7 +10,7 @@ import (
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
 	"gopkg.in/src-d/go-git.v4/utils/merkletrie"
 	"gopkg.in/src-d/hercules.v3/pb"
-	"gopkg.in/src-d/hercules.v3/stdout"
+	"gopkg.in/src-d/hercules.v3/yaml"
 )
 
 type CouplesAnalysis struct {
@@ -197,7 +197,7 @@ func (couples *CouplesAnalysis) serializeText(result *CouplesResult, writer io.W
 	fmt.Fprintln(writer, "  files_coocc:")
 	fmt.Fprintln(writer, "    index:")
 	for _, file := range result.Files {
-		fmt.Fprintf(writer, "      - %s\n", stdout.SafeString(file))
+		fmt.Fprintf(writer, "      - %s\n", yaml.SafeString(file))
 	}
 
 	fmt.Fprintln(writer, "    matrix:")
@@ -220,7 +220,7 @@ func (couples *CouplesAnalysis) serializeText(result *CouplesResult, writer io.W
 	fmt.Fprintln(writer, "  people_coocc:")
 	fmt.Fprintln(writer, "    index:")
 	for _, person := range couples.reversedPeopleDict {
-		fmt.Fprintf(writer, "      - %s\n", stdout.SafeString(person))
+		fmt.Fprintf(writer, "      - %s\n", yaml.SafeString(person))
 	}
 
 	fmt.Fprintln(writer, "    matrix:")
@@ -243,10 +243,10 @@ func (couples *CouplesAnalysis) serializeText(result *CouplesResult, writer io.W
 	fmt.Fprintln(writer, "    author_files:") // sorted by number of files each author changed
 	peopleFiles := sortByNumberOfFiles(result.PeopleFiles, couples.reversedPeopleDict, result.Files)
 	for _, authorFiles := range peopleFiles {
-		fmt.Fprintf(writer, "      - %s:\n", stdout.SafeString(authorFiles.Author))
+		fmt.Fprintf(writer, "      - %s:\n", yaml.SafeString(authorFiles.Author))
 		sort.Strings(authorFiles.Files)
 		for _, file := range authorFiles.Files {
-			fmt.Fprintf(writer, "        - %s\n", stdout.SafeString(file)) // sorted by path
+			fmt.Fprintf(writer, "        - %s\n", yaml.SafeString(file)) // sorted by path
 		}
 	}
 }

+ 2 - 0
day.go

@@ -42,6 +42,8 @@ func (days *DaysSinceStart) Consume(deps map[string]interface{}) (map[string]int
 	if index == 0 {
 		// first iteration - initialize the file objects from the tree
 		days.day0 = commit.Author.When
+		// our precision is 1 day
+		days.day0 = days.day0.Truncate(24 * time.Hour)
 	}
 	day := int(commit.Author.When.Sub(days.day0).Hours() / 24)
 	if day < days.previousDay {

+ 3 - 0
day_test.go

@@ -44,6 +44,9 @@ func TestDaysSinceStartConsume(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Equal(t, res["day"].(int), 0)
 	assert.Equal(t, dss.previousDay, 0)
+	assert.Equal(t, dss.day0.Hour(), 1)   // 18 UTC+1
+	assert.Equal(t, dss.day0.Minute(), 0) // 30
+	assert.Equal(t, dss.day0.Second(), 0) // 29
 
 	commit, _ = testRepository.CommitObject(plumbing.NewHash(
 		"fc9ceecb6dabcb2aab60e8619d972e8d8208a7df"))

+ 1 - 1
stdout/utils.go

@@ -1,4 +1,4 @@
-package stdout
+package yaml
 
 import (
 	"fmt"