|
@@ -25,9 +25,12 @@
|
|
|
package issues
|
|
package issues
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "errors"
|
|
|
"os"
|
|
"os"
|
|
|
|
|
+ "path/filepath"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// converts file from []string to string, reports errors
|
|
|
func readPath(path string) (output string, err error) {
|
|
func readPath(path string) (output string, err error) {
|
|
|
content, err := os.ReadFile(path)
|
|
content, err := os.ReadFile(path)
|
|
|
|
|
|
|
@@ -89,7 +92,65 @@ func IsIssueCollection(path string) bool {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Writes a issue to disk
|
|
// Writes a issue to disk
|
|
|
-func WriteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
|
|
|
|
|
|
|
+func WriteIssue(issue Issue, ignoreExisting bool) (success bool, err error) {
|
|
|
|
|
+ if IsIssue(issue.Path) && !ignoreExisting {
|
|
|
|
|
+ return false, errors.New("path exists")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // make base directory (effectively, the title)
|
|
|
|
|
+ err = os.Mkdir(issue.Path, 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Write Fields
|
|
|
|
|
+ f := []Field{issue.Description, issue.Status}
|
|
|
|
|
+ for _, field := range f {
|
|
|
|
|
+ if len(field.Path) > 0 { // skip empty paths
|
|
|
|
|
+ path := filepath.Join(issue.Path, field.Path)
|
|
|
|
|
+ err = os.WriteFile(path, []byte(field.Data), 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err // test by overwrite path
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Write Tags
|
|
|
|
|
+ if len(issue.Tags.Path) > 0 { // skip tags with no path init
|
|
|
|
|
+ err = os.Mkdir(filepath.Join(issue.Path, issue.Tags.Path), 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err // test by overwrite path
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, field := range issue.Tags.Fields {
|
|
|
|
|
+ if len(field.Path) > 0 { // skip empty paths
|
|
|
|
|
+ path := filepath.Join(issue.Path, issue.Tags.Path, field.Path)
|
|
|
|
|
+ err = os.WriteFile(path, []byte(field.Data), 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err // test by overwrite path
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Write Blockedby
|
|
|
|
|
+ if len(issue.Tags.Path) > 0 { // skip blockedby with no path init
|
|
|
|
|
+ err = os.Mkdir(filepath.Join(issue.Path, issue.Blockedby.Path), 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err // test by overwrite path
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, field := range issue.Blockedby.Fields {
|
|
|
|
|
+ if len(field.Path) > 0 { // skip empty paths
|
|
|
|
|
+ path := filepath.Join(issue.Path, issue.Blockedby.Path, field.Path)
|
|
|
|
|
+ err = os.WriteFile(path, []byte(field.Data), 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return false, err // test by overwrite path
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true, nil
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// Removes a issue from disk
|
|
// Removes a issue from disk
|
|
|
func DeleteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
|
|
func DeleteIssue(issue Issue) (success bool, err error) { return false, nil } // TODO: implement
|