vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Add named release channels and a generic channel file route
24019cb30892b9fc0118697e8b89cd61e9fab576 · Keenan Nemetz · 19d ago · parent 4f8a3da8
Add named release channels and a generic channel file route A channel is a mutable pointer, channels/<name>.md, to one immutable annotated release. The target tag object is recorded so a rewritten tag is detected rather than silently followed. - metadata: channel parse/render/validate, closed-layout and size checks, set/clear writers - CLI: vole release channel set|list|clear; a dangling target is reported - server: maintain/admin path gate and audit for channel.set/clear - index: release_channels table, incremental refresh, per-tag badge query - web: /channels list, /channels/<name> redirect, and /channels/<name>/<path...> serving the target release's tree with OID ETags, Range, revalidation, and octet-stream responses - tests: metadata round trips, index moves, hook role/audit, page/tree/dangling/ private, and the CLI end to end No apt, yum, or other package-manager code is involved: a package layout is a directory in the release tree. Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
forge/index/channels.go +90
| @@ -0,0 +1,90 @@ | |||
| 1 | package index | ||
| 2 | |||
| 3 | // Release channels: channels/<name>.md on the metadata branch names one release. | ||
| 4 | // The rows are derived with the rest of the branch, so a channel page and a | ||
| 5 | // release page's badges are two reads of one snapshot rather than two Git walks. | ||
| 6 | |||
| 7 | import ( | ||
| 8 | "database/sql" | ||
| 9 | "errors" | ||
| 10 | "time" | ||
| 11 | |||
| 12 | "rodent.software/vole/metadata" | ||
| 13 | ) | ||
| 14 | |||
| 15 | func replaceChannels(tx execer, repoID string, channels []metadata.Channel) error { | ||
| 16 | if _, err := tx.Exec(`DELETE FROM release_channels WHERE repo_id=?`, repoID); err != nil { | ||
| 17 | return err | ||
| 18 | } | ||
| 19 | for _, ch := range channels { | ||
| 20 | if _, err := tx.Exec( | ||
| 21 | `INSERT OR REPLACE INTO release_channels | ||
| 22 | (repo_id, name, tag, tag_object, updated_by, updated_at, description) | ||
| 23 | VALUES (?,?,?,?,?,?,?)`, | ||
| 24 | repoID, ch.Name, ch.Release, ch.ReleaseObject, ch.UpdatedBy, ch.UpdatedAt.Unix(), ch.Description); err != nil { | ||
| 25 | return err | ||
| 26 | } | ||
| 27 | } | ||
| 28 | return nil | ||
| 29 | } | ||
| 30 | |||
| 31 | // Channels returns every channel for a repository, sorted by name. | ||
| 32 | func (s *Store) Channels(repoID string) ([]metadata.Channel, error) { | ||
| 33 | rows, err := s.db.Query( | ||
| 34 | `SELECT name, tag, tag_object, updated_by, updated_at, description | ||
| 35 | FROM release_channels WHERE repo_id=? ORDER BY name`, repoID) | ||
| 36 | if err != nil { | ||
| 37 | return nil, err | ||
| 38 | } | ||
| 39 | defer rows.Close() | ||
| 40 | var out []metadata.Channel | ||
| 41 | for rows.Next() { | ||
| 42 | var ch metadata.Channel | ||
| 43 | var at int64 | ||
| 44 | if err := rows.Scan(&ch.Name, &ch.Release, &ch.ReleaseObject, &ch.UpdatedBy, &at, &ch.Description); err != nil { | ||
| 45 | return nil, err | ||
| 46 | } | ||
| 47 | ch.UpdatedAt = time.Unix(at, 0).UTC() | ||
| 48 | out = append(out, ch) | ||
| 49 | } | ||
| 50 | return out, rows.Err() | ||
| 51 | } | ||
| 52 | |||
| 53 | // Channel returns one channel by name. | ||
| 54 | func (s *Store) Channel(repoID, name string) (metadata.Channel, bool, error) { | ||
| 55 | var ch metadata.Channel | ||
| 56 | var at int64 | ||
| 57 | err := s.db.QueryRow( | ||
| 58 | `SELECT name, tag, tag_object, updated_by, updated_at, description | ||
| 59 | FROM release_channels WHERE repo_id=? AND name=?`, repoID, name). | ||
| 60 | Scan(&ch.Name, &ch.Release, &ch.ReleaseObject, &ch.UpdatedBy, &at, &ch.Description) | ||
| 61 | if err != nil { | ||
| 62 | if errors.Is(err, sql.ErrNoRows) { | ||
| 63 | return metadata.Channel{}, false, nil | ||
| 64 | } | ||
| 65 | return metadata.Channel{}, false, err | ||
| 66 | } | ||
| 67 | ch.UpdatedAt = time.Unix(at, 0).UTC() | ||
| 68 | return ch, true, nil | ||
| 69 | } | ||
| 70 | |||
| 71 | // ChannelsForTag returns the channel names that currently point at a tag, | ||
| 72 | // sorted. The release page shows them as badges. | ||
| 73 | func (s *Store) ChannelsForTag(repoID, tag string) ([]string, error) { | ||
| 74 | rows, err := s.db.Query( | ||
| 75 | `SELECT name FROM release_channels WHERE repo_id=? AND tag=? ORDER BY name`, | ||
| 76 | repoID, tag) | ||
| 77 | if err != nil { | ||
| 78 | return nil, err | ||
| 79 | } | ||
| 80 | defer rows.Close() | ||
| 81 | var out []string | ||
| 82 | for rows.Next() { | ||
| 83 | var name string | ||
| 84 | if err := rows.Scan(&name); err != nil { | ||
| 85 | return nil, err | ||
| 86 | } | ||
| 87 | out = append(out, name) | ||
| 88 | } | ||
| 89 | return out, rows.Err() | ||
| 90 | } | ||