diff_refiner.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package hercules
  2. import (
  3. "gopkg.in/src-d/go-git.v4"
  4. )
  5. type FileDiffRefiner struct {
  6. }
  7. func (ref *FileDiffRefiner) Name() string {
  8. return "FileDiffRefiner"
  9. }
  10. func (ref *FileDiffRefiner) Provides() []string {
  11. arr := [...]string{"file_diff"}
  12. return arr[:]
  13. }
  14. func (ref *FileDiffRefiner) Requires() []string {
  15. arr := [...]string{"file_diff", "changed_uasts"}
  16. return arr[:]
  17. }
  18. func (ref *FileDiffRefiner) Features() []string {
  19. arr := [...]string{"uast"}
  20. return arr[:]
  21. }
  22. func (ref *FileDiffRefiner) ListConfigurationOptions() []ConfigurationOption {
  23. return []ConfigurationOption{}
  24. }
  25. func (ref *FileDiffRefiner) Configure(facts map[string]interface{}) {}
  26. func (ref *FileDiffRefiner) Initialize(repository *git.Repository) {
  27. }
  28. func (ref *FileDiffRefiner) Consume(deps map[string]interface{}) (map[string]interface{}, error) {
  29. changesList := deps["changed_uasts"].([]UASTChange)
  30. changes := map[string]UASTChange{}
  31. for _, change := range changesList {
  32. if change.Before != nil && change.After != nil {
  33. changes[change.Change.To.Name] = change
  34. }
  35. }
  36. diffs := deps["file_diff"].(map[string]FileDiffData)
  37. for fileName, _ /*diff*/ := range diffs {
  38. _ /*change*/ = changes[fileName]
  39. // TODO: scan diff line by line
  40. }
  41. result := map[string]FileDiffData{}
  42. return map[string]interface{}{"file_diff": result}, nil
  43. }
  44. func init() {
  45. Registry.Register(&FileDiffRefiner{})
  46. }