From 5c6eb63a90a0007229056fd307938d19cffd44c3 Mon Sep 17 00:00:00 2001 From: Wilhelm Berggren Date: Sun, 26 Jul 2026 21:01:04 +0200 Subject: [PATCH] lexicons: add blobs field to `repo.{issue,pull}` Ideally both `body` and `blobs` should be wrapped as single `body` field with `sh.tangled.markup.markdown` type like `sh.tangled.feed.comment` records, but that breaking change is deferred for later `org.tangled.*` migration. Signed-off-by: Wilhelm Berggren Signed-off-by: Seongmin Lee --- api/tangled/cbor_gen.go | 168 +++++++++++++++++++++++++++++++++++++- api/tangled/repoissue.go | 15 ++-- api/tangled/repopull.go | 1 + lexicons/issue/issue.json | 8 ++ lexicons/pulls/pull.json | 8 ++ 5 files changed, 191 insertions(+), 9 deletions(-) diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go index 36312457..eed70520 100644 --- a/api/tangled/cbor_gen.go +++ b/api/tangled/cbor_gen.go @@ -11386,7 +11386,11 @@ func (t *RepoIssue) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) - fieldCount := 7 + fieldCount := 8 + + if t.Blobs == nil { + fieldCount-- + } if t.Body == nil { fieldCount-- @@ -11478,6 +11482,35 @@ func (t *RepoIssue) MarshalCBOR(w io.Writer) error { return err } + // t.Blobs ([]*util.LexBlob) (slice) + if t.Blobs != nil { + + if len("blobs") > 1000000 { + return xerrors.Errorf("Value in field \"blobs\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blobs"))); err != nil { + return err + } + if _, err := cw.WriteString(string("blobs")); err != nil { + return err + } + + if len(t.Blobs) > 8192 { + return xerrors.Errorf("Slice value in field t.Blobs was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blobs))); err != nil { + return err + } + for _, v := range t.Blobs { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + } + // t.Title (string) (string) if len("title") > 1000000 { return xerrors.Errorf("Value in field \"title\" was too long") @@ -11682,6 +11715,55 @@ func (t *RepoIssue) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } + // t.Blobs ([]*util.LexBlob) (slice) + case "blobs": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Blobs: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Blobs = make([]*util.LexBlob, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Blobs[i] = new(util.LexBlob) + if err := t.Blobs[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Blobs[i] pointer: %w", err) + } + } + + } + + } + } // t.Title (string) (string) case "title": @@ -12416,7 +12498,11 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) - fieldCount := 10 + fieldCount := 11 + + if t.Blobs == nil { + fieldCount-- + } if t.Body == nil { fieldCount-- @@ -12493,6 +12579,35 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { return err } + // t.Blobs ([]*util.LexBlob) (slice) + if t.Blobs != nil { + + if len("blobs") > 1000000 { + return xerrors.Errorf("Value in field \"blobs\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("blobs"))); err != nil { + return err + } + if _, err := cw.WriteString(string("blobs")); err != nil { + return err + } + + if len(t.Blobs) > 8192 { + return xerrors.Errorf("Slice value in field t.Blobs was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blobs))); err != nil { + return err + } + for _, v := range t.Blobs { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + } + // t.Title (string) (string) if len("title") > 1000000 { return xerrors.Errorf("Value in field \"title\" was too long") @@ -12779,6 +12894,55 @@ func (t *RepoPull) UnmarshalCBOR(r io.Reader) (err error) { t.LexiconTypeID = string(sval) } + // t.Blobs ([]*util.LexBlob) (slice) + case "blobs": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Blobs: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Blobs = make([]*util.LexBlob, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Blobs[i] = new(util.LexBlob) + if err := t.Blobs[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Blobs[i] pointer: %w", err) + } + } + + } + + } + } // t.Title (string) (string) case "title": diff --git a/api/tangled/repoissue.go b/api/tangled/repoissue.go index 3d02d83d..f2279f2b 100644 --- a/api/tangled/repoissue.go +++ b/api/tangled/repoissue.go @@ -17,11 +17,12 @@ func init() { } // // RECORDTYPE: RepoIssue type RepoIssue struct { - LexiconTypeID string `json:"$type,const=sh.tangled.repo.issue" cborgen:"$type,const=sh.tangled.repo.issue"` - Body *string `json:"body,omitempty" cborgen:"body,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Mentions []string `json:"mentions,omitempty" cborgen:"mentions,omitempty"` - References []string `json:"references,omitempty" cborgen:"references,omitempty"` - Repo string `json:"repo" cborgen:"repo"` - Title string `json:"title" cborgen:"title"` + LexiconTypeID string `json:"$type,const=sh.tangled.repo.issue" cborgen:"$type,const=sh.tangled.repo.issue"` + Blobs []*util.LexBlob `json:"blobs,omitempty" cborgen:"blobs,omitempty"` + Body *string `json:"body,omitempty" cborgen:"body,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Mentions []string `json:"mentions,omitempty" cborgen:"mentions,omitempty"` + References []string `json:"references,omitempty" cborgen:"references,omitempty"` + Repo string `json:"repo" cborgen:"repo"` + Title string `json:"title" cborgen:"title"` } diff --git a/api/tangled/repopull.go b/api/tangled/repopull.go index 7e878f3a..e2106ff5 100644 --- a/api/tangled/repopull.go +++ b/api/tangled/repopull.go @@ -18,6 +18,7 @@ func init() { // RECORDTYPE: RepoPull type RepoPull struct { LexiconTypeID string `json:"$type,const=sh.tangled.repo.pull" cborgen:"$type,const=sh.tangled.repo.pull"` + Blobs []*util.LexBlob `json:"blobs,omitempty" cborgen:"blobs,omitempty"` Body *string `json:"body,omitempty" cborgen:"body,omitempty"` CreatedAt string `json:"createdAt" cborgen:"createdAt"` DependentOn *string `json:"dependentOn,omitempty" cborgen:"dependentOn,omitempty"` diff --git a/lexicons/issue/issue.json b/lexicons/issue/issue.json index cd484feb..e1800649 100644 --- a/lexicons/issue/issue.json +++ b/lexicons/issue/issue.json @@ -38,6 +38,14 @@ "type": "string", "format": "at-uri" } + }, + "blobs": { + "type": "array", + "items": { + "type": "blob", + "accept": ["image/*"], + "maxSize": 1000000 + } } } } diff --git a/lexicons/pulls/pull.json b/lexicons/pulls/pull.json index e4934808..47393a03 100644 --- a/lexicons/pulls/pull.json +++ b/lexicons/pulls/pull.json @@ -58,6 +58,14 @@ "dependentOn": { "type": "string", "format": "at-uri" + }, + "blobs": { + "type": "array", + "items": { + "type": "blob", + "accept": ["image/*"], + "maxSize": 1000000 + } } } } -- 2.51.2