diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go index 83efa83d..ab4f2482 100644 --- a/api/tangled/cbor_gen.go +++ b/api/tangled/cbor_gen.go @@ -1799,6 +1799,391 @@ func (t *KnotMember) UnmarshalCBOR(r io.Reader) (err error) { return nil } +func (t *PipelineStatus) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 7 + + if t.Error == nil { + fieldCount-- + } + + if t.ExitCode == nil { + fieldCount-- + } + + if t.FinishedAt == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 1000000 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.pipeline.status"))); err != nil { + return err + } + if _, err := cw.WriteString(string("sh.tangled.pipeline.status")); err != nil { + return err + } + + // t.Error (string) (string) + if t.Error != nil { + + if len("error") > 1000000 { + return xerrors.Errorf("Value in field \"error\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("error"))); err != nil { + return err + } + if _, err := cw.WriteString(string("error")); err != nil { + return err + } + + if t.Error == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Error) > 1000000 { + return xerrors.Errorf("Value in field t.Error was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Error))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Error)); err != nil { + return err + } + } + } + + // t.Status (string) (string) + if len("status") > 1000000 { + return xerrors.Errorf("Value in field \"status\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("status"))); err != nil { + return err + } + if _, err := cw.WriteString(string("status")); err != nil { + return err + } + + if len(t.Status) > 1000000 { + return xerrors.Errorf("Value in field t.Status was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Status))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Status)); err != nil { + return err + } + + // t.ExitCode (int64) (int64) + if t.ExitCode != nil { + + if len("exitCode") > 1000000 { + return xerrors.Errorf("Value in field \"exitCode\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("exitCode"))); err != nil { + return err + } + if _, err := cw.WriteString(string("exitCode")); err != nil { + return err + } + + if t.ExitCode == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if *t.ExitCode >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(*t.ExitCode)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-*t.ExitCode-1)); err != nil { + return err + } + } + } + + } + + // t.StartedAt (string) (string) + if len("startedAt") > 1000000 { + return xerrors.Errorf("Value in field \"startedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("startedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("startedAt")); err != nil { + return err + } + + if len(t.StartedAt) > 1000000 { + return xerrors.Errorf("Value in field t.StartedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.StartedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.StartedAt)); err != nil { + return err + } + + // t.UpdatedAt (string) (string) + if len("updatedAt") > 1000000 { + return xerrors.Errorf("Value in field \"updatedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("updatedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("updatedAt")); err != nil { + return err + } + + if len(t.UpdatedAt) > 1000000 { + return xerrors.Errorf("Value in field t.UpdatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UpdatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.UpdatedAt)); err != nil { + return err + } + + // t.FinishedAt (string) (string) + if t.FinishedAt != nil { + + if len("finishedAt") > 1000000 { + return xerrors.Errorf("Value in field \"finishedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("finishedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("finishedAt")); err != nil { + return err + } + + if t.FinishedAt == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.FinishedAt) > 1000000 { + return xerrors.Errorf("Value in field t.FinishedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.FinishedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.FinishedAt)); err != nil { + return err + } + } + } + return nil +} + +func (t *PipelineStatus) UnmarshalCBOR(r io.Reader) (err error) { + *t = PipelineStatus{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("PipelineStatus: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 10) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Error (string) (string) + case "error": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Error = (*string)(&sval) + } + } + // t.Status (string) (string) + case "status": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.Status = string(sval) + } + // t.ExitCode (int64) (int64) + case "exitCode": + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.ExitCode = (*int64)(&extraI) + } + } + // t.StartedAt (string) (string) + case "startedAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.StartedAt = string(sval) + } + // t.UpdatedAt (string) (string) + case "updatedAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.UpdatedAt = string(sval) + } + // t.FinishedAt (string) (string) + case "finishedAt": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 1000000) + if err != nil { + return err + } + + t.FinishedAt = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} func (t *Pipeline_CloneOpts) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) diff --git a/api/tangled/pipelinestatus.go b/api/tangled/pipelinestatus.go new file mode 100644 index 00000000..edb37a08 --- /dev/null +++ b/api/tangled/pipelinestatus.go @@ -0,0 +1,35 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package tangled + +// schema: sh.tangled.pipeline.status + +import ( + "github.com/bluesky-social/indigo/lex/util" +) + +const ( + PipelineStatusNSID = "sh.tangled.pipeline.status" +) + +func init() { + util.RegisterType("sh.tangled.pipeline.status", &PipelineStatus{}) +} // +// RECORDTYPE: PipelineStatus +type PipelineStatus struct { + LexiconTypeID string `json:"$type,const=sh.tangled.pipeline.status" cborgen:"$type,const=sh.tangled.pipeline.status"` + // error: error message if failed + Error *string `json:"error,omitempty" cborgen:"error,omitempty"` + // exitCode: exit code if failed + ExitCode *int64 `json:"exitCode,omitempty" cborgen:"exitCode,omitempty"` + // finishedAt: pipeline finish time, if finished + FinishedAt *string `json:"finishedAt,omitempty" cborgen:"finishedAt,omitempty"` + // pipeline: pipeline at ref + Pipeline string `json:"pipeline" cborgen:"pipeline"` + // startedAt: pipeline start time + StartedAt string `json:"startedAt" cborgen:"startedAt"` + // status: Pipeline status + Status string `json:"status" cborgen:"status"` + // updatedAt: pipeline last updated time + UpdatedAt string `json:"updatedAt" cborgen:"updatedAt"` +} diff --git a/api/tangled/tangledpipeline.go b/api/tangled/tangledpipeline.go index 11c8b1b2..46a3497e 100644 --- a/api/tangled/tangledpipeline.go +++ b/api/tangled/tangledpipeline.go @@ -85,7 +85,7 @@ type Pipeline_TriggerRepo struct { // Pipeline_Workflow is a "workflow" in the sh.tangled.pipeline schema. type Pipeline_Workflow struct { Clone *Pipeline_CloneOpts `json:"clone" cborgen:"clone"` - Dependencies []Pipeline_Dependencies_Elem `json:"dependencies" cborgen:"dependencies"` + Dependencies []Pipeline_Dependencies_Elem `json:"dependencies" cborgen:"dependencies"` Environment []*Pipeline_Workflow_Environment_Elem `json:"environment" cborgen:"environment"` Name string `json:"name" cborgen:"name"` Steps []*Pipeline_Step `json:"steps" cborgen:"steps"` diff --git a/cmd/gen.go b/cmd/gen.go index 3069f8be..aeeb3bd9 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -22,6 +22,7 @@ func main() { tangled.GitRefUpdate{}, tangled.GraphFollow{}, tangled.KnotMember{}, + tangled.PipelineStatus{}, tangled.Pipeline_CloneOpts{}, tangled.Pipeline_Dependencies_Elem{}, tangled.Pipeline_ManualTriggerData_Inputs_Elem{}, diff --git a/lexicons/pipeline/status.json b/lexicons/pipeline/status.json new file mode 100644 index 00000000..56f364f0 --- /dev/null +++ b/lexicons/pipeline/status.json @@ -0,0 +1,58 @@ +{ + "lexicon": 1, + "id": "sh.tangled.pipeline.status", + "needsCbor": true, + "needsType": true, + "defs": { + "main": { + "type": "record", + "key": "tid", + "record": { + "type": "object", + "required": ["pipeline", "status", "startedAt", "updatedAt"], + "properties": { + "pipeline": { + "type": "string", + "format": "at-uri", + "description": "pipeline at ref" + }, + "status": { + "type": "string", + "description": "Pipeline status", + "enum": [ + "pending", + "running", + "failed", + "timeout", + "cancelled", + "success" + ] + }, + "error": { + "type": "string", + "description": "error message if failed" + }, + "exitCode": { + "type": "integer", + "description": "exit code if failed" + }, + "startedAt": { + "type": "string", + "format": "datetime", + "description": "pipeline start time" + }, + "updatedAt": { + "type": "string", + "format": "datetime", + "description": "pipeline last updated time" + }, + "finishedAt": { + "type": "string", + "format": "datetime", + "description": "pipeline finish time, if finished" + } + } + } + } + } +}