From 7c7558ce08c3f63493ae1e451ccf90fb1d4834eb Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Tue, 9 Dec 2025 23:28:04 +0900 Subject: [PATCH] lexicons,appview/pulls: replace `patch` with `patchBlob` Change-Id: mkyzmlswtmnkxznqwtmuuytlnotknwxk legacy field name `patch` is preserved (but not used) to support some level of backward compatibility Signed-off-by: Seongmin Lee --- api/tangled/cbor_gen.go | 99 ++++++++++++++++++++++++++++++++-------- api/tangled/repopull.go | 21 +++++---- appview/pulls/pulls.go | 10 ++-- lexicons/pulls/pull.json | 10 +++- 4 files changed, 104 insertions(+), 36 deletions(-) diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go index 93c51a29..5974f133 100644 --- a/api/tangled/cbor_gen.go +++ b/api/tangled/cbor_gen.go @@ -7934,7 +7934,7 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) - fieldCount := 9 + fieldCount := 10 if t.Body == nil { fieldCount-- @@ -7944,6 +7944,10 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { fieldCount-- } + if t.Patch == nil { + fieldCount-- + } + if t.References == nil { fieldCount-- } @@ -8008,26 +8012,35 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { } // t.Patch (string) (string) - if len("patch") > 1000000 { - return xerrors.Errorf("Value in field \"patch\" was too long") - } + if t.Patch != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("patch"))); err != nil { - return err - } - if _, err := cw.WriteString(string("patch")); err != nil { - return err - } + if len("patch") > 1000000 { + return xerrors.Errorf("Value in field \"patch\" was too long") + } - if len(t.Patch) > 1000000 { - return xerrors.Errorf("Value in field t.Patch was too long") - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("patch"))); err != nil { + return err + } + if _, err := cw.WriteString(string("patch")); err != nil { + return err + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Patch))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Patch)); err != nil { - return err + if t.Patch == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Patch) > 1000000 { + return xerrors.Errorf("Value in field t.Patch was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Patch))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Patch)); err != nil { + return err + } + } } // t.Title (string) (string) @@ -8147,6 +8160,22 @@ func (t *RepoPull) MarshalCBOR(w io.Writer) error { return err } + // t.PatchBlob (util.LexBlob) (struct) + if len("patchBlob") > 1000000 { + return xerrors.Errorf("Value in field \"patchBlob\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("patchBlob"))); err != nil { + return err + } + if _, err := cw.WriteString(string("patchBlob")); err != nil { + return err + } + + if err := t.PatchBlob.MarshalCBOR(cw); err != nil { + return err + } + // t.References ([]string) (slice) if t.References != nil { @@ -8262,12 +8291,22 @@ func (t *RepoPull) UnmarshalCBOR(r io.Reader) (err error) { case "patch": { - sval, err := cbg.ReadStringWithMax(cr, 1000000) + 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.Patch = string(sval) + t.Patch = (*string)(&sval) + } } // t.Title (string) (string) case "title": @@ -8371,6 +8410,26 @@ func (t *RepoPull) UnmarshalCBOR(r io.Reader) (err error) { t.CreatedAt = string(sval) } + // t.PatchBlob (util.LexBlob) (struct) + case "patchBlob": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.PatchBlob = new(util.LexBlob) + if err := t.PatchBlob.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.PatchBlob pointer: %w", err) + } + } + + } // t.References ([]string) (slice) case "references": diff --git a/api/tangled/repopull.go b/api/tangled/repopull.go index 3292367b..d923855b 100644 --- a/api/tangled/repopull.go +++ b/api/tangled/repopull.go @@ -17,15 +17,18 @@ func init() { } // // RECORDTYPE: RepoPull type RepoPull struct { - LexiconTypeID string `json:"$type,const=sh.tangled.repo.pull" cborgen:"$type,const=sh.tangled.repo.pull"` - Body *string `json:"body,omitempty" cborgen:"body,omitempty"` - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Mentions []string `json:"mentions,omitempty" cborgen:"mentions,omitempty"` - Patch string `json:"patch" cborgen:"patch"` - References []string `json:"references,omitempty" cborgen:"references,omitempty"` - Source *RepoPull_Source `json:"source,omitempty" cborgen:"source,omitempty"` - Target *RepoPull_Target `json:"target" cborgen:"target"` - Title string `json:"title" cborgen:"title"` + LexiconTypeID string `json:"$type,const=sh.tangled.repo.pull" cborgen:"$type,const=sh.tangled.repo.pull"` + Body *string `json:"body,omitempty" cborgen:"body,omitempty"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Mentions []string `json:"mentions,omitempty" cborgen:"mentions,omitempty"` + // patch: (deprecated) use patchBlob instead + Patch *string `json:"patch,omitempty" cborgen:"patch,omitempty"` + // patchBlob: patch content + PatchBlob *util.LexBlob `json:"patchBlob" cborgen:"patchBlob"` + References []string `json:"references,omitempty" cborgen:"references,omitempty"` + Source *RepoPull_Source `json:"source,omitempty" cborgen:"source,omitempty"` + Target *RepoPull_Target `json:"target" cborgen:"target"` + Title string `json:"title" cborgen:"title"` } // RepoPull_Source is a "source" in the sh.tangled.repo.pull schema. diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 62a234c5..eb835233 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -1258,7 +1258,7 @@ func (s *Pulls) createPullRequest( Repo: string(repo.RepoAt()), Branch: targetBranch, }, - Patch: blob.Blob.Ref.String(), + PatchBlob: blob.Blob, Source: recordPullSource, CreatedAt: time.Now().Format(time.RFC3339), }, @@ -1342,7 +1342,7 @@ func (s *Pulls) createStackedPullRequest( } record := p.AsRecord() - record.Patch = blob.Blob.Ref.String() + record.PatchBlob = blob.Blob writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ RepoApplyWrites_Create: &comatproto.RepoApplyWrites_Create{ Collection: tangled.RepoPullNSID, @@ -1883,7 +1883,7 @@ func (s *Pulls) resubmitPullHelper( return } record := pull.AsRecord() - record.Patch = blob.Blob.Ref.String() + record.PatchBlob = blob.Blob record.CreatedAt = time.Now().Format(time.RFC3339) _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ @@ -2025,7 +2025,7 @@ func (s *Pulls) resubmitStackedPullHelper( return } record := p.AsRecord() - record.Patch = blob.Blob.Ref.String() + record.PatchBlob = blob.Blob writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ RepoApplyWrites_Create: &comatproto.RepoApplyWrites_Create{ Collection: tangled.RepoPullNSID, @@ -2067,7 +2067,7 @@ func (s *Pulls) resubmitStackedPullHelper( return } record := np.AsRecord() - record.Patch = blob.Blob.Ref.String() + record.PatchBlob = blob.Blob writes = append(writes, &comatproto.RepoApplyWrites_Input_Writes_Elem{ RepoApplyWrites_Update: &comatproto.RepoApplyWrites_Update{ Collection: tangled.RepoPullNSID, diff --git a/lexicons/pulls/pull.json b/lexicons/pulls/pull.json index e2527e47..8e5e7c9e 100644 --- a/lexicons/pulls/pull.json +++ b/lexicons/pulls/pull.json @@ -12,7 +12,7 @@ "required": [ "target", "title", - "patch", + "patchBlob", "createdAt" ], "properties": { @@ -27,7 +27,13 @@ "type": "string" }, "patch": { - "type": "string" + "type": "string", + "description": "(deprecated) use patchBlob instead" + }, + "patchBlob": { + "type": "blob", + "accept": "text/x-patch", + "description": "patch content" }, "source": { "type": "ref", -- 2.43.0