From 3798a8bd004eef8b23640826db29592ebd485cbb Mon Sep 17 00:00:00 2001 From: dawn Date: Mon, 21 Sep 2026 15:08:08 +0300 Subject: [PATCH] api/tangled,knotmirror/xrpc,spindle/{engines/microvm,xrpc},web: lexgen && fmt Signed-off-by: dawn --- api/tangled/actorprofile.go | 6 +- api/tangled/cbor_gen.go | 64 ++++++++++++++- api/tangled/embedcommit.go | 10 +++ api/tangled/feeddefs.go | 80 +++++++++++++++++++ api/tangled/feedlistComments.go | 6 +- api/tangled/gitdefs.go | 7 ++ api/tangled/temp2listCommits.go | 7 +- knotmirror/xrpc/xrpc.go | 10 +-- spindle/engines/microvm/substituter_proxy.go | 2 +- spindle/xrpc/org_tangled_secret_common.go | 2 +- .../lexicons/types/sh/tangled/ci/pipeline.ts | 1 + .../types/sh/tangled/ci/queryPipelines.ts | 7 +- .../lexicons/types/sh/tangled/ci/trigger.ts | 25 ++++++ .../api/lexicons/types/sh/tangled/pipeline.ts | 38 ++++++++- .../types/sh/tangled/repo/addSecret.ts | 4 +- 15 files changed, 252 insertions(+), 17 deletions(-) create mode 100644 api/tangled/feeddefs.go diff --git a/api/tangled/actorprofile.go b/api/tangled/actorprofile.go index c6c46939b..91a488f80 100644 --- a/api/tangled/actorprofile.go +++ b/api/tangled/actorprofile.go @@ -23,8 +23,10 @@ type ActorProfile struct { // bluesky: Include link to this account on Bluesky. Bluesky bool `json:"bluesky" cborgen:"bluesky"` // description: Free-form profile description text. - Description *string `json:"description,omitempty" cborgen:"description,omitempty"` - Links []string `json:"links,omitempty" cborgen:"links,omitempty"` + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + // isOrganization: Temporary flag indicating that this profile belongs to an organization. + IsOrganization *bool `json:"isOrganization,omitempty" cborgen:"isOrganization,omitempty"` + Links []string `json:"links,omitempty" cborgen:"links,omitempty"` // location: Free-form location text. Location *string `json:"location,omitempty" cborgen:"location,omitempty"` // pinnedRepositories: Pinned repositories. Values are repo DIDs for repos that have them, or AT-URIs for legacy repos. diff --git a/api/tangled/cbor_gen.go b/api/tangled/cbor_gen.go index 426e243a8..cf831e056 100644 --- a/api/tangled/cbor_gen.go +++ b/api/tangled/cbor_gen.go @@ -27,7 +27,7 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) - fieldCount := 10 + fieldCount := 11 if t.Avatar == nil { fieldCount-- @@ -37,6 +37,10 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { fieldCount-- } + if t.IsOrganization == nil { + fieldCount-- + } + if t.Links == nil { fieldCount-- } @@ -287,6 +291,31 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { } } + // t.IsOrganization (bool) (bool) + if t.IsOrganization != nil { + + if len("isOrganization") > 1000000 { + return xerrors.Errorf("Value in field \"isOrganization\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("isOrganization"))); err != nil { + return err + } + if _, err := cw.WriteString(string("isOrganization")); err != nil { + return err + } + + if t.IsOrganization == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteBool(w, *t.IsOrganization); err != nil { + return err + } + } + } + // t.PreferredHandle (string) (string) if t.PreferredHandle != nil { @@ -590,6 +619,39 @@ func (t *ActorProfile) UnmarshalCBOR(r io.Reader) (err error) { t.Description = (*string)(&sval) } } + // t.IsOrganization (bool) (bool) + case "isOrganization": + + { + 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 + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + + var val bool + switch extra { + case 20: + val = false + case 21: + val = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + t.IsOrganization = &val + } + } // t.PreferredHandle (string) (string) case "preferredHandle": diff --git a/api/tangled/embedcommit.go b/api/tangled/embedcommit.go index a7b160dc1..9d35fdab4 100644 --- a/api/tangled/embedcommit.go +++ b/api/tangled/embedcommit.go @@ -81,3 +81,13 @@ func (t *EmbedCommit_Commit) UnmarshalCBOR(r io.Reader) error { return nil } } + +// EmbedCommit_View is a "view" in the sh.tangled.embed.commit schema. +// +// RECORDTYPE: EmbedCommit_View +type EmbedCommit_View struct { + LexiconTypeID string `json:"$type,const=sh.tangled.embed.commit#view" cborgen:"$type,const=sh.tangled.embed.commit#view"` + Change *string `json:"change,omitempty" cborgen:"change,omitempty"` + Commit string `json:"commit" cborgen:"commit"` + Repo string `json:"repo" cborgen:"repo"` +} diff --git a/api/tangled/feeddefs.go b/api/tangled/feeddefs.go new file mode 100644 index 000000000..88fae6ea5 --- /dev/null +++ b/api/tangled/feeddefs.go @@ -0,0 +1,80 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package tangled + +// schema: sh.tangled.feed.defs + +import ( + "encoding/json" + "fmt" + + comatprototypes "github.com/bluesky-social/indigo/api/atproto" + "github.com/bluesky-social/indigo/lex/util" +) + +const () + +// FeedDefs_CommentView is a "commentView" in the sh.tangled.feed.defs schema. +type FeedDefs_CommentView struct { + Body *FeedDefs_CommentView_Body `json:"body" cborgen:"body"` + Cid string `json:"cid" cborgen:"cid"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Embed *FeedDefs_CommentView_Embed `json:"embed,omitempty" cborgen:"embed,omitempty"` + ReplyTo *comatprototypes.RepoStrongRef `json:"replyTo,omitempty" cborgen:"replyTo,omitempty"` + Subject *comatprototypes.RepoStrongRef `json:"subject" cborgen:"subject"` + Uri string `json:"uri" cborgen:"uri"` +} + +type FeedDefs_CommentView_Body struct { + MarkupMarkdown *MarkupMarkdown +} + +func (t *FeedDefs_CommentView_Body) MarshalJSON() ([]byte, error) { + if t.MarkupMarkdown != nil { + t.MarkupMarkdown.LexiconTypeID = "sh.tangled.markup.markdown" + return json.Marshal(t.MarkupMarkdown) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_CommentView_Body) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "sh.tangled.markup.markdown": + t.MarkupMarkdown = new(MarkupMarkdown) + return json.Unmarshal(b, t.MarkupMarkdown) + + default: + return nil + } +} + +type FeedDefs_CommentView_Embed struct { + EmbedCommit_View *EmbedCommit_View +} + +func (t *FeedDefs_CommentView_Embed) MarshalJSON() ([]byte, error) { + if t.EmbedCommit_View != nil { + t.EmbedCommit_View.LexiconTypeID = "sh.tangled.embed.commit#view" + return json.Marshal(t.EmbedCommit_View) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *FeedDefs_CommentView_Embed) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "sh.tangled.embed.commit#view": + t.EmbedCommit_View = new(EmbedCommit_View) + return json.Unmarshal(b, t.EmbedCommit_View) + + default: + return nil + } +} diff --git a/api/tangled/feedlistComments.go b/api/tangled/feedlistComments.go index 568792adb..001792606 100644 --- a/api/tangled/feedlistComments.go +++ b/api/tangled/feedlistComments.go @@ -15,6 +15,8 @@ const ( ) // FeedListComments_ListItem is a "listItem" in the sh.tangled.feed.listComments schema. +// +// DEPRECATED: only sh.tangled.feed.listCommentsBy still answers with this shape. Use #commentView. type FeedListComments_ListItem struct { Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"` Uri string `json:"uri" cborgen:"uri"` @@ -24,8 +26,8 @@ type FeedListComments_ListItem struct { // FeedListComments_Output is the output of a sh.tangled.feed.listComments call. type FeedListComments_Output struct { - Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` - Items []*FeedListComments_ListItem `json:"items" cborgen:"items"` + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Items []*FeedDefs_CommentView `json:"items" cborgen:"items"` // total: Total items in the full list; omitted for filtered or merged views Total *int64 `json:"total,omitempty" cborgen:"total,omitempty"` } diff --git a/api/tangled/gitdefs.go b/api/tangled/gitdefs.go index 70f06012a..a85a5b8ff 100644 --- a/api/tangled/gitdefs.go +++ b/api/tangled/gitdefs.go @@ -35,6 +35,13 @@ type GitDefs_DiffSrc struct { Size int64 `json:"size" cborgen:"size"` } +// GitDefs_DiffStat is a "diffStat" in the sh.tangled.git.defs schema. +type GitDefs_DiffStat struct { + Deletions int64 `json:"deletions" cborgen:"deletions"` + FilesChanged int64 `json:"filesChanged" cborgen:"filesChanged"` + Insertions int64 `json:"insertions" cborgen:"insertions"` +} + // GitDefs_FileDiff is a "fileDiff" in the sh.tangled.git.defs schema. type GitDefs_FileDiff struct { // hasByteChanges: Byte count per side, present only when the two sides differ diff --git a/api/tangled/temp2listCommits.go b/api/tangled/temp2listCommits.go index c95bd6c9b..e9e95408b 100644 --- a/api/tangled/temp2listCommits.go +++ b/api/tangled/temp2listCommits.go @@ -22,6 +22,7 @@ type GitTemp2ListCommits_Commit struct { Message string `json:"message" cborgen:"message"` Oid string `json:"oid" cborgen:"oid"` Parents []string `json:"parents" cborgen:"parents"` + Stat *GitDefs_DiffStat `json:"stat,omitempty" cborgen:"stat,omitempty"` Tree string `json:"tree" cborgen:"tree"` } @@ -38,10 +39,11 @@ type GitTemp2ListCommits_Output struct { // GitTemp2ListCommits calls the XRPC method "sh.tangled.git.temp2.listCommits". // +// includeStats: Diff each commit against its first parent and include a line stat // limit: Maximum number of commits to return // repo: DID of the repository // skip: Number of matching commits to skip. A poor man's pagination. -func GitTemp2ListCommits(ctx context.Context, c util.LexClient, after string, allRefs bool, before string, limit int64, ranges []string, repo string, skip int64) (*GitTemp2ListCommits_Output, error) { +func GitTemp2ListCommits(ctx context.Context, c util.LexClient, after string, allRefs bool, before string, includeStats bool, limit int64, ranges []string, repo string, skip int64) (*GitTemp2ListCommits_Output, error) { var out GitTemp2ListCommits_Output params := map[string]interface{}{} @@ -54,6 +56,9 @@ func GitTemp2ListCommits(ctx context.Context, c util.LexClient, after string, al if before != "" { params["before"] = before } + if includeStats { + params["includeStats"] = includeStats + } if limit != 0 { params["limit"] = limit } diff --git a/knotmirror/xrpc/xrpc.go b/knotmirror/xrpc/xrpc.go index ac88c1d1c..6868be449 100644 --- a/knotmirror/xrpc/xrpc.go +++ b/knotmirror/xrpc/xrpc.go @@ -10,13 +10,13 @@ import ( "net/url" "time" + "context" "github.com/bluesky-social/indigo/atproto/atclient" "github.com/bluesky-social/indigo/util/ssrf" "github.com/go-chi/chi/v5" "github.com/hashicorp/golang-lru/v2/expirable" "github.com/redis/go-redis/v9" "github.com/samber/lo" - "context" "golang.org/x/sync/semaphore" "golang.org/x/sync/singleflight" "tangled.org/core/api/tangled" @@ -45,10 +45,10 @@ type Xrpc struct { committers *expirable.LRU[string, []string] committerGroup singleflight.Group // treeGroup coalesces concurrent identical tree walks. Results are shared across goroutines and must be treated as immutable. - treeGroup singleflight.Group - gitSem *semaphore.Weighted - inflight *inflightTracker - serviceSigner *serviceauth.Signer + treeGroup singleflight.Group + gitSem *semaphore.Weighted + inflight *inflightTracker + serviceSigner *serviceauth.Signer } func New(logger *slog.Logger, cfg *config.Config, db *sql.DB, rdb *redis.Client, indexer *repoindexer.Indexer, resolver *idresolver.Resolver, ks *knotstream.KnotStream) *Xrpc { diff --git a/spindle/engines/microvm/substituter_proxy.go b/spindle/engines/microvm/substituter_proxy.go index 7042321cc..964e9cd4d 100644 --- a/spindle/engines/microvm/substituter_proxy.go +++ b/spindle/engines/microvm/substituter_proxy.go @@ -283,7 +283,7 @@ const nixCacheInfo = "StoreDir: /nix/store\nWantMassQuery: 1\nPriority: 40\n" var ( readNarinfoPathRe = regexp.MustCompile(`^/[0-9abcdfghijklmnpqrsvwxyz]{32}\.narinfo$`) readNarPathRe = regexp.MustCompile(`^/nar/[0-9abcdfghijklmnpqrsvwxyz]{32,64}\.nar(?:\.(?:xz|zst|bz2|gz|lzip|br))?$`) - readNarQueryRe = regexp.MustCompile(`^$|^hash=[0-9abcdfghijklmnpqrsvwxyz]{32}$`) + readNarQueryRe = regexp.MustCompile(`^$|^hash=[0-9abcdfghijklmnpqrsvwxyz]{32}$`) ) func allowedReadCachePath(path, rawQuery string) bool { diff --git a/spindle/xrpc/org_tangled_secret_common.go b/spindle/xrpc/org_tangled_secret_common.go index 2c3874b60..ce0da22b1 100644 --- a/spindle/xrpc/org_tangled_secret_common.go +++ b/spindle/xrpc/org_tangled_secret_common.go @@ -10,7 +10,7 @@ import ( ) const ( - maxSecretKeyLen = 50 + maxSecretKeyLen = 50 maxSecretValueLen = 4096 ) diff --git a/web/src/lib/api/lexicons/types/sh/tangled/ci/pipeline.ts b/web/src/lib/api/lexicons/types/sh/tangled/ci/pipeline.ts index cbe5ebb83..5483972f9 100644 --- a/web/src/lib/api/lexicons/types/sh/tangled/ci/pipeline.ts +++ b/web/src/lib/api/lexicons/types/sh/tangled/ci/pipeline.ts @@ -31,6 +31,7 @@ const _mainSchema = /*#__PURE__*/ v.object({ ShTangledCiTrigger.manualSchema, ShTangledCiTrigger.pullRequestSchema, ShTangledCiTrigger.pushSchema, + ShTangledCiTrigger.scheduleSchema, ]); }, /** diff --git a/web/src/lib/api/lexicons/types/sh/tangled/ci/queryPipelines.ts b/web/src/lib/api/lexicons/types/sh/tangled/ci/queryPipelines.ts index 7b702b02c..665c59561 100644 --- a/web/src/lib/api/lexicons/types/sh/tangled/ci/queryPipelines.ts +++ b/web/src/lib/api/lexicons/types/sh/tangled/ci/queryPipelines.ts @@ -20,7 +20,12 @@ const _mainSchema = /*#__PURE__*/ v.query("sh.tangled.ci.queryPipelines", { */ kinds: /*#__PURE__*/ v.optional( /*#__PURE__*/ v.array( - /*#__PURE__*/ v.literalEnum(["manual", "pull_request", "push"]), + /*#__PURE__*/ v.literalEnum([ + "manual", + "pull_request", + "push", + "schedule", + ]), ), ), /** diff --git a/web/src/lib/api/lexicons/types/sh/tangled/ci/trigger.ts b/web/src/lib/api/lexicons/types/sh/tangled/ci/trigger.ts index e92de2230..8a267949c 100644 --- a/web/src/lib/api/lexicons/types/sh/tangled/ci/trigger.ts +++ b/web/src/lib/api/lexicons/types/sh/tangled/ci/trigger.ts @@ -86,23 +86,48 @@ const _pushSchema = /*#__PURE__*/ v.object({ ]), ref: /*#__PURE__*/ v.string(), }); +const _scheduleSchema = /*#__PURE__*/ v.object({ + $type: /*#__PURE__*/ v.optional( + /*#__PURE__*/ v.literal("sh.tangled.ci.trigger#schedule"), + ), + /** + * default branch ref resolved for the scheduled run + */ + ref: /*#__PURE__*/ v.string(), + /** + * UTC minute selected by the cron schedule + */ + scheduledAt: /*#__PURE__*/ v.datetimeString(), + /** + * commit SHA the scheduled run targets + * @minLength 40 + * @maxLength 40 + */ + sha: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ + /*#__PURE__*/ v.stringLength(40, 40), + ]), +}); type manual$schematype = typeof _manualSchema; type pair$schematype = typeof _pairSchema; type pullRequest$schematype = typeof _pullRequestSchema; type push$schematype = typeof _pushSchema; +type schedule$schematype = typeof _scheduleSchema; export interface manualSchema extends manual$schematype {} export interface pairSchema extends pair$schematype {} export interface pullRequestSchema extends pullRequest$schematype {} export interface pushSchema extends push$schematype {} +export interface scheduleSchema extends schedule$schematype {} export const manualSchema = _manualSchema as manualSchema; export const pairSchema = _pairSchema as pairSchema; export const pullRequestSchema = _pullRequestSchema as pullRequestSchema; export const pushSchema = _pushSchema as pushSchema; +export const scheduleSchema = _scheduleSchema as scheduleSchema; export interface Manual extends v.InferInput {} export interface Pair extends v.InferInput {} export interface PullRequest extends v.InferInput {} export interface Push extends v.InferInput {} +export interface Schedule extends v.InferInput {} diff --git a/web/src/lib/api/lexicons/types/sh/tangled/pipeline.ts b/web/src/lib/api/lexicons/types/sh/tangled/pipeline.ts index ea0d633b3..637a7dfc7 100644 --- a/web/src/lib/api/lexicons/types/sh/tangled/pipeline.ts +++ b/web/src/lib/api/lexicons/types/sh/tangled/pipeline.ts @@ -100,11 +100,37 @@ const _pushTriggerDataSchema = /*#__PURE__*/ v.object({ ]), ref: /*#__PURE__*/ v.string(), }); +const _scheduleTriggerDataSchema = /*#__PURE__*/ v.object({ + $type: /*#__PURE__*/ v.optional( + /*#__PURE__*/ v.literal("sh.tangled.pipeline#scheduleTriggerData"), + ), + /** + * default branch ref resolved for the scheduled run + */ + ref: /*#__PURE__*/ v.string(), + /** + * UTC minute selected by the cron schedule + */ + scheduledAt: /*#__PURE__*/ v.datetimeString(), + /** + * commit SHA the scheduled run targets + * @minLength 40 + * @maxLength 40 + */ + sha: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ + /*#__PURE__*/ v.stringLength(40, 40), + ]), +}); const _triggerMetadataSchema = /*#__PURE__*/ v.object({ $type: /*#__PURE__*/ v.optional( /*#__PURE__*/ v.literal("sh.tangled.pipeline#triggerMetadata"), ), - kind: /*#__PURE__*/ v.literalEnum(["manual", "pull_request", "push"]), + kind: /*#__PURE__*/ v.literalEnum([ + "manual", + "pull_request", + "push", + "schedule", + ]), get manual() { return /*#__PURE__*/ v.optional(manualTriggerDataSchema); }, @@ -117,6 +143,9 @@ const _triggerMetadataSchema = /*#__PURE__*/ v.object({ get repo() { return triggerRepoSchema; }, + get schedule() { + return /*#__PURE__*/ v.optional(scheduleTriggerDataSchema); + }, /** * Repository DID that code and workflow definitions are checked out from, when different from repo (e.g. a fork's commit for a fork-based manual trigger). If absent, source uses repo itself. */ @@ -156,6 +185,7 @@ type manualTriggerData$schematype = typeof _manualTriggerDataSchema; type pair$schematype = typeof _pairSchema; type pullRequestTriggerData$schematype = typeof _pullRequestTriggerDataSchema; type pushTriggerData$schematype = typeof _pushTriggerDataSchema; +type scheduleTriggerData$schematype = typeof _scheduleTriggerDataSchema; type triggerMetadata$schematype = typeof _triggerMetadataSchema; type triggerRepo$schematype = typeof _triggerRepoSchema; type workflow$schematype = typeof _workflowSchema; @@ -166,6 +196,7 @@ export interface manualTriggerDataSchema extends manualTriggerData$schematype {} export interface pairSchema extends pair$schematype {} export interface pullRequestTriggerDataSchema extends pullRequestTriggerData$schematype {} export interface pushTriggerDataSchema extends pushTriggerData$schematype {} +export interface scheduleTriggerDataSchema extends scheduleTriggerData$schematype {} export interface triggerMetadataSchema extends triggerMetadata$schematype {} export interface triggerRepoSchema extends triggerRepo$schematype {} export interface workflowSchema extends workflow$schematype {} @@ -179,6 +210,8 @@ export const pullRequestTriggerDataSchema = _pullRequestTriggerDataSchema as pullRequestTriggerDataSchema; export const pushTriggerDataSchema = _pushTriggerDataSchema as pushTriggerDataSchema; +export const scheduleTriggerDataSchema = + _scheduleTriggerDataSchema as scheduleTriggerDataSchema; export const triggerMetadataSchema = _triggerMetadataSchema as triggerMetadataSchema; export const triggerRepoSchema = _triggerRepoSchema as triggerRepoSchema; @@ -196,6 +229,9 @@ export interface PullRequestTriggerData extends v.InferInput< export interface PushTriggerData extends v.InferInput< typeof pushTriggerDataSchema > {} +export interface ScheduleTriggerData extends v.InferInput< + typeof scheduleTriggerDataSchema +> {} export interface TriggerMetadata extends v.InferInput< typeof triggerMetadataSchema > {} diff --git a/web/src/lib/api/lexicons/types/sh/tangled/repo/addSecret.ts b/web/src/lib/api/lexicons/types/sh/tangled/repo/addSecret.ts index 74aee757b..cce1d9b5b 100644 --- a/web/src/lib/api/lexicons/types/sh/tangled/repo/addSecret.ts +++ b/web/src/lib/api/lexicons/types/sh/tangled/repo/addSecret.ts @@ -17,10 +17,10 @@ const _mainSchema = /*#__PURE__*/ v.procedure("sh.tangled.repo.addSecret", { repo: /*#__PURE__*/ v.resourceUriString(), /** * @minLength 1 - * @maxLength 200 + * @maxLength 4096 */ value: /*#__PURE__*/ v.constrain(/*#__PURE__*/ v.string(), [ - /*#__PURE__*/ v.stringLength(1, 200), + /*#__PURE__*/ v.stringLength(1, 4096), ]), }), }, -- 2.51.2