MCPcopy Create free account
hub / github.com/Facets-cloud/flow / uniqueSlug

Function uniqueSlug

internal/app/add.go:331–351  ·  view source on GitHub ↗

uniqueSlug returns base if no row with that slug exists in table; otherwise appends -2, -3, ... until it finds an unused one.

(db *sql.DB, table, base string)

Source from the content-addressed store, hash-verified

329// uniqueSlug returns base if no row with that slug exists in table;
330// otherwise appends -2, -3, ... until it finds an unused one.
331func uniqueSlug(db *sql.DB, table, base string) (string, error) {
332 slug := base
333 n := 2
334 for {
335 var exists int
336 // nolint:gosec — table name is hardcoded ("projects" or "tasks").
337 q := "SELECT 1 FROM " + table + " WHERE slug = ?"
338 err := db.QueryRow(q, slug).Scan(&exists)
339 if errors.Is(err, sql.ErrNoRows) {
340 return slug, nil
341 }
342 if err != nil {
343 return "", err
344 }
345 slug = fmt.Sprintf("%s-%d", base, n)
346 n++
347 if n > 1000 {
348 return "", fmt.Errorf("slug %q: too many collisions", base)
349 }
350 }
351}
352
353func isValidPriority(p string) bool {
354 return p == "high" || p == "medium" || p == "low"

Callers 4

addOwnerFunction · 0.85
addPlaybookFunction · 0.85
addProjectFunction · 0.85
addTaskFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected