doc.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Package hercules contains the functions which are needed to gather various statistics
  3. from a Git repository.
  4. The analysis is expressed in a form of the tree: there are nodes - "pipeline items" - which
  5. require some other nodes to be executed prior to selves and in turn provide the data for
  6. dependent nodes. There are several service items which do not produce any useful
  7. statistics but rather provide the requirements for other items. The top-level items
  8. include:
  9. - BurndownAnalysis - line burndown statistics for project, files and developers.
  10. - CouplesAnalysis - coupling statistics for files and developers.
  11. - ShotnessAnalysis - structural hotness and couples, by any Babelfish UAST XPath (functions by default).
  12. The typical API usage is to initialize the Pipeline class:
  13. import "gopkg.in/src-d/go-git.v4"
  14. var repository *git.Repository
  15. // ...initialize repository...
  16. pipeline := hercules.NewPipeline(repository)
  17. Then add the required analysis:
  18. ba := pipeline.DeployItem(&hercules.BurndownAnalysis{}).(hercules.LeafPipelineItem)
  19. This call will add all the needed intermediate pipeline items. Then link and execute the analysis tree:
  20. pipeline.Initialize(nil)
  21. result, err := pipeline.Run(pipeline.Commits(false))
  22. Finally extract the result:
  23. result := result[ba].(hercules.BurndownResult)
  24. The actual usage example is cmd/hercules/root.go - the command line tool's code.
  25. You can provide additional options via `facts` on initialization. For example,
  26. to provide your own logger, enable people-tracking, and set a custom tick size:
  27. pipe.Initialize(map[string]interface{}{
  28. hercules.ConfigLogger: zap.NewExample().Sugar(),
  29. hercules.ConfigTickSize: 12,
  30. leaves.ConfigBurndownTrackPeople: true,
  31. })
  32. Hercules depends heavily on https://github.com/src-d/go-git and leverages the
  33. diff algorithm through https://github.com/sergi/go-diff.
  34. Besides, BurndownAnalysis involves File and RBTree. These are low level data structures
  35. which enable incremental blaming. File carries an instance of RBTree and the current line
  36. burndown state. RBTree implements the red-black balanced binary tree and is
  37. based on https://github.com/yasushi-saito/rbtree.
  38. Coupling stats are supposed to be further processed rather than observed directly.
  39. labours.py uses Swivel embeddings and visualises them in Tensorflow Projector.
  40. Shotness analysis as well as other UAST-featured items relies on
  41. [Babelfish](https://doc.bblf.sh) and requires the server to be running.
  42. */
  43. package hercules