Documentation
¶
Overview ¶
Package sync implements the repo sync poller (Loop 1 in the P2 design): periodically HEAD-check each connected repo, shallow-clone on SHA change, parse cronfoundry.yaml + referenced SKILL.md files, upsert skill + schedule rows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadManifest ¶
LoadManifest reads and validates a checked-out repo's cronfoundry.yaml, then parses each SKILL.md it references. Returns (manifest, skillsByPath) or an error on any step.
Security: each skill path from the manifest is resolved to an absolute path and verified to stay inside repoRoot. A malicious cronfoundry.yaml that claims `path: ../../etc/passwd` is rejected before we touch the filesystem outside the clone dir.
func UpsertSkillsAndSchedules ¶
func UpsertSkillsAndSchedules( ctx context.Context, pool *pgxpool.Pool, orgID, repoID pgtype.UUID, manifest *config.Manifest, skills map[string]*config.Skill, sha string, ) error
UpsertSkillsAndSchedules reconciles the parsed manifest + skill frontmatters against the DB:
- skills present in the manifest are upserted (keyed on repo_id+path)
- skills absent from the manifest are deleted (cascades to their schedules)
- for each manifest skill, schedules absent from the manifest are soft-disabled (enabled=false) to preserve run history; schedules present are upserted and marked enabled.
All DB work happens in a single transaction.
Types ¶
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller orchestrates repo-sync passes. P2c will add a Run() loop that schedules SyncOne against all due repo_connection rows on a ticker.
func NewPoller ¶
func NewPoller(cfg PollerConfig) *Poller
NewPoller constructs a Poller with sensible defaults.
func (*Poller) SyncOne ¶
SyncOne runs a single sync pass for the named repo_connection.
Flow:
- Load the repo_connection row.
- Fetch an installation token.
- HEAD-check the default branch via the GitHub API.
- If the SHA matches last_synced_head_sha, touch last_synced_at and return.
- Otherwise shallow-clone the repo at the new SHA into a tempdir.
- Parse cronfoundry.yaml + SKILL.md files.
- Upsert skill + schedule rows.
- Mark the repo_connection as synced at the new SHA.
Errors at any step are recorded in last_sync_error and surfaced to the caller; the row's last_synced_at is still advanced so a broken repo doesn't back up the queue.
type PollerConfig ¶
type PollerConfig struct {
Pool *pgxpool.Pool
OrgID pgtype.UUID
Installations *github.InstallationCache
GitHubBaseURL string // default: "https://api.github.com"
HTTPClient *http.Client // default: http.DefaultClient
CloneURLFor func(owner, name string) string // default: x-access-token HTTPS
}
PollerConfig bundles the poller's collaborators. Only Pool, OrgID, and Installations are required; the rest have sensible defaults.
OrgID is retained for the P2c scheduler loop — it'll be used to list the connections belonging to this org ("list connections for this org" queries). It is NOT used for per-row upserts in SyncOne; each repo_connection row carries its own OrgID and is the source of truth for downstream skill/schedule writes to prevent cross-tenant writes if someone ever hands SyncOne a connID from a different org.