core.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package hercules
  2. import (
  3. git "gopkg.in/src-d/go-git.v4"
  4. "gopkg.in/src-d/go-git.v4/plumbing/object"
  5. "gopkg.in/src-d/hercules.v4/internal/core"
  6. "gopkg.in/src-d/hercules.v4/internal/plumbing"
  7. "gopkg.in/src-d/hercules.v4/internal/plumbing/identity"
  8. "gopkg.in/src-d/hercules.v4/internal/plumbing/uast"
  9. "gopkg.in/src-d/hercules.v4/leaves"
  10. )
  11. // ConfigurationOptionType represents the possible types of a ConfigurationOption's value.
  12. type ConfigurationOptionType = core.ConfigurationOptionType
  13. const (
  14. // BoolConfigurationOption reflects the boolean value type.
  15. BoolConfigurationOption = core.BoolConfigurationOption
  16. // IntConfigurationOption reflects the integer value type.
  17. IntConfigurationOption = core.IntConfigurationOption
  18. // StringConfigurationOption reflects the string value type.
  19. StringConfigurationOption = core.StringConfigurationOption
  20. // FloatConfigurationOption reflects a floating point value type.
  21. FloatConfigurationOption = core.FloatConfigurationOption
  22. // StringsConfigurationOption reflects the array of strings value type.
  23. StringsConfigurationOption = core.StringsConfigurationOption
  24. )
  25. // ConfigurationOption allows for the unified, retrospective way to setup PipelineItem-s.
  26. type ConfigurationOption = core.ConfigurationOption
  27. // PipelineItem is the interface for all the units in the Git commits analysis pipeline.
  28. type PipelineItem = core.PipelineItem
  29. // FeaturedPipelineItem enables switching the automatic insertion of pipeline items on or off.
  30. type FeaturedPipelineItem = core.FeaturedPipelineItem
  31. // LeafPipelineItem corresponds to the top level pipeline items which produce the end results.
  32. type LeafPipelineItem = core.LeafPipelineItem
  33. // MergeablePipelineItem specifies the methods to combine several analysis results together.
  34. type MergeablePipelineItem = core.MergeablePipelineItem
  35. // CommonAnalysisResult holds the information which is always extracted at Pipeline.Run().
  36. type CommonAnalysisResult = core.CommonAnalysisResult
  37. // MetadataToCommonAnalysisResult copies the data from a Protobuf message.
  38. func MetadataToCommonAnalysisResult(meta *core.Metadata) *CommonAnalysisResult {
  39. return core.MetadataToCommonAnalysisResult(meta)
  40. }
  41. // Pipeline is the core Hercules entity which carries several PipelineItems and executes them.
  42. // See the extended example of how a Pipeline works in doc.go
  43. type Pipeline = core.Pipeline
  44. const (
  45. // ConfigPipelineDumpPath is the name of the Pipeline configuration option (Pipeline.Initialize())
  46. // which enables saving the items DAG to the specified file.
  47. ConfigPipelineDumpPath = core.ConfigPipelineDumpPath
  48. // ConfigPipelineDryRun is the name of the Pipeline configuration option (Pipeline.Initialize())
  49. // which disables Configure() and Initialize() invocation on each PipelineItem during the
  50. // Pipeline initialization.
  51. // Subsequent Run() calls are going to fail. Useful with ConfigPipelineDumpPath=true.
  52. ConfigPipelineDryRun = core.ConfigPipelineDryRun
  53. // ConfigPipelineCommits is the name of the Pipeline configuration option (Pipeline.Initialize())
  54. // which allows to specify the custom commit sequence. By default, Pipeline.Commits() is used.
  55. ConfigPipelineCommits = core.ConfigPipelineCommits
  56. )
  57. // NewPipeline initializes a new instance of Pipeline struct.
  58. func NewPipeline(repository *git.Repository) *Pipeline {
  59. return core.NewPipeline(repository)
  60. }
  61. // LoadCommitsFromFile reads the file by the specified FS path and generates the sequence of commits
  62. // by interpreting each line as a Git commit hash.
  63. func LoadCommitsFromFile(path string, repository *git.Repository) ([]*object.Commit, error) {
  64. return core.LoadCommitsFromFile(path, repository)
  65. }
  66. // PipelineItemRegistry contains all the known PipelineItem-s.
  67. type PipelineItemRegistry = core.PipelineItemRegistry
  68. // Registry contains all known pipeline item types.
  69. var Registry = core.Registry
  70. const (
  71. // DependencyAuthor is the name of the dependency provided by identity.Detector.
  72. DependencyAuthor = identity.DependencyAuthor
  73. // DependencyBlobCache identifies the dependency provided by BlobCache.
  74. DependencyBlobCache = plumbing.DependencyBlobCache
  75. // DependencyDay is the name of the dependency which DaysSinceStart provides - the number
  76. // of days since the first commit in the analysed sequence.
  77. DependencyDay = plumbing.DependencyDay
  78. // DependencyFileDiff is the name of the dependency provided by FileDiff.
  79. DependencyFileDiff = plumbing.DependencyFileDiff
  80. // DependencyTreeChanges is the name of the dependency provided by TreeDiff.
  81. DependencyTreeChanges = plumbing.DependencyTreeChanges
  82. // DependencyUastChanges is the name of the dependency provided by Changes.
  83. DependencyUastChanges = uast.DependencyUastChanges
  84. // DependencyUasts is the name of the dependency provided by Extractor.
  85. DependencyUasts = uast.DependencyUasts
  86. // FactCommitsByDay contains the mapping between day indices and the corresponding commits.
  87. FactCommitsByDay = plumbing.FactCommitsByDay
  88. // FactIdentityDetectorPeopleCount is the name of the fact which is inserted in
  89. // identity.Detector.Configure(). It is equal to the overall number of unique authors
  90. // (the length of ReversedPeopleDict).
  91. FactIdentityDetectorPeopleCount = identity.FactIdentityDetectorPeopleCount
  92. // FactIdentityDetectorPeopleDict is the name of the fact which is inserted in
  93. // identity.Detector.Configure(). It corresponds to identity.Detector.PeopleDict - the mapping
  94. // from the signatures to the author indices.
  95. FactIdentityDetectorPeopleDict = identity.FactIdentityDetectorPeopleDict
  96. // FactIdentityDetectorReversedPeopleDict is the name of the fact which is inserted in
  97. // identity.Detector.Configure(). It corresponds to identity.Detector.ReversedPeopleDict -
  98. // the mapping from the author indices to the main signature.
  99. FactIdentityDetectorReversedPeopleDict = identity.FactIdentityDetectorReversedPeopleDict
  100. )
  101. // FileDiffData is the type of the dependency provided by plumbing.FileDiff.
  102. type FileDiffData = plumbing.FileDiffData
  103. // CountLines returns the number of lines in a *object.Blob.
  104. func CountLines(file *object.Blob) (int, error) {
  105. return plumbing.CountLines(file)
  106. }
  107. func init() {
  108. // hack to link with .leaves
  109. _ = leaves.BurndownAnalysis{}
  110. }