ResolveProject resolves a ref to exactly one project by slug.
(db *sql.DB, ref string, includeArchived bool)
| 35 | |
| 36 | // ResolveProject resolves a ref to exactly one project by slug. |
| 37 | func ResolveProject(db *sql.DB, ref string, includeArchived bool) (*flowdb.Project, error) { |
| 38 | ref = strings.TrimSpace(ref) |
| 39 | if ref == "" { |
| 40 | return nil, fmt.Errorf("empty project ref") |
| 41 | } |
| 42 | |
| 43 | p, err := flowdb.GetProject(db, ref) |
| 44 | if err != nil { |
| 45 | if errors.Is(err, sql.ErrNoRows) { |
| 46 | return nil, fmt.Errorf("no project matching %q", ref) |
| 47 | } |
| 48 | return nil, err |
| 49 | } |
| 50 | if !includeArchived && p.ArchivedAt.Valid { |
| 51 | return nil, fmt.Errorf("project %q is archived", ref) |
| 52 | } |
| 53 | return p, nil |
| 54 | } |
| 55 | |
| 56 | // ResolvePlaybook resolves a ref to exactly one playbook by slug. |
| 57 | // includeArchived controls whether archived rows are eligible. |
no test coverage detected