فهرست منبع

Merge pull request #298 from vmarkovtsev/master

Fix --shotness
Vadim Markovtsev 5 سال پیش
والد
کامیت
89b5284127

+ 1 - 2
contrib/_plugin_example/churn_analysis.go

@@ -73,13 +73,12 @@ func (churn *ChurnAnalysis) Provides() []string {
 // tick - number of ticks since start for each commit
 // author - author of the commit
 func (churn *ChurnAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		hercules.DependencyFileDiff,
 		hercules.DependencyTreeChanges,
 		hercules.DependencyBlobCache,
 		hercules.DependencyTick,
 		hercules.DependencyAuthor}
-	return arr[:]
 }
 
 // ListConfigurationOptions tells the engine which parameters can be changed through the command

+ 1 - 2
internal/core/forks_test.go

@@ -20,8 +20,7 @@ func (item *testForkPipelineItem) Name() string {
 }
 
 func (item *testForkPipelineItem) Provides() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *testForkPipelineItem) Requires() []string {

+ 10 - 6
internal/core/pipeline.go

@@ -385,7 +385,7 @@ func (pipeline *Pipeline) DeployItem(item PipelineItem) PipelineItem {
 			pipeline.SetFeature(f)
 		}
 	}
-	queue := []PipelineItem{}
+	var queue []PipelineItem
 	queue = append(queue, item)
 	added := map[string]PipelineItem{}
 	for _, item := range pipeline.items {
@@ -514,7 +514,7 @@ func (items sortablePipelineItems) Swap(i, j int) {
 	items[i], items[j] = items[j], items[i]
 }
 
-func (pipeline *Pipeline) resolve(dumpPath string) {
+func (pipeline *Pipeline) resolve(dumpPath string) error {
 	graph := toposort.NewGraph()
 	sort.Sort(sortablePipelineItems(pipeline.items))
 	name2item := map[string]PipelineItem{}
@@ -553,7 +553,7 @@ func (pipeline *Pipeline) resolve(dumpPath string) {
 						fmt.Fprintln(os.Stderr, "]")
 					}
 					pipeline.l.Critical("Failed to resolve pipeline dependencies: ambiguous graph.")
-					return
+					return errors.New("ambiguous graph")
 				}
 				ambiguousMap[key] = graph.FindParents(key)
 			}
@@ -571,7 +571,7 @@ func (pipeline *Pipeline) resolve(dumpPath string) {
 			key = "[" + key + "]"
 			if graph.AddEdge(key, name) == 0 {
 				pipeline.l.Criticalf("Unsatisfied dependency: %s -> %s", key, item.Name())
-				return
+				return errors.New("unsatisfied dependency")
 			}
 		}
 	}
