Files
alan 06bf580154 Archive pipelines: hide unused ones while keeping their history
archived_at on pipelines (migrated in place). archive_pipeline and
unarchive_pipeline by id or name with an expected-version guard;
list_pipelines hides archived unless include_archived. Archived
pipelines refuse runs, retries, new versions and name reuse, and
cannot be archived while an enabled schedule points at them.
CLI archive/unarchive and list --archived/--all, docs and skill note.
2026-11-04 23:25:55 +00:00

53 lines
1.5 KiB
Go

package cli
import (
"fmt"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// archive implements `pipelines archive` and `pipelines unarchive`. The
// server keeps every version and run; the latest version is the guard.
func (a App) archive(command string, pos []string, o *options, call callFunc, resolve resolveFunc) error {
if len(pos) != 1 {
return fmt.Errorf("%s requires one pipeline name or ID; use pipelines help %s", command, command)
}
p, err := resolve(pos[0])
if err != nil {
return err
}
request := protocol.Message{Type: protocol.UnarchivePipeline, PipelineID: p.ID, ExpectedVersion: p.Version}
if command == "archive" {
request.Type = protocol.ArchivePipeline
if err := a.confirmAction("Archive "+p.Name+"? It leaves the pipeline list and cannot start runs; its versions, runs and artifacts are kept and it can be unarchived.", o.yes); err != nil {
return err
}
}
r, err := call(request)
if err != nil {
return err
}
if r.Detail == nil {
return fmt.Errorf("server did not return the pipeline; update pipelines-server")
}
if o.json {
return a.output(r.Detail.PipelineSummary)
}
if command == "archive" {
fmt.Fprintf(a.Out, "Archived %s (history kept; pipelines unarchive %d restores it)\n", r.Detail.Name, r.Detail.ID)
} else {
fmt.Fprintf(a.Out, "Unarchived %s\n", r.Detail.Name)
}
return nil
}
func archivedOnly(items []protocol.PipelineSummary) []protocol.PipelineSummary {
kept := []protocol.PipelineSummary{}
for _, p := range items {
if p.ArchivedAt != "" {
kept = append(kept, p)
}
}
return kept
}