Monorepo for Tangled tangled.org

lexicons: pulls: put target repo and branch together in their own object

Signed-off-by: nelind <nel.n.lindberg@gmail.com>

Changed files
+206 -80
api
appview
db
pulls
cmd
lexicons
pulls
+166 -64
api/tangled/cbor_gen.go
··· 6522 6522 6523 6523 return nil 6524 6524 } 6525 + func (t *RepoPull_Target) MarshalCBOR(w io.Writer) error { 6526 + if t == nil { 6527 + _, err := w.Write(cbg.CborNull) 6528 + return err 6529 + } 6530 + 6531 + cw := cbg.NewCborWriter(w) 6532 + 6533 + if _, err := cw.Write([]byte{162}); err != nil { 6534 + return err 6535 + } 6536 + 6537 + // t.Repo (string) (string) 6538 + if len("repo") > 1000000 { 6539 + return xerrors.Errorf("Value in field \"repo\" was too long") 6540 + } 6541 + 6542 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repo"))); err != nil { 6543 + return err 6544 + } 6545 + if _, err := cw.WriteString(string("repo")); err != nil { 6546 + return err 6547 + } 6548 + 6549 + if len(t.Repo) > 1000000 { 6550 + return xerrors.Errorf("Value in field t.Repo was too long") 6551 + } 6552 + 6553 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repo))); err != nil { 6554 + return err 6555 + } 6556 + if _, err := cw.WriteString(string(t.Repo)); err != nil { 6557 + return err 6558 + } 6559 + 6560 + // t.Branch (string) (string) 6561 + if len("branch") > 1000000 { 6562 + return xerrors.Errorf("Value in field \"branch\" was too long") 6563 + } 6564 + 6565 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("branch"))); err != nil { 6566 + return err 6567 + } 6568 + if _, err := cw.WriteString(string("branch")); err != nil { 6569 + return err 6570 + } 6571 + 6572 + if len(t.Branch) > 1000000 { 6573 + return xerrors.Errorf("Value in field t.Branch was too long") 6574 + } 6575 + 6576 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Branch))); err != nil { 6577 + return err 6578 + } 6579 + if _, err := cw.WriteString(string(t.Branch)); err != nil { 6580 + return err 6581 + } 6582 + return nil 6583 + } 6584 + 6585 + func (t *RepoPull_Target) UnmarshalCBOR(r io.Reader) (err error) { 6586 + *t = RepoPull_Target{} 6587 + 6588 + cr := cbg.NewCborReader(r) 6589 + 6590 + maj, extra, err := cr.ReadHeader() 6591 + if err != nil { 6592 + return err 6593 + } 6594 + defer func() { 6595 + if err == io.EOF { 6596 + err = io.ErrUnexpectedEOF 6597 + } 6598 + }() 6599 + 6600 + if maj != cbg.MajMap { 6601 + return fmt.Errorf("cbor input should be of type map") 6602 + } 6603 + 6604 + if extra > cbg.MaxLength { 6605 + return fmt.Errorf("RepoPull_Target: map struct too large (%d)", extra) 6606 + } 6607 + 6608 + n := extra 6609 + 6610 + nameBuf := make([]byte, 6) 6611 + for i := uint64(0); i < n; i++ { 6612 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) 6613 + if err != nil { 6614 + return err 6615 + } 6616 + 6617 + if !ok { 6618 + // Field doesn't exist on this type, so ignore it 6619 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 6620 + return err 6621 + } 6622 + continue 6623 + } 6624 + 6625 + switch string(nameBuf[:nameLen]) { 6626 + // t.Repo (string) (string) 6627 + case "repo": 6628 + 6629 + { 6630 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 6631 + if err != nil { 6632 + return err 6633 + } 6634 + 6635 + t.Repo = string(sval) 6636 + } 6637 + // t.Branch (string) (string) 6638 + case "branch": 6639 + 6640 + { 6641 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 6642 + if err != nil { 6643 + return err 6644 + } 6645 + 6646 + t.Branch = string(sval) 6647 + } 6648 + 6649 + default: 6650 + // Field doesn't exist on this type, so ignore it 6651 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 6652 + return err 6653 + } 6654 + } 6655 + } 6656 + 6657 + return nil 6658 + } 6525 6659 func (t *RepoPull) MarshalCBOR(w io.Writer) error { 6526 6660 if t == nil { 6527 6661 _, err := w.Write(cbg.CborNull) ··· 6529 6663 } 6530 6664 6531 6665 cw := cbg.NewCborWriter(w) 6532 - fieldCount := 8 6666 + fieldCount := 7 6533 6667 6534 6668 if t.Body == nil { 6535 6669 fieldCount-- ··· 6659 6793 } 6660 6794 } 6661 6795 6662 - // t.CreatedAt (string) (string) 6663 - if len("createdAt") > 1000000 { 6664 - return xerrors.Errorf("Value in field \"createdAt\" was too long") 6796 + // t.Target (tangled.RepoPull_Target) (struct) 6797 + if len("target") > 1000000 { 6798 + return xerrors.Errorf("Value in field \"target\" was too long") 6665 6799 } 6666 6800 6667 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 6801 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("target"))); err != nil { 6668 6802 return err 6669 6803 } 6670 - if _, err := cw.WriteString(string("createdAt")); err != nil { 6804 + if _, err := cw.WriteString(string("target")); err != nil { 6671 6805 return err 6672 6806 } 6673 6807 6674 - if len(t.CreatedAt) > 1000000 { 6675 - return xerrors.Errorf("Value in field t.CreatedAt was too long") 6676 - } 6677 - 6678 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 6679 - return err 6680 - } 6681 - if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 6808 + if err := t.Target.MarshalCBOR(cw); err != nil { 6682 6809 return err 6683 6810 } 6684 6811 6685 - // t.TargetRepo (string) (string) 6686 - if len("targetRepo") > 1000000 { 6687 - return xerrors.Errorf("Value in field \"targetRepo\" was too long") 6812 + // t.CreatedAt (string) (string) 6813 + if len("createdAt") > 1000000 { 6814 + return xerrors.Errorf("Value in field \"createdAt\" was too long") 6688 6815 } 6689 6816 6690 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("targetRepo"))); err != nil { 6817 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 6691 6818 return err 6692 6819 } 6693 - if _, err := cw.WriteString(string("targetRepo")); err != nil { 6820 + if _, err := cw.WriteString(string("createdAt")); err != nil { 6694 6821 return err 6695 6822 } 6696 6823 6697 - if len(t.TargetRepo) > 1000000 { 6698 - return xerrors.Errorf("Value in field t.TargetRepo was too long") 6824 + if len(t.CreatedAt) > 1000000 { 6825 + return xerrors.Errorf("Value in field t.CreatedAt was too long") 6699 6826 } 6700 6827 6701 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.TargetRepo))); err != nil { 6828 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 6702 6829 return err 6703 6830 } 6704 - if _, err := cw.WriteString(string(t.TargetRepo)); err != nil { 6705 - return err 6706 - } 6707 - 6708 - // t.TargetBranch (string) (string) 6709 - if len("targetBranch") > 1000000 { 6710 - return xerrors.Errorf("Value in field \"targetBranch\" was too long") 6711 - } 6712 - 6713 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("targetBranch"))); err != nil { 6714 - return err 6715 - } 6716 - if _, err := cw.WriteString(string("targetBranch")); err != nil { 6717 - return err 6718 - } 6719 - 6720 - if len(t.TargetBranch) > 1000000 { 6721 - return xerrors.Errorf("Value in field t.TargetBranch was too long") 6722 - } 6723 - 6724 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.TargetBranch))); err != nil { 6725 - return err 6726 - } 6727 - if _, err := cw.WriteString(string(t.TargetBranch)); err != nil { 6831 + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 6728 6832 return err 6729 6833 } 6730 6834 return nil ··· 6755 6859 6756 6860 n := extra 6757 6861 6758 - nameBuf := make([]byte, 12) 6862 + nameBuf := make([]byte, 9) 6759 6863 for i := uint64(0); i < n; i++ { 6760 6864 nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000) 6761 6865 if err != nil { ··· 6845 6949 } 6846 6950 6847 6951 } 6848 - // t.CreatedAt (string) (string) 6849 - case "createdAt": 6952 + // t.Target (tangled.RepoPull_Target) (struct) 6953 + case "target": 6850 6954 6851 6955 { 6852 - sval, err := cbg.ReadStringWithMax(cr, 1000000) 6853 - if err != nil { 6854 - return err 6855 - } 6856 6956 6857 - t.CreatedAt = string(sval) 6858 - } 6859 - // t.TargetRepo (string) (string) 6860 - case "targetRepo": 6861 - 6862 - { 6863 - sval, err := cbg.ReadStringWithMax(cr, 1000000) 6957 + b, err := cr.ReadByte() 6864 6958 if err != nil { 6865 6959 return err 6866 6960 } 6961 + if b != cbg.CborNull[0] { 6962 + if err := cr.UnreadByte(); err != nil { 6963 + return err 6964 + } 6965 + t.Target = new(RepoPull_Target) 6966 + if err := t.Target.UnmarshalCBOR(cr); err != nil { 6967 + return xerrors.Errorf("unmarshaling t.Target pointer: %w", err) 6968 + } 6969 + } 6867 6970 6868 - t.TargetRepo = string(sval) 6869 6971 } 6870 - // t.TargetBranch (string) (string) 6871 - case "targetBranch": 6972 + // t.CreatedAt (string) (string) 6973 + case "createdAt": 6872 6974 6873 6975 { 6874 6976 sval, err := cbg.ReadStringWithMax(cr, 1000000) ··· 6876 6978 return err 6877 6979 } 6878 6980 6879 - t.TargetBranch = string(sval) 6981 + t.CreatedAt = string(sval) 6880 6982 } 6881 6983 6882 6984 default:
+7 -2
api/tangled/repopull.go
··· 22 22 CreatedAt string `json:"createdAt" cborgen:"createdAt"` 23 23 Patch string `json:"patch" cborgen:"patch"` 24 24 Source *RepoPull_Source `json:"source,omitempty" cborgen:"source,omitempty"` 25 - TargetBranch string `json:"targetBranch" cborgen:"targetBranch"` 26 - TargetRepo string `json:"targetRepo" cborgen:"targetRepo"` 25 + Target *RepoPull_Target `json:"target" cborgen:"target"` 27 26 Title string `json:"title" cborgen:"title"` 28 27 } 29 28 ··· 33 32 Repo *string `json:"repo,omitempty" cborgen:"repo,omitempty"` 34 33 Sha string `json:"sha" cborgen:"sha"` 35 34 } 35 + 36 + // RepoPull_Target is a "target" in the sh.tangled.repo.pull schema. 37 + type RepoPull_Target struct { 38 + Branch string `json:"branch" cborgen:"branch"` 39 + Repo string `json:"repo" cborgen:"repo"` 40 + }
+4 -2
appview/db/pulls.go
··· 94 94 Title: p.Title, 95 95 Body: &p.Body, 96 96 CreatedAt: p.Created.Format(time.RFC3339), 97 - TargetRepo: p.RepoAt.String(), 98 - TargetBranch: p.TargetBranch, 97 + Target: &tangled.RepoPull_Target{ 98 + Repo: p.RepoAt.String(), 99 + Branch: p.TargetBranch, 100 + }, 99 101 Patch: p.LatestPatch(), 100 102 Source: source, 101 103 }
+8 -4
appview/pulls/pulls.go
··· 1035 1035 Record: &lexutil.LexiconTypeDecoder{ 1036 1036 Val: &tangled.RepoPull{ 1037 1037 Title: title, 1038 - TargetRepo: string(f.RepoAt()), 1039 - TargetBranch: targetBranch, 1038 + Target: &tangled.RepoPull_Target{ 1039 + Repo: string(f.RepoAt()), 1040 + Branch: targetBranch, 1041 + }, 1040 1042 Patch: patch, 1041 1043 Source: recordPullSource, 1042 1044 }, ··· 1605 1607 Record: &lexutil.LexiconTypeDecoder{ 1606 1608 Val: &tangled.RepoPull{ 1607 1609 Title: pull.Title, 1608 - TargetRepo: string(f.RepoAt()), 1609 - TargetBranch: pull.TargetBranch, 1610 + Target: &tangled.RepoPull_Target{ 1611 + Repo: string(f.RepoAt()), 1612 + Branch: pull.TargetBranch, 1613 + }, 1610 1614 Patch: patch, // new patch 1611 1615 Source: recordPullSource, 1612 1616 },
+1
cmd/gen.go
··· 46 46 tangled.RepoPull{}, 47 47 tangled.RepoPullComment{}, 48 48 tangled.RepoPull_Source{}, 49 + tangled.RepoPull_Target{}, 49 50 tangled.RepoPullStatus{}, 50 51 tangled.Spindle{}, 51 52 tangled.SpindleMember{},
+20 -8
lexicons/pulls/pull.json
··· 10 10 "record": { 11 11 "type": "object", 12 12 "required": [ 13 - "targetRepo", 14 - "targetBranch", 13 + "target", 15 14 "title", 16 15 "patch", 17 16 "createdAt" 18 17 ], 19 18 "properties": { 20 - "targetRepo": { 21 - "type": "string", 22 - "format": "at-uri" 23 - }, 24 - "targetBranch": { 25 - "type": "string" 19 + "target": { 20 + "type": "ref", 21 + "ref": "#target" 26 22 }, 27 23 "title": { 28 24 "type": "string" ··· 41 37 "type": "string", 42 38 "format": "datetime" 43 39 } 40 + } 41 + } 42 + }, 43 + "target": { 44 + "type": "object", 45 + "required": [ 46 + "repo", 47 + "branch" 48 + ], 49 + "properties": { 50 + "repo": { 51 + "type": "string", 52 + "format": "at-uri" 53 + }, 54 + "branch": { 55 + "type": "string" 44 56 } 45 57 } 46 58 },