@@ -625,7 +625,7 @@ func (pipeline *Pipeline) resolve(dumpPath string) {
 	strplan, ok := graph.Toposort()
 	if !ok {
 		pipeline.l.Critical("Failed to resolve pipeline dependencies: unable to topologically sort the items.")
-		return
+		return errors.New("topological sort failure")
 	}
 	pipeline.items = make([]PipelineItem, 0, len(pipeline.items))
 	for _, key := range strplan {
@@ -640,6 +640,7 @@ func (pipeline *Pipeline) resolve(dumpPath string) {
 		absPath, _ := filepath.Abs(dumpPath)
 		pipeline.l.Infof("Wrote the DAG to %s\n", absPath)
 	}
+	return nil
 }
 
 // Initialize prepares the pipeline for the execution (Run()). This function
@@ -685,7 +686,10 @@ func (pipeline *Pipeline) Initialize(facts map[string]interface{}) error {
 		pipeline.HibernationDistance = val
 	}
 	dumpPath, _ := facts[ConfigPipelineDAGPath].(string)
-	pipeline.resolve(dumpPath)
+	err := pipeline.resolve(dumpPath)
+	if err != nil {
+		return err
+	}
 	if dumpPlan, exists := facts[ConfigPipelineDumpPlan].(bool); exists {
 		pipeline.DumpPlan = dumpPlan
 	}

+ 4 - 7
internal/core/pipeline_test.go

@@ -41,8 +41,7 @@ func (item *testPipelineItem) Name() string {
 }
 
 func (item *testPipelineItem) Provides() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *testPipelineItem) Requires() []string {
@@ -163,13 +162,11 @@ func (item *dependingTestPipelineItem) Name() string {
 }
 
 func (item *dependingTestPipelineItem) Provides() []string {
-	arr := [...]string{"test2"}
-	return arr[:]
+	return []string{"test2"}
 }
 
 func (item *dependingTestPipelineItem) Requires() []string {
-	arr := [...]string{"test"}
-	return arr[:]
+	return []string{"test"}
 }
 
 func (item *dependingTestPipelineItem) ListConfigurationOptions() []ConfigurationOption {
@@ -510,7 +507,7 @@ func TestPipelineError(t *testing.T) {
 	item := &testPipelineItem{}
 	item.TestError = true
 	pipeline.AddItem(item)
-	pipeline.Initialize(map[string]interface{}{})
+	assert.NoError(t, pipeline.Initialize(map[string]interface{}{}))
 	commits := make([]*object.Commit, 1)
 	commits[0], _ = test.Repository.CommitObject(plumbing.NewHash(
 		"af9ddc0db70f09f3f27b4b98e415592a7485171c"))

+ 6 - 12
internal/core/registry_test.go

@@ -28,8 +28,7 @@ func (item *dummyPipelineItem) Name() string {
 }
 
 func (item *dummyPipelineItem) Provides() []string {
-	arr := [...]string{"dummy"}
-	return arr[:]
+	return []string{"dummy"}
 }
 
 func (item *dummyPipelineItem) Requires() []string {
@@ -37,8 +36,7 @@ func (item *dummyPipelineItem) Requires() []string {
 }
 
 func (item *dummyPipelineItem) Features() []string {
-	arr := [...]string{"power"}
-	return arr[:]
+	return []string{"power"}
 }
 
 func (item *dummyPipelineItem) Configure(facts map[string]interface{}) error {
@@ -78,8 +76,7 @@ func (item *dummyPipelineItem2) Name() string {
 }
 
 func (item *dummyPipelineItem2) Provides() []string {
-	arr := [...]string{"dummy2"}
-	return arr[:]
+	return []string{"dummy2"}
 }
 
 func (item *dummyPipelineItem2) Requires() []string {
@@ -87,8 +84,7 @@ func (item *dummyPipelineItem2) Requires() []string {
 }
 
 func (item *dummyPipelineItem2) Features() []string {
-	arr := [...]string{"other"}
-	return arr[:]
+	return []string{"other"}
 }
 
 func (item *dummyPipelineItem2) Configure(facts map[string]interface{}) error {
@@ -121,8 +117,7 @@ func (item *dummyPipelineItem3) Name() string {
 }
 
 func (item *dummyPipelineItem3) Provides() []string {
-	arr := [...]string{"dummy3"}
-	return arr[:]
+	return []string{"dummy3"}
 }
 
 func (item *dummyPipelineItem3) Requires() []string {
@@ -159,8 +154,7 @@ func (item *dummyPipelineItem4) Name() string {
 }
 
 func (item *dummyPipelineItem4) Provides() []string {
-	arr := [...]string{"dummy4"}
-	return arr[:]
+	return []string{"dummy4"}
 }
 
 func (item *dummyPipelineItem4) Requires() []string {

+ 2 - 4
internal/plumbing/blob_cache.go

@@ -107,16 +107,14 @@ func (blobCache *BlobCache) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (blobCache *BlobCache) Provides() []string {
-	arr := [...]string{DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyBlobCache}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (blobCache *BlobCache) Requires() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/diff.go

@@ -52,16 +52,14 @@ func (diff *FileDiff) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (diff *FileDiff) Provides() []string {
-	arr := [...]string{DependencyFileDiff}
-	return arr[:]
+	return []string{DependencyFileDiff}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (diff *FileDiff) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
internal/plumbing/identity/identity.go

@@ -61,8 +61,7 @@ func (detector *Detector) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (detector *Detector) Provides() []string {
-	arr := [...]string{DependencyAuthor}
-	return arr[:]
+	return []string{DependencyAuthor}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 2 - 4
internal/plumbing/languages.go

@@ -33,16 +33,14 @@ func (langs *LanguagesDetection) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (langs *LanguagesDetection) Provides() []string {
-	arr := [...]string{DependencyLanguages}
-	return arr[:]
+	return []string{DependencyLanguages}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (langs *LanguagesDetection) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/line_stats.go

@@ -43,16 +43,14 @@ func (lsc *LinesStatsCalculator) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (lsc *LinesStatsCalculator) Provides() []string {
-	arr := [...]string{DependencyLineStats}
-	return arr[:]
+	return []string{DependencyLineStats}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (lsc *LinesStatsCalculator) Requires() []string {
-	arr := [...]string{DependencyTreeChanges, DependencyBlobCache, DependencyFileDiff}
-	return arr[:]
+	return []string{DependencyTreeChanges, DependencyBlobCache, DependencyFileDiff}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 4
internal/plumbing/renames.go

@@ -67,16 +67,14 @@ func (ra *RenameAnalysis) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ra *RenameAnalysis) Provides() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ra *RenameAnalysis) Requires() []string {
-	arr := [...]string{DependencyBlobCache, DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyBlobCache, DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
internal/plumbing/ticks.go

@@ -50,8 +50,7 @@ func (ticks *TicksSinceStart) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ticks *TicksSinceStart) Provides() []string {
-	arr := [...]string{DependencyTick}
-	return arr[:]
+	return []string{DependencyTick}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 1 - 2
internal/plumbing/tree_diff.go

@@ -74,8 +74,7 @@ func (treediff *TreeDiff) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (treediff *TreeDiff) Provides() []string {
-	arr := [...]string{DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyTreeChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.

+ 3 - 6
internal/plumbing/uast/diff_refiner.go

@@ -31,22 +31,19 @@ func (ref *FileDiffRefiner) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (ref *FileDiffRefiner) Provides() []string {
-	arr := [...]string{plumbing.DependencyFileDiff}
-	return arr[:]
+	return []string{plumbing.DependencyFileDiff}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ref *FileDiffRefiner) Requires() []string {
-	arr := [...]string{plumbing.DependencyFileDiff, DependencyUastChanges}
-	return arr[:]
+	return []string{plumbing.DependencyFileDiff, DependencyUastChanges}
 }
 
 // Features which must be enabled for this PipelineItem to be automatically inserted into the DAG.
 func (ref *FileDiffRefiner) Features() []string {
-	arr := [...]string{FeatureUast}
-	return arr[:]
+	return []string{FeatureUast}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 6 - 12
internal/plumbing/uast/uast.go

@@ -108,22 +108,19 @@ func (exr *Extractor) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (exr *Extractor) Provides() []string {
-	arr := [...]string{DependencyUasts}
-	return arr[:]
+	return []string{DependencyUasts}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (exr *Extractor) Requires() []string {
-	arr := [...]string{items.DependencyTreeChanges, items.DependencyBlobCache}
-	return arr[:]
+	return []string{items.DependencyTreeChanges, items.DependencyBlobCache}
 }
 
 // Features which must be enabled for this PipelineItem to be automatically inserted into the DAG.
 func (exr *Extractor) Features() []string {
-	arr := [...]string{FeatureUast}
-	return arr[:]
+	return []string{FeatureUast}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.
@@ -380,16 +377,14 @@ func (uc *Changes) Name() string {
 // Each produced entity will be inserted into `deps` of dependent Consume()-s according
 // to this list. Also used by core.Registry to build the global map of providers.
 func (uc *Changes) Provides() []string {
-	arr := [...]string{DependencyUastChanges}
-	return arr[:]
+	return []string{DependencyUastChanges}
 }
 
 // Requires returns the list of names of entities which are needed by this PipelineItem.
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (uc *Changes) Requires() []string {
-	arr := [...]string{DependencyUasts, items.DependencyTreeChanges}
-	return arr[:]
+	return []string{DependencyUasts, items.DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.
@@ -500,8 +495,7 @@ func (saver *ChangesSaver) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (saver *ChangesSaver) Requires() []string {
-	arr := [...]string{DependencyUastChanges}
-	return arr[:]
+	return []string{DependencyUastChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/burndown.go

@@ -199,10 +199,9 @@ func (analyser *BurndownAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (analyser *BurndownAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		items.DependencyFileDiff, items.DependencyTreeChanges, items.DependencyBlobCache,
 		items.DependencyTick, identity.DependencyAuthor}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/comment_sentiment.go

@@ -81,8 +81,7 @@ func (sent *CommentSentimentAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (sent *CommentSentimentAnalysis) Requires() []string {
-	arr := [...]string{uast_items.DependencyUastChanges, items.DependencyTick}
-	return arr[:]
+	return []string{uast_items.DependencyUastChanges, items.DependencyTick}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 2 - 3
leaves/commits.go

@@ -5,7 +5,7 @@ import (
 	"io"
 
 	"github.com/gogo/protobuf/proto"
-	git "gopkg.in/src-d/go-git.v4"
+	"gopkg.in/src-d/go-git.v4"
 	"gopkg.in/src-d/go-git.v4/plumbing"
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
 	"gopkg.in/src-d/hercules.v10/internal/core"
@@ -67,9 +67,8 @@ func (ca *CommitsAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (ca *CommitsAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		identity.DependencyAuthor, items.DependencyLanguages, items.DependencyLineStats}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/couples.go

@@ -89,8 +89,7 @@ func (couples *CouplesAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (couples *CouplesAnalysis) Requires() []string {
-	arr := [...]string{identity.DependencyAuthor, items.DependencyTreeChanges}
-	return arr[:]
+	return []string{identity.DependencyAuthor, items.DependencyTreeChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/devs.go

@@ -81,10 +81,9 @@ func (devs *DevsAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (devs *DevsAnalysis) Requires() []string {
-	arr := [...]string{
+	return []string{
 		identity.DependencyAuthor, items.DependencyTreeChanges, items.DependencyTick,
 		items.DependencyLanguages, items.DependencyLineStats}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/file_history.go

@@ -57,8 +57,7 @@ func (history *FileHistoryAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (history *FileHistoryAnalysis) Requires() []string {
-	arr := [...]string{items.DependencyTreeChanges, items.DependencyLineStats, identity.DependencyAuthor}
-	return arr[:]
+	return []string{items.DependencyTreeChanges, items.DependencyLineStats, identity.DependencyAuthor}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 1 - 2
leaves/research/typos.go

@@ -82,9 +82,8 @@ func (tdb *TyposDatasetBuilder) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (tdb *TyposDatasetBuilder) Requires() []string {
-	arr := [...]string{
+	return []string{
 		uast_items.DependencyUastChanges, items.DependencyFileDiff, items.DependencyBlobCache}
-	return arr[:]
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.

+ 6 - 2
leaves/shotness.go

@@ -92,8 +92,7 @@ func (shotness *ShotnessAnalysis) Provides() []string {
 // Each requested entity will be inserted into `deps` of Consume(). In turn, those
 // entities are Provides() upstream.
 func (shotness *ShotnessAnalysis) Requires() []string {
-	arr := [...]string{items.DependencyFileDiff, uast_items.DependencyUastChanges}
-	return arr[:]
+	return []string{items.DependencyFileDiff, uast_items.DependencyUastChanges}
 }
 
 // ListConfigurationOptions returns the list of changeable public properties of this PipelineItem.
@@ -120,6 +119,11 @@ func (shotness *ShotnessAnalysis) Flag() string {
 	return "shotness"
 }
 
+// Features returns the Hercules features required to deploy this leaf.
+func (shotness *ShotnessAnalysis) Features() []string {
+	return []string{uast_items.FeatureUast}
+}
+
 // Description returns the text which explains what the analysis is doing.
 func (shotness *ShotnessAnalysis) Description() string {
 	return "Structural hotness - a fine-grained alternative to --couples. " +

+ 1 - 0
leaves/shotness_test.go

@@ -57,6 +57,7 @@ func TestShotnessMeta(t *testing.T) {
 		core.ConfigLogger: logger,
 	}))
 	assert.Equal(t, logger, sh.l)
+	assert.Equal(t, []string{uast_items.FeatureUast}, sh.Features())
 }
 
 func TestShotnessRegistration(t *testing.T) {