| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package buggo
- import (
- "os"
- )
- func readPath(path string) (output string, err error) {
- content, err := os.ReadFile(path)
- if err != nil {
- return "", err
- }
- for _, line := range content {
- output = output + string(line)
- }
- return output, nil
- }
- func loadVariadicField(pathOnDisk string, vf VariadicField) (v VariadicField, err error) {
- rootPath := pathOnDisk + "/" + vf.Path
- files, err := os.ReadDir(rootPath)
- if err != nil {
- return vf, err
- }
- for _, file := range files {
- data, err := readPath(rootPath + "/" + file.Name())
- if err != nil {
- return vf, err
- }
- vf.Fields = append(vf.Fields, Field{data: data, path: file.Name()})
- }
- return vf, err
- }
- // Loads a bug from disk
- func LoadBug(path string) (bug Bug, err error) {
- // Required Fields
- description := &Field{path: "/description"}
- status := &Field{path: "/status"}
- requiredFields := []*Field{description, status}
- for _, field := range requiredFields {
- data, err := readPath(path + field.path)
- if err != nil {
- return Bug{}, err
- }
- field.data = data
- }
- // Variadic Fields
- tags := VariadicField{Path: "/tags"}
- blockers := VariadicField{Path: "/blockedby"}
- tags, _ = loadVariadicField(path, tags)
- blockers, _ = loadVariadicField(path, blockers)
- // we can ignore the errors, as loadVariadicField already gracefully handles
- //them.
- return Bug{
- Description: *description,
- Status: *status,
- Tags: tags,
- Blockedby: blockers,
- }, err
- }
- // Writes a bug to disk
- func (b Bug) WriteBug() (success bool, err error) { return false, nil } // TODO: implement
- // Removes a bug from disk
- func (b Bug) DeleteBug() (success bool, err error) { return false, nil } // TODO: implement
|