|
@@ -4,6 +4,7 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"gopkg.in/src-d/go-git.v4"
|
|
|
+ "gopkg.in/src-d/go-git.v4/plumbing"
|
|
|
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
|
|
)
|
|
|
|
|
@@ -12,12 +13,16 @@ import (
|
|
|
type DaysSinceStart struct {
|
|
|
day0 time.Time
|
|
|
previousDay int
|
|
|
+ commits map[int][]plumbing.Hash
|
|
|
}
|
|
|
|
|
|
const (
|
|
|
// DependencyDay is the name of the dependency which DaysSinceStart provides - the number
|
|
|
// of days since the first commit in the analysed sequence.
|
|
|
DependencyDay = "day"
|
|
|
+
|
|
|
+ // FactCommitsByDay contains the mapping between day indices and the corresponding commits.
|
|
|
+ FactCommitsByDay = "DaysSinceStart.Commits"
|
|
|
)
|
|
|
|
|
|
// Name of this PipelineItem. Uniquely identifies the type, used for mapping keys, etc.
|
|
@@ -46,13 +51,27 @@ func (days *DaysSinceStart) ListConfigurationOptions() []ConfigurationOption {
|
|
|
}
|
|
|
|
|
|
// Configure sets the properties previously published by ListConfigurationOptions().
|
|
|
-func (days *DaysSinceStart) Configure(facts map[string]interface{}) {}
|
|
|
+func (days *DaysSinceStart) Configure(facts map[string]interface{}) {
|
|
|
+ if days.commits == nil {
|
|
|
+ days.commits = map[int][]plumbing.Hash{}
|
|
|
+ }
|
|
|
+ facts[FactCommitsByDay] = days.commits
|
|
|
+}
|
|
|
|
|
|
// Initialize resets the temporary caches and prepares this PipelineItem for a series of Consume()
|
|
|
// calls. The repository which is going to be analysed is supplied as an argument.
|
|
|
func (days *DaysSinceStart) Initialize(repository *git.Repository) {
|
|
|
days.day0 = time.Time{}
|
|
|
days.previousDay = 0
|
|
|
+ if len(days.commits) > 0 {
|
|
|
+ keys := make([]int, len(days.commits))
|
|
|
+ for key := range days.commits {
|
|
|
+ keys = append(keys, key)
|
|
|
+ }
|
|
|
+ for _, key := range keys {
|
|
|
+ delete(days.commits, key)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Consume runs this PipelineItem on the next commit data.
|
|
@@ -75,6 +94,11 @@ func (days *DaysSinceStart) Consume(deps map[string]interface{}) (map[string]int
|
|
|
day = days.previousDay
|
|
|
}
|
|
|
days.previousDay = day
|
|
|
+ dayCommits := days.commits[day]
|
|
|
+ if dayCommits == nil {
|
|
|
+ dayCommits = []plumbing.Hash{}
|
|
|
+ }
|
|
|
+ days.commits[day] = append(dayCommits, commit.Hash)
|
|
|
return map[string]interface{}{DependencyDay: day}, nil
|
|
|
}
|
|
|
|