io.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // This package defines several top level IO functions for interacting with
  2. // issues and collections of issues.
  3. //
  4. // Examples:
  5. //
  6. // To check if a folder is spec compliant:
  7. // ...
  8. // if issues.IsIssue(path_to_folder) {
  9. // process_issue(path_to_folder)
  10. // }
  11. //
  12. // Additionally, to check if a folder is a collection of spec compliant issues:
  13. // ...
  14. // if issues.IsIssueCollection(path_to_folder) {
  15. // process_collection(path_to_folder)
  16. // }
  17. //
  18. // To write an [Issue] object to disk:
  19. // ...
  20. // // NOT IMPLEMENTED
  21. //
  22. // To remove an [Issue] object from disk:
  23. // ...
  24. // // NOT IMPLEMENTED
  25. package issues
  26. import (
  27. "os"
  28. )
  29. func readPath(path string) (output string, err error) {
  30. content, err := os.ReadFile(path)
  31. if err != nil {
  32. return "", err
  33. }
  34. for _, line := range content {
  35. output = output + string(line)
  36. }
  37. return output, nil
  38. }
  39. // Reports true when the specified path conforms to the minimum Poorman spec
  40. func IsIssue(path string) bool {
  41. files, err := os.ReadDir(path)
  42. if err != nil {
  43. return false
  44. }
  45. var specFiles []bool
  46. for _, file := range files {
  47. if file.Name() == "description" || file.Name() == "status" {
  48. specFiles = append(specFiles, true)
  49. }
  50. }
  51. if len(specFiles) >= 2 {
  52. return true
  53. }
  54. return false
  55. }
  56. // Reports true when the specified path is a directory of Issues
  57. func IsIssueCollection(path string) bool {
  58. if IsIssue(path) {
  59. return false
  60. }
  61. files, err := os.ReadDir(path)
  62. if err != nil {
  63. return false
  64. }
  65. var isIssue []bool
  66. for _, file := range files {
  67. if IsIssue(path + "/" + file.Name()) {
  68. isIssue = append(isIssue, true)
  69. }
  70. }
  71. if len(isIssue) > 0 {
  72. return true
  73. }
  74. return false
  75. }
  76. // Writes a issue to disk
  77. func WriteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
  78. // Removes a issue from disk
  79. func DeleteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement