io.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package issues
  2. import (
  3. "os"
  4. )
  5. func readPath(path string) (output string, err error) {
  6. content, err := os.ReadFile(path)
  7. if err != nil {
  8. return "", err
  9. }
  10. for _, line := range content {
  11. output = output + string(line)
  12. }
  13. return output, nil
  14. }
  15. // Reports true when the specified path conforms to the minimum Poorman spec
  16. func IsIssue(path string) bool {
  17. files, err := os.ReadDir(path)
  18. if err != nil {
  19. return false
  20. }
  21. var specFiles []bool
  22. for _, file := range files {
  23. if file.Name() == "description" || file.Name() == "status" {
  24. specFiles = append(specFiles, true)
  25. }
  26. }
  27. if len(specFiles) >= 2 {
  28. return true
  29. }
  30. return false
  31. }
  32. // Reports true when the specified path is a directory of Issues
  33. func IsIssueCollection(path string) bool {
  34. if IsIssue(path) {
  35. return false
  36. }
  37. files, err := os.ReadDir(path)
  38. if err != nil {
  39. return false
  40. }
  41. var isIssue []bool
  42. for _, file := range files {
  43. if IsIssue(path + "/" + file.Name()) {
  44. isIssue = append(isIssue, true)
  45. }
  46. }
  47. if len(isIssue) > 0 {
  48. return true
  49. }
  50. return false
  51. }
  52. // Writes a issue to disk
  53. func WriteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
  54. // Removes a issue from disk
  55. func DeleteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement