diff --git a/leaves/burndown.go b/leaves/burndown.go index 9186b9a3..03665d7e 100644 --- a/leaves/burndown.go +++ b/leaves/burndown.go @@ -368,7 +368,9 @@ func (analyser *BurndownAnalysis) Finalize() interface{} { globalHistory, lastDay := analyser.groupSparseHistory(analyser.globalHistory, -1) fileHistories := map[string]DenseHistory{} for key, history := range analyser.fileHistories { - fileHistories[key], _ = analyser.groupSparseHistory(history, lastDay) + if len(history) > 0 { + fileHistories[key], _ = analyser.groupSparseHistory(history, lastDay) + } } peopleHistories := make([]DenseHistory, analyser.PeopleNumber) for i, history := range analyser.peopleHistories { diff --git a/leaves/burndown_test.go b/leaves/burndown_test.go index 5999186b..9ff89183 100644 --- a/leaves/burndown_test.go +++ b/leaves/burndown_test.go @@ -1170,3 +1170,18 @@ func TestBurndownDeserialize(t *testing.T) { assert.Equal(t, result.granularity, 30) assert.Equal(t, result.sampling, 30) } + +func TestBurndownEmptyFileHistory(t *testing.T) { + burndown := &BurndownAnalysis{ + Sampling: 30, + Granularity: 30, + globalHistory: sparseHistory{0: map[int]int64{0: 10}}, + fileHistories: map[string]sparseHistory{"test.go": {}}, + } + res := burndown.Finalize().(BurndownResult) + assert.Len(t, res.GlobalHistory, 1) + assert.Len(t, res.FileHistories, 0) + assert.NotNil(t, res.FileHistories) + assert.Len(t, res.PeopleHistories, 0) + assert.NotNil(t, res.PeopleHistories) +}