Skip to content

feat(api): unfiltered per-PR audit-event query + type-label audit row #4006

Description

@JSONbored

Context

The durable audit_events table works well as a per-PR correlation key — a live query against production D1 returned a clean, chronologically-ordered timeline of every event for one real repo#PR target across many distinct event types. But the only public API over it, /v1/repos/:owner/:repo/agent/audit-feed (listAgentAuditEvents, src/db/repositories.ts:2942), hard-filters to eventType LIKE 'agent.action.%' OR 'agent.pending_action.%' — excluding roughly 140 of the ~150 distinct event types that actually exist in the table (gate overrides, public-surface publishes, auth events, moderation violations, finding-resolution events, etc.).

Separately, the maintainer's own cited example — "why was this PR labeled wrong" — isn't in the durable audit ledger at all. type_label_decision/type_label_error (src/queue/processors.ts:8017-8036) are only ever a console.log, never a recordAuditEvent call, so even the broadened query below wouldn't surface it without also fixing this.

Requirements

  1. Add a new, unfiltered query function (e.g. listAuditEventsForTarget(env, { repoFullName, pullNumber, sinceIso?, limit? })) with no eventType restriction, reusing the existing repo#PR target-key correlation — no schema change needed, the data already supports this.
  2. Expose it via a new or extended API route (or a maintainer-only flag on the existing audit-feed route) so a maintainer can pull one PR's entire event history in one call.
  3. Add a recordAuditEvent(env, { eventType: "github_app.type_label_decision", targetKey: \${repoFullName}#${pr.number}`, outcome, detail, metadata: { labels, source } })call alongside the existing console.log atprocessors.ts:8017-8036`, so label decisions become queryable through this same mechanism.

Deliverables

  • listAuditEventsForTarget in src/db/repositories.ts.
  • A route/flag exposing it in src/api/routes.ts.
  • The new type_label_decision audit-event write in src/queue/processors.ts.
  • Test coverage for the new query and the new audit-event write.

Expected outcome

"Why did X happen to PR #N" becomes a single API call pulling the PR's full decision history — including label decisions — instead of requiring a maintainer to already know which of ~150 event-type prefixes to look for, or to grep container logs.

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.orbGittensory Orb related - maintainer self-hosting analytics.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions