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.
| 1 | package client |
| 2 | |
| 3 | // Release channels over the instance's SSH verb. |
| 4 | // |
| 5 | // A channel is server-side state, not a metadata file: the CLI asks the instance |
| 6 | // it pushes to. The server resolves the repository role, validates the annotated |
| 7 | // tag, writes the channel database, and records the move in the audit log. |
| 8 | |
| 9 | import ( |
| 10 | "encoding/json" |
| 11 | "fmt" |
| 12 | "strings" |
| 13 | "time" |
| 14 | ) |
| 15 | |
| 16 | // Channel is one server-side release alias. |
| 17 | type Channel struct { |
| 18 | Name string `json:"name"` |
| 19 | Release string `json:"release"` |
| 20 | ReleaseObject string `json:"release_object"` |
| 21 | UpdatedBy string `json:"updated_by"` |
| 22 | UpdatedAt time.Time `json:"updated_at"` |
| 23 | Description string `json:"description"` |
| 24 | Dangling bool `json:"dangling"` |
| 25 | } |
| 26 | |
| 27 | // channelCommand resolves the instance and repository for a channel verb and |
| 28 | // builds the command line the server parses. |
| 29 | func channelCommand(gitDir, remote, op string, extra ...string) (host, port, command string, err error) { |
| 30 | if strings.TrimSpace(remote) == "" { |
| 31 | remote = "origin" |
| 32 | } |
| 33 | host, port, path, err := SSHTarget(gitDir, remote) |
| 34 | if err != nil { |
| 35 | return "", "", "", err |
| 36 | } |
| 37 | if RepoNameFromPath(path) == "" { |
| 38 | return "", "", "", fmt.Errorf("%s does not name a repository", remote) |
| 39 | } |
| 40 | args := append([]string{"vole-channel", op, path}, extra...) |
| 41 | quoted := make([]string, len(args)) |
| 42 | for i, arg := range args { |
| 43 | quoted[i] = quoteSSHArg(arg) |
| 44 | } |
| 45 | return host, port, strings.Join(quoted, " "), nil |
| 46 | } |
| 47 | |
| 48 | // SetChannel points a channel at an annotated tag. The description is sent on |
| 49 | // stdin so it never becomes part of a command line or the audit log. |
| 50 | func SetChannel(gitDir, remote, name, tag, description string) (string, error) { |
| 51 | host, port, command, err := channelCommand(gitDir, remote, "set", name, tag) |
| 52 | if err != nil { |
| 53 | return "", err |
| 54 | } |
| 55 | out, err := runSSH(host, port, command, strings.NewReader(description)) |
| 56 | if err != nil { |
| 57 | return "", err |
| 58 | } |
| 59 | return strings.TrimSpace(out), nil |
| 60 | } |
| 61 | |
| 62 | // ClearChannel removes a channel pointer. |
| 63 | func ClearChannel(gitDir, remote, name string) (string, error) { |
| 64 | host, port, command, err := channelCommand(gitDir, remote, "clear", name) |
| 65 | if err != nil { |
| 66 | return "", err |
| 67 | } |
| 68 | out, err := runSSH(host, port, command, nil) |
| 69 | if err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | return strings.TrimSpace(out), nil |
| 73 | } |
| 74 | |
| 75 | // ListChannels reads the repository's channels. The server answers JSON so a |
| 76 | // description containing a tab or newline survives the wire. |
| 77 | func ListChannels(gitDir, remote string) ([]Channel, error) { |
| 78 | host, port, command, err := channelCommand(gitDir, remote, "list") |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | out, err := runSSH(host, port, command, nil) |
| 83 | if err != nil { |
| 84 | return nil, err |
| 85 | } |
| 86 | var list []Channel |
| 87 | if strings.TrimSpace(out) == "" { |
| 88 | return list, nil |
| 89 | } |
| 90 | if err := json.Unmarshal([]byte(out), &list); err != nil { |
| 91 | return nil, fmt.Errorf("read channels: %w", err) |
| 92 | } |
| 93 | return list, nil |
| 94 | } |
| 95 |