Quellcode durchsuchen

Disable tracking individual files if not required

Vadim Markovtsev vor 7 Jahren
Ursprung
Commit
f24496cd6d
3 geänderte Dateien mit 45 neuen und 22 gelöschten Zeilen
  1. 29 21
      burndown.go
  2. 15 1
      burndown_test.go
  3. 1 0
      cmd/hercules/main.go

+ 29 - 21
burndown.go

@@ -26,6 +26,10 @@ type BurndownAnalysis struct {
 	// <= Granularity. Try 15 or 30.
 	Sampling int
 
+	// TrackFiles enables or disables the fine-grained per-file burndown analysis.
+	// It does not change the top level burndown results.
+	TrackFiles bool
+
 	// The number of developers for which to collect the burndown stats. 0 disables it.
 	PeopleNumber int
 
@@ -263,15 +267,17 @@ func (analyser *BurndownAnalysis) updateMatrix(
 func (analyser *BurndownAnalysis) newFile(
 	author int, day int, size int, global map[int]int64, people []map[int]int64,
 	matrix []map[int]int64) *File {
-	if analyser.PeopleNumber == 0 {
-		return NewFile(day, size, NewStatus(global, analyser.updateStatus),
-			NewStatus(map[int]int64{}, analyser.updateStatus))
-	}
-	return NewFile(analyser.packPersonWithDay(author, day), size,
-		NewStatus(global, analyser.updateStatus),
-		NewStatus(map[int]int64{}, analyser.updateStatus),
-		NewStatus(people, analyser.updatePeople),
-		NewStatus(matrix, analyser.updateMatrix))
+	statuses := make([]Status, 1)
+	statuses[0] = NewStatus(global, analyser.updateStatus)
+	if analyser.TrackFiles {
+		statuses = append(statuses, NewStatus(map[int]int64{}, analyser.updateStatus))
+	}
+	if analyser.PeopleNumber > 0 {
+		statuses = append(statuses, NewStatus(people, analyser.updatePeople))
+		statuses = append(statuses, NewStatus(matrix, analyser.updateMatrix))
+		day = analyser.packPersonWithDay(author, day)
+	}
+	return NewFile(day, size, statuses...)
 }
 
 func (analyser *BurndownAnalysis) handleInsertion(
@@ -450,20 +456,22 @@ func (analyser *BurndownAnalysis) groupStatus() ([]int64, map[string][]int64, []
 		global[len(global)-1] = group
 	}
 	locals := make(map[string][]int64)
-	for key, file := range analyser.files {
-		status := make([]int64, day/granularity+adjust)
-		var group int64
-		for i := 0; i < day; i++ {
-			group += file.Status(1).(map[int]int64)[i]
-			if (i % granularity) == (granularity - 1) {
-				status[i/granularity] = group
-				group = 0
+	if analyser.TrackFiles {
+		for key, file := range analyser.files {
+			status := make([]int64, day/granularity+adjust)
+			var group int64
+			for i := 0; i < day; i++ {
+				group += file.Status(1).(map[int]int64)[i]
+				if (i % granularity) == (granularity - 1) {
+					status[i/granularity] = group
+					group = 0
+				}
 			}
+			if day%granularity != 0 {
+				status[len(status)-1] = group
+			}
+			locals[key] = status
 		}
-		if day%granularity != 0 {
-			status[len(status)-1] = group
-		}
-		locals[key] = status
 	}
 	peoples := make([][]int64, len(analyser.people))
 	for key, person := range analyser.people {

+ 15 - 1
burndown_test.go

@@ -6,6 +6,7 @@ import (
 	"github.com/stretchr/testify/assert"
 	"gopkg.in/src-d/go-git.v4/plumbing"
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
+	"io"
 )
 
 func TestBurndownMeta(t *testing.T) {
@@ -23,6 +24,7 @@ func TestBurndownConsumeFinalize(t *testing.T) {
 		Granularity:  30,
 		Sampling:     30,
 		PeopleNumber: 2,
+		TrackFiles: true,
 	}
 	burndown.Initialize(testRepository)
 	deps := map[string]interface{}{}
@@ -104,12 +106,13 @@ func TestBurndownConsumeFinalize(t *testing.T) {
 	burndown2 := BurndownAnalysis{
 		Granularity:  30,
 		Sampling:     0,
-		PeopleNumber: 0,
 	}
 	burndown2.Initialize(testRepository)
 	_, err = burndown2.Consume(deps)
 	assert.Nil(t, err)
 	assert.Equal(t, len(burndown2.people), 0)
+	assert.Equal(t, len(burndown2.peopleHistories), 0)
+	assert.Equal(t, len(burndown2.fileHistories), 0)
 
 	// stage 2
 	// 2b1ed978194a94edeabbca6de7ff3b5771d4d665
@@ -237,3 +240,14 @@ func TestBurndownConsumeFinalize(t *testing.T) {
 	}
 }
 
+type panickingCloser struct {
+}
+
+func (c panickingCloser) Close() error {
+	return io.EOF
+}
+
+func TestCheckClose(t *testing.T) {
+	closer := panickingCloser{}
+	assert.Panics(t, func() {checkClose(closer)})
+}

+ 1 - 0
cmd/hercules/main.go

@@ -170,6 +170,7 @@ func main() {
 		Granularity:  granularity,
 		Sampling:     sampling,
 		Debug:        debug,
+		TrackFiles:   withFiles,
 		PeopleNumber: peopleCount,
 	}
 	pipeline.AddItem(burndowner